aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/juick/server/api/Service.java17
-rw-r--r--src/main/java/com/juick/service/EmailService.java3
-rw-r--r--src/main/java/com/juick/service/EmailServiceImpl.java7
-rw-r--r--src/test/java/com/juick/server/tests/ServerTests.java5
4 files changed, 32 insertions, 0 deletions
diff --git a/src/main/java/com/juick/server/api/Service.java b/src/main/java/com/juick/server/api/Service.java
index 4474e4f0..12a9167f 100644
--- a/src/main/java/com/juick/server/api/Service.java
+++ b/src/main/java/com/juick/server/api/Service.java
@@ -177,6 +177,23 @@ public class Service {
throw new HttpForbiddenException();
}
}
+ @ApiIgnore
+ @PostMapping("/api/mail/unsubscribe")
+ @ResponseStatus(value = HttpStatus.OK)
+ public void processMailUnsubscribe(@Visitor User current, InputStream data) throws Exception {
+ if (current.getName().equals(serviceUser)) {
+ MimeMessage msg = new MimeMessage(session, data);
+ String from = msg.getFrom() == null || msg.getFrom().length > 1 ? ((InternetAddress) msg.getSender()).getAddress()
+ : ((InternetAddress) msg.getFrom()[0]).getAddress();
+
+ User visitor = userService.getUserByEmail(from);
+ if (!visitor.isAnonymous()) {
+
+ }
+ } else {
+ throw new HttpForbiddenException();
+ }
+ }
private void endSession(SseEmitter emitter) {
serverManager.getSessions().stream()
.filter(s -> s.getEmitter().equals(emitter))
diff --git a/src/main/java/com/juick/service/EmailService.java b/src/main/java/com/juick/service/EmailService.java
index b957d5ed..82c2fe5f 100644
--- a/src/main/java/com/juick/service/EmailService.java
+++ b/src/main/java/com/juick/service/EmailService.java
@@ -17,6 +17,8 @@
package com.juick.service;
+import com.juick.model.User;
+
import java.util.List;
/**
@@ -27,6 +29,7 @@ public interface EmailService {
boolean addVerificationCode(Integer userId, String account, String code);
boolean addEmail(Integer userId, String email);
boolean deleteEmail(Integer userId, String account);
+ boolean disableEmail(User user, String account);
String getNotificationsEmail(Integer userId);
boolean setNotificationsEmail(Integer userId, String account);
List<String> getEmails(Integer userId, boolean active);
diff --git a/src/main/java/com/juick/service/EmailServiceImpl.java b/src/main/java/com/juick/service/EmailServiceImpl.java
index 6f0cf995..8d053f50 100644
--- a/src/main/java/com/juick/service/EmailServiceImpl.java
+++ b/src/main/java/com/juick/service/EmailServiceImpl.java
@@ -17,6 +17,7 @@
package com.juick.service;
+import com.juick.model.User;
import org.apache.commons.lang3.StringUtils;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
@@ -66,6 +67,12 @@ public class EmailServiceImpl extends BaseJdbcService implements EmailService {
.addValue("email", account)) > 0;
}
+ @Override
+ public boolean disableEmail(User user, String account) {
+ return getJdbcTemplate().update("UPDATE emails SET subscr_hour=NULL " +
+ "WHERE user_id=? AND email=?", user.getUid(), account) > 0;
+ }
+
@Transactional(readOnly = true)
@Override
public String getNotificationsEmail(Integer userId) {
diff --git a/src/test/java/com/juick/server/tests/ServerTests.java b/src/test/java/com/juick/server/tests/ServerTests.java
index 0b915431..ebfcda08 100644
--- a/src/test/java/com/juick/server/tests/ServerTests.java
+++ b/src/test/java/com/juick/server/tests/ServerTests.java
@@ -462,6 +462,11 @@ public class ServerTests {
User hugnich3 = userService.createUser("hugnich3", "x").orElseThrow(IllegalStateException::new);
jdbcTemplate.update("INSERT INTO emails(user_id,email) VALUES(?,?)", hugnich3.getUid(), "first@localhost");
jdbcTemplate.update("INSERT INTO emails(user_id,email) VALUES(?,?)", hugnich3.getUid(), "second@localhost");
+ emailService.addEmail(hugnich3.getUid(), "test@email.example.com");
+ assertThat(emailService.getNotificationsEmail(hugnich3.getUid()), is("test@email.example.com"));
+ emailService.disableEmail(hugnich3, "test@email.example.com");
+ assertThat(emailService.getNotificationsEmail(hugnich3.getUid()), is(emptyString()));
+ assertThat(emailService.deleteEmail(hugnich3.getUid(), "test@email.example.com"), equalTo(true));
assertThat(emailService.deleteEmail(hugnich3.getUid(), "second@localhost"), equalTo(true));
assertThat(emailService.deleteEmail(hugnich3.getUid(), "first@localhost"), equalTo(false));
}