aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/server/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/juick/server/api')
-rw-r--r--src/main/java/com/juick/server/api/Service.java7
-rw-r--r--src/main/java/com/juick/server/api/Users.java12
2 files changed, 8 insertions, 11 deletions
diff --git a/src/main/java/com/juick/server/api/Service.java b/src/main/java/com/juick/server/api/Service.java
index 2763eab1..4474e4f0 100644
--- a/src/main/java/com/juick/server/api/Service.java
+++ b/src/main/java/com/juick/server/api/Service.java
@@ -27,6 +27,7 @@ import com.juick.server.util.HttpForbiddenException;
import com.juick.service.EmailService;
import com.juick.service.MessagesService;
import com.juick.service.UserService;
+import com.juick.service.component.AccountVerificationEvent;
import com.juick.service.security.annotation.Visitor;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.io.IOUtils;
@@ -36,6 +37,7 @@ import org.apache.commons.mail.util.MimeMessageParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.ApplicationEventPublisher;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
@@ -70,7 +72,7 @@ public class Service {
@Inject
private CommandsManager commandsManager;
@Inject
- private EmailManager emailManager;
+ private ApplicationEventPublisher applicationEventPublisher;
@Value("${api_user:juick}")
private String serviceUser;
@Value("${upload_tmp_dir:#{systemEnvironment['TEMP'] ?: '/tmp'}}")
@@ -168,8 +170,7 @@ public class Service {
if (!Arrays.asList(ignoredEmails).contains(from)) {
String verificationCode = RandomStringUtils.randomAlphanumeric(8).toUpperCase();
emailService.addVerificationCode(null, from, verificationCode);
- String signupUrl = String.format("Follow this link to create Juick account: https://juick.com/signup?type=email&hash=%s", verificationCode);
- emailManager.sendEmail("noreply@juick.com", from, "Juick registration", signupUrl, StringUtils.EMPTY, Collections.emptyMap());
+ applicationEventPublisher.publishEvent(new AccountVerificationEvent(this, from, verificationCode));
}
}
} else {
diff --git a/src/main/java/com/juick/server/api/Users.java b/src/main/java/com/juick/server/api/Users.java
index e53c5424..531883fc 100644
--- a/src/main/java/com/juick/server/api/Users.java
+++ b/src/main/java/com/juick/server/api/Users.java
@@ -27,11 +27,13 @@ import com.juick.server.util.HttpUtils;
import com.juick.server.util.WebUtils;
import com.juick.server.www.WebApp;
import com.juick.service.*;
+import com.juick.service.component.MailVerificationEvent;
import com.juick.service.security.annotation.Visitor;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.ApplicationEventPublisher;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
@@ -68,7 +70,7 @@ public class Users {
@Value("${upload_tmp_dir:#{systemEnvironment['TEMP'] ?: '/tmp'}}")
private String tmpDir;
@Inject
- private EmailManager emailManager;
+ private ApplicationEventPublisher applicationEventPublisher;
@RequestMapping(value = "/api/auth", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public String getAuthToken(@Visitor User visitor) {
@@ -138,13 +140,7 @@ public class Users {
if (!emailService.verifyAddressByCode(visitor.getUid(), newEmail)) {
String authCode = RandomStringUtils.randomAlphanumeric(8).toUpperCase();
if (emailService.addVerificationCode(visitor.getUid(), newEmail, authCode)) {
- if (!emailManager.sendEmail("noreply@juick.com", newEmail, "Juick authorization link",
- String.format("Follow link to attach this email to Juick account:\n" +
- "http://juick.com/settings?page=auth-email&code=%s\n\n" +
- "If you don't know, what this mean - just ignore this mail.\n", authCode),
- StringUtils.EMPTY, Collections.emptyMap())) {
- throw new HttpBadRequestException();
- }
+ applicationEventPublisher.publishEvent(new MailVerificationEvent(this, newEmail , authCode));
}
}
}