diff --git a/maxkey-core/src/main/java/org/maxkey/crypto/password/opt/impl/MailOtpAuthn.java b/maxkey-core/src/main/java/org/maxkey/crypto/password/opt/impl/MailOtpAuthn.java index ba46787c..22486b98 100644 --- a/maxkey-core/src/main/java/org/maxkey/crypto/password/opt/impl/MailOtpAuthn.java +++ b/maxkey-core/src/main/java/org/maxkey/crypto/password/opt/impl/MailOtpAuthn.java @@ -1,5 +1,6 @@ package org.maxkey.crypto.password.opt.impl; +import java.text.MessageFormat; import org.apache.commons.mail.DefaultAuthenticator; import org.apache.commons.mail.Email; import org.apache.commons.mail.SimpleEmail; @@ -15,7 +16,10 @@ public class MailOtpAuthn extends AbstractOptAuthn { @Autowired EmailConfig emailConfig; - + String subject = "One Time PassWord"; + + String messageTemplate = "{0} You Token is {1} , it validity in {2} minutes."; + public MailOtpAuthn() { optType = OptTypes.EMAIL; } @@ -32,13 +36,15 @@ public class MailOtpAuthn extends AbstractOptAuthn { new DefaultAuthenticator(emailConfig.getUsername(), emailConfig.getPassword())); email.setFrom(emailConfig.getSenderMail()); - email.setSubject("One Time PassWord"); - email.setMsg("You Token is " + token - + " , it validity in " + (interval / 60) + " minutes"); + email.setSubject(subject); + email.setMsg( + MessageFormat.format( + messageTemplate,userInfo.getUsername(),token,(interval / 60))); + email.addTo(userInfo.getEmail()); email.send(); _logger.debug( - "token " + token + " send to user +" + userInfo.getUsername() + "token " + token + " send to user " + userInfo.getUsername() + ", email " + userInfo.getEmail()); //ζˆεŠŸθΏ”ε›ž this.optTokenStore.store( @@ -62,4 +68,21 @@ public class MailOtpAuthn extends AbstractOptAuthn { this.emailConfig = emailConfig; } + public String getSubject() { + return subject; + } + + public void setSubject(String subject) { + this.subject = subject; + } + + public String getMessageTemplate() { + return messageTemplate; + } + + public void setMessageTemplate(String messageTemplate) { + this.messageTemplate = messageTemplate; + } + + } diff --git a/maxkey-web-maxkey/src/main/java/org/maxkey/web/contorller/ForgotPasswordContorller.java b/maxkey-web-maxkey/src/main/java/org/maxkey/web/contorller/ForgotPasswordContorller.java index fd31cf7f..50be7b14 100644 --- a/maxkey-web-maxkey/src/main/java/org/maxkey/web/contorller/ForgotPasswordContorller.java +++ b/maxkey-web-maxkey/src/main/java/org/maxkey/web/contorller/ForgotPasswordContorller.java @@ -6,6 +6,8 @@ import java.util.regex.Pattern; import org.maxkey.crypto.password.opt.AbstractOptAuthn; import org.maxkey.dao.service.UserInfoService; import org.maxkey.domain.UserInfo; +import org.maxkey.web.WebConstants; +import org.maxkey.web.WebContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -30,6 +32,7 @@ public class ForgotPasswordContorller { public final static int NOTFOUND = 1; public final static int EMAIL = 2; public final static int MOBILE = 3; + public final static int CAPTCHAERROR = 4; } public class PasswordResetResult{ @@ -60,17 +63,27 @@ public class ForgotPasswordContorller { public ModelAndView email(@RequestParam String emailMobile,@RequestParam String captcha) { _logger.debug("forgotpassword /forgotpassword/emailmobile."); _logger.debug("emailMobile : " + emailMobile); - UserInfo userInfo = userInfoService.queryUserInfoByEmailMobile(emailMobile); - Matcher matcher = emailRegex.matcher(emailMobile); int forgotType = ForgotType.NOTFOUND; - if (matcher.matches() && null != userInfo) { - tfaMailOptAuthn.produce(userInfo); - forgotType = ForgotType.EMAIL; - } - matcher = mobileRegex.matcher(emailMobile); - if (matcher.matches() && null != userInfo) { - tfaMobileOptAuthn.produce(userInfo); - forgotType = ForgotType.MOBILE; + UserInfo userInfo = null; + if (captcha != null && captcha + .equals(WebContext.getSession().getAttribute( + WebConstants.KAPTCHA_SESSION_KEY).toString())) { + userInfo = userInfoService.queryUserInfoByEmailMobile(emailMobile); + Matcher matcher = emailRegex.matcher(emailMobile); + + if (matcher.matches() && null != userInfo) { + tfaMailOptAuthn.produce(userInfo); + forgotType = ForgotType.EMAIL; + } + matcher = mobileRegex.matcher(emailMobile); + if (matcher.matches() && null != userInfo) { + tfaMobileOptAuthn.produce(userInfo); + forgotType = ForgotType.MOBILE; + } + + }else { + _logger.debug("login captcha valid error."); + forgotType = ForgotType.CAPTCHAERROR; } ModelAndView modelAndView = new ModelAndView("forgotpassword/resetpwd"); diff --git a/maxkey-web-maxkey/src/main/resources/templates/views/forgotpassword/resetpwd.ftl b/maxkey-web-maxkey/src/main/resources/templates/views/forgotpassword/resetpwd.ftl index b9cd9bf5..caf43965 100644 --- a/maxkey-web-maxkey/src/main/resources/templates/views/forgotpassword/resetpwd.ftl +++ b/maxkey-web-maxkey/src/main/resources/templates/views/forgotpassword/resetpwd.ftl @@ -10,13 +10,19 @@ <#include "../layout/nologintop.ftl">
- <#if 1 == forgotType> - <@locale code="forgotpassword.resetpwd.notfound.prefix"/> - ${emailMobile} - <@locale code="forgotpassword.resetpwd.notfound.suffix"/> - <@locale code="forgotpassword.backstep"/> - - <#if 2 == forgotType || 3 == forgotType > + + + <#if 4 == forgotType> + <@locale code="forgotpassword.pwdreseted.captcha"/> + <@locale code="forgotpassword.backstep"/> + + <#if 1 == forgotType> + <@locale code="forgotpassword.resetpwd.notfound.prefix"/> + ${emailMobile} + <@locale code="forgotpassword.resetpwd.notfound.suffix"/> + <@locale code="forgotpassword.backstep"/> + + <#if 2 == forgotType || 3 == forgotType >