diff options
author | Vitaly Takmazov | 2018-08-30 11:38:06 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2018-08-30 11:38:06 +0300 |
commit | aa15f2243ea4ad0b80a4cc1e81eeedb94e7409b9 (patch) | |
tree | f1afd1b0471bb878940616c7c269c2980a5b10b1 /juick-server/src/main/java/com/juick/server/api | |
parent | 4e5540dd5c58906a3c4afe18197f1ab1e0292692 (diff) |
email registration
Diffstat (limited to 'juick-server/src/main/java/com/juick/server/api')
-rw-r--r-- | juick-server/src/main/java/com/juick/server/api/Service.java | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/juick-server/src/main/java/com/juick/server/api/Service.java b/juick-server/src/main/java/com/juick/server/api/Service.java index f67f6986..527fb739 100644 --- a/juick-server/src/main/java/com/juick/server/api/Service.java +++ b/juick-server/src/main/java/com/juick/server/api/Service.java @@ -5,9 +5,11 @@ import com.juick.server.CommandsManager; import com.juick.server.EmailManager; import com.juick.server.util.HttpForbiddenException; import com.juick.server.util.UserUtils; +import com.juick.service.EmailService; import com.juick.service.UserService; import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.mail.util.MimeMessageParser; import org.slf4j.Logger; @@ -29,22 +31,26 @@ import java.io.InputStream; import java.net.URI; import java.nio.charset.StandardCharsets; import java.nio.file.Paths; -import java.util.Properties; -import java.util.Scanner; -import java.util.UUID; +import java.util.*; @Controller public class Service { private static Logger logger = LoggerFactory.getLogger(Post.class); @Inject private UserService userService; - @Inject - CommandsManager commandsManager; + private EmailService emailService; + @Inject + private CommandsManager commandsManager; + @Inject + private EmailManager emailManager; @Value("${api_user:juick}") private String serviceUser; @Value("${upload_tmp_dir:#{systemEnvironment['TEMP'] ?: '/tmp'}}") private String tmpDir; + @Value("${banned_emails:}") + private String[] ignoredEmails; + Session session = Session.getDefaultInstance(new Properties()); @ApiIgnore @@ -108,7 +114,12 @@ public class Service { : URI.create(StringUtils.EMPTY); commandsManager.processCommand(visitor, body[0], attachmentUri); } else { - logger.info("not registered: {}", from); + 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&code=%s", verificationCode); + emailManager.sendEmail(from, "Juick registration", signupUrl, StringUtils.EMPTY, Collections.emptyMap()); + } } } else { throw new HttpForbiddenException(); |