aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/server/api/Users.java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2020-03-07 16:01:52 +0300
committerGravatar Vitaly Takmazov2020-03-07 16:01:52 +0300
commitafb897034311fe7e0e981ec44100d3b3fd3ef39d (patch)
tree6104cab72b5eaae4b499e35b7bbc93be875e4336 /src/main/java/com/juick/server/api/Users.java
parentc9d67837cbcaae84a03b7bd14e508ca62880f87f (diff)
Load EmailManager conditionally
Diffstat (limited to 'src/main/java/com/juick/server/api/Users.java')
-rw-r--r--src/main/java/com/juick/server/api/Users.java12
1 files changed, 4 insertions, 8 deletions
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));
}
}
}