Skip to content
This repository was archived by the owner on Sep 29, 2024. It is now read-only.

Commit 4cf25c5

Browse files
authored
Merge pull request #819 from SE-TINF22B6/cors-fix
Add basic report function
2 parents 237ba4e + 4f97336 commit 4cf25c5

File tree

8 files changed

+127
-8
lines changed

8 files changed

+127
-8
lines changed

src/main/java/de/tinf22b6/dhbwhub/controller/AuthController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public ResponseEntity<?> emailVerification (@Valid @RequestBody EmailVerificatio
9999

100100
try {
101101
emailService.sendMessageUsingThymeleafTemplate(
102-
emailVerificationRequest.getEmail(), "Email Verification", templateModel);
102+
emailVerificationRequest.getEmail(), "Email Verification", "mail-template.html", templateModel);
103103
} catch (MessagingException | IOException e) {
104104
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
105105
.body(new MessageResponse("Failed to send email with token."));

src/main/java/de/tinf22b6/dhbwhub/controller/PostController.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ public HomepagePostPreviewProposal create(@RequestBody CreatePostProposal propos
8888
return service.create(proposal);
8989
}
9090

91+
@PostMapping("/report")
92+
public void report(@RequestBody ReportPostProposal proposal) {
93+
service.report(proposal);
94+
}
95+
9196
@GetMapping("/{id}")
9297
public Post get(@PathVariable Long id) {
9398
return service.get(id);
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package de.tinf22b6.dhbwhub.proposal.simplified_models;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Getter;
5+
import lombok.NoArgsConstructor;
6+
import lombok.Setter;
7+
8+
@Getter
9+
@Setter
10+
@AllArgsConstructor
11+
@NoArgsConstructor
12+
public class ReportPostProposal {
13+
private String reportReason;
14+
15+
private String reportDescription;
16+
17+
private Long postId;
18+
19+
private Long authorId;
20+
21+
private Long userId;
22+
}

src/main/java/de/tinf22b6/dhbwhub/service/EmailService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ public EmailService(JavaMailSender emailSender, SpringTemplateEngine thymeleafTe
3232
}
3333

3434
public void sendMessageUsingThymeleafTemplate(
35-
String to, String subject, Map<String, Object> templateModel)
35+
String to, String subject, String template, Map<String, Object> templateModel)
3636
throws MessagingException, IOException {
3737

3838
Context thymeleafContext = new Context();
3939
thymeleafContext.setVariables(templateModel);
4040

41-
String htmlBody = thymeleafTemplateEngine.process("mail-template.html", thymeleafContext);
41+
String htmlBody = thymeleafTemplateEngine.process(template, thymeleafContext);
4242

4343
sendHtmlMessage(to, subject, htmlBody);
4444
}

src/main/java/de/tinf22b6/dhbwhub/service/PostServiceImpl.java

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
import de.tinf22b6.dhbwhub.proposal.simplified_models.*;
1616
import de.tinf22b6.dhbwhub.repository.*;
1717
import de.tinf22b6.dhbwhub.service.interfaces.PostService;
18+
import jakarta.mail.MessagingException;
1819
import jakarta.persistence.EntityExistsException;
1920
import org.springframework.beans.factory.annotation.Autowired;
21+
import org.springframework.beans.factory.annotation.Value;
2022
import org.springframework.stereotype.Service;
2123

22-
import java.util.ArrayList;
23-
import java.util.Arrays;
24-
import java.util.List;
25-
import java.util.Objects;
24+
import java.io.IOException;
25+
import java.util.*;
2626

2727
@Service
2828
public class PostServiceImpl implements PostService {
@@ -33,23 +33,29 @@ public class PostServiceImpl implements PostService {
3333
private final LogtableRepository logtableRepository;
3434
private final NotificationRepository notificationRepository;
3535
private final CommentRepository commentRepository;
36+
private final EmailService emailService;
3637

3738
public PostServiceImpl(@Autowired PostRepository repository,
3839
@Autowired UserRepository userRepository,
3940
@Autowired PictureRepository pictureRepository,
4041
@Autowired PostTagRepository postTagRepository,
4142
@Autowired LogtableRepository logtableRepository,
4243
@Autowired NotificationRepository notificationRepository,
43-
@Autowired CommentRepository commentRepository) {
44+
@Autowired CommentRepository commentRepository,
45+
@Autowired EmailService emailService) {
4446
this.repository = repository;
4547
this.userRepository = userRepository;
4648
this.pictureRepository = pictureRepository;
4749
this.postTagRepository = postTagRepository;
4850
this.logtableRepository = logtableRepository;
4951
this.notificationRepository = notificationRepository;
5052
this.commentRepository = commentRepository;
53+
this.emailService = emailService;
5154
}
5255

56+
@Value("${spring.mail.support-mail}")
57+
private String supportMail;
58+
5359
@Override
5460
public List<Post> getAll() {
5561
return repository.findAll();
@@ -82,6 +88,22 @@ public HomepagePostPreviewProposal create(CreatePostProposal proposal) {
8288
return getPostHomepageView(post.getId());
8389
}
8490

91+
@Override
92+
public void report(ReportPostProposal proposal) {
93+
Map<String, Object> templateModel = new HashMap<>();
94+
templateModel.put("post_url", String.format("https://www.dhbwhub.de/post/?id=%d", proposal.getPostId()));
95+
templateModel.put("user_id_of_reporter", proposal.getUserId());
96+
templateModel.put("user_id_of_author", proposal.getAuthorId());
97+
templateModel.put("report_reason", proposal.getReportReason());
98+
templateModel.put("additional_notes", proposal.getReportDescription());
99+
100+
try {
101+
emailService.sendMessageUsingThymeleafTemplate(supportMail, "Incoming User Report", "report-template.html", templateModel);
102+
} catch (MessagingException | IOException e) {
103+
throw new RuntimeException("An error occurred while trying to send the report: " + e.getMessage());
104+
}
105+
}
106+
85107
@Override
86108
public Post get(Long id) {
87109
Post post = repository.find(id);

src/main/java/de/tinf22b6/dhbwhub/service/interfaces/PostService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public interface PostService {
1010
List<Post> getAll();
1111
Post create(PostProposal proposal);
1212
HomepagePostPreviewProposal create(CreatePostProposal proposal);
13+
void report(ReportPostProposal proposal);
1314
Post get(Long id);
1415
Post update(Long id, PostProposal proposal);
1516
int increaseLikes(LikePostProposal likePostProposal);

src/main/resources/application.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ spring:
1414
host: smtp.strato.de
1515
port: 465
1616
username: info@dhbwhub.de
17+
support-mail: info@dhbwhub.de
1718
password: ${SMTP_PASSWORD}
1819
protocol: smtp
1920
templates:
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<!DOCTYPE html>
2+
<html lang="en" xmlns:th="https://thymeleaf.org">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Incoming User Report</title>
7+
<style>
8+
body {
9+
font-family: Arial, sans-serif;
10+
margin: 0;
11+
padding: 0;
12+
background-color: grey;
13+
color: #333;
14+
}
15+
.container {
16+
max-width: 600px;
17+
margin: 20px auto;
18+
padding: 20px;
19+
background-color: #25282c;
20+
border-radius: 10px;
21+
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
22+
}
23+
.text {
24+
font-family: Arial, sans-serif;
25+
color: white;
26+
}
27+
.header img {
28+
max-width: 150px;
29+
}
30+
.verification-code {
31+
text-align: center;
32+
font-size: 24px;
33+
color: #ff4444;
34+
margin-bottom: 30px;
35+
}
36+
.footer {
37+
text-align: center;
38+
margin-top: 50px;
39+
color: white;
40+
}
41+
</style>
42+
</head>
43+
<body>
44+
<div class="container">
45+
<div class="text">
46+
<p>Dies ist eine automatische Nachricht, die Sie über die neusten Benutzeraktivitäten in Bezug auf die Meldung von Inhalten informiert</p>
47+
48+
<h4>Details zum Vorfall:</h4>
49+
<ul>
50+
<li><strong>URL zum Post:</strong> <td th:text="${post_url}"></td></li>
51+
<li><strong>Benutzer-ID des Reporters:</strong> <td th:text="${user_id_of_reporter}"></td></li>
52+
<li><strong>Benutzer-ID des Authors:</strong> <td th:text="${user_id_of_author}"></td></li>
53+
<li><strong>Report Grund:</strong> <td th:text="${report_reason}"></td></li>
54+
<li><strong>Zusätzliche Anmerkungen des Reporters:</strong> <td th:text="${additional_notes}"></td></li>
55+
</ul>
56+
57+
<h4>Erforderliche Maßnahmen:</h4>
58+
<p>Bitte überprüfen Sie den gemeldeten Inhalt, um sicherzustellen, dass er mit den Community-Richtlinien und Nutzungsbedingungen unserer Plattform übereinstimmt.</p>
59+
</div>
60+
<div class="footer">
61+
© 2024 DHBWhub. All rights reserved.
62+
<br>
63+
<br>
64+
Erzbergerstraße 121, 76133 Karlsruhe, Deutschland
65+
</div>
66+
</div>
67+
</body>
68+
</html>

0 commit comments

Comments
 (0)