From 56563439b6b7cb14acec2565eaf9fd652788ffce Mon Sep 17 00:00:00 2001 From: MaxKey Date: Thu, 27 Jan 2022 17:14:51 +0800 Subject: [PATCH] onetimepwd login --- .../maxkey/password/onetimepwd/OtpAuthnService.java | 5 ++++- .../java/org/maxkey/web/endpoint/LoginEndpoint.java | 11 ++++++----- .../src/main/resources/static/javascript/login.js | 1 + 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/maxkey-authentications/maxkey-authentication-otp/src/main/java/org/maxkey/password/onetimepwd/OtpAuthnService.java b/maxkey-authentications/maxkey-authentication-otp/src/main/java/org/maxkey/password/onetimepwd/OtpAuthnService.java index 7531ce32..75c4b03a 100644 --- a/maxkey-authentications/maxkey-authentication-otp/src/main/java/org/maxkey/password/onetimepwd/OtpAuthnService.java +++ b/maxkey-authentications/maxkey-authentication-otp/src/main/java/org/maxkey/password/onetimepwd/OtpAuthnService.java @@ -5,6 +5,7 @@ import java.util.concurrent.TimeUnit; import org.maxkey.configuration.EmailConfig; import org.maxkey.constants.ConstsBoolean; +import org.maxkey.crypto.password.PasswordReciprocal; import org.maxkey.entity.EmailSenders; import org.maxkey.entity.SmsProvider; import org.maxkey.password.onetimepwd.impl.MailOtpAuthn; @@ -84,10 +85,12 @@ public class OtpAuthnService { }else if(smsProvider.getProvider().equalsIgnoreCase("email")) { EmailSenders emailSender = emailSendersService.findOne("where instid = ? ", new Object[]{instId}, new int[]{Types.VARCHAR}); + + String credentials = PasswordReciprocal.getInstance().decoder(emailSender.getCredentials()); EmailConfig emailConfig = new EmailConfig( emailSender.getAccount(), - emailSender.getCredentials(), + credentials, emailSender.getSmtpHost(), emailSender.getPort(), ConstsBoolean.isTrue(emailSender.getSslSwitch()), diff --git a/maxkey-webs/maxkey-web-maxkey/src/main/java/org/maxkey/web/endpoint/LoginEndpoint.java b/maxkey-webs/maxkey-web-maxkey/src/main/java/org/maxkey/web/endpoint/LoginEndpoint.java index 02dfbecd..bef5a011 100644 --- a/maxkey-webs/maxkey-web-maxkey/src/main/java/org/maxkey/web/endpoint/LoginEndpoint.java +++ b/maxkey-webs/maxkey-web-maxkey/src/main/java/org/maxkey/web/endpoint/LoginEndpoint.java @@ -32,6 +32,7 @@ import org.maxkey.configuration.ApplicationConfig; import org.maxkey.entity.Institutions; import org.maxkey.entity.UserInfo; import org.maxkey.password.onetimepwd.AbstractOtpAuthn; +import org.maxkey.password.onetimepwd.OtpAuthnService; import org.maxkey.persistence.service.UserInfoService; import org.maxkey.web.WebConstants; import org.maxkey.web.WebContext; @@ -82,9 +83,9 @@ public class LoginEndpoint { @Qualifier("tfaOtpAuthn") protected AbstractOtpAuthn tfaOtpAuthn; - //@Autowired - //@Qualifier("smsOtpAuthn") - protected AbstractOtpAuthn smsOtpAuthn; + @Autowired + @Qualifier("otpAuthnService") + protected OtpAuthnService otpAuthnService; Pattern mobileRegex = Pattern.compile( "^(13[4,5,6,7,8,9]|15[0,8,9,1,7]|188|187)\\\\d{8}$"); @@ -168,10 +169,10 @@ public class LoginEndpoint { @RequestMapping("/login/sendsms/{mobile}") @ResponseBody - public String produceOtp(@PathVariable("mobile") String mobile) { + public String produceOtp(@PathVariable("mobile") String mobile,HttpServletRequest request) { UserInfo queryUserInfo=userInfoService.findByEmailMobile(mobile); if(queryUserInfo!=null) { - smsOtpAuthn.produce(queryUserInfo); + otpAuthnService.getByInstId(WebContext.getInst(request)).produce(queryUserInfo); return "ok"; } diff --git a/maxkey-webs/maxkey-web-resources/src/main/resources/static/javascript/login.js b/maxkey-webs/maxkey-web-resources/src/main/resources/static/javascript/login.js index 708b377d..d717932a 100644 --- a/maxkey-webs/maxkey-web-resources/src/main/resources/static/javascript/login.js +++ b/maxkey-webs/maxkey-web-resources/src/main/resources/static/javascript/login.js @@ -1,5 +1,6 @@ var currentSwitchTab="normalLogin"; function doLoginSubmit(){ + currentSwitchTab = $(".switch_tab_current").attr("id") ; $.cookie("mxk_login_username", $("#"+currentSwitchTab+"Form input[name=username]").val(), { expires: 7 }); $("#"+currentSwitchTab+"SubmitButton").click(); $.cookie("mxk_login_switch_tab", currentSwitchTab, { expires: 7 });