Browse Source

onetimepwd login

MaxKey 3 years ago
parent
commit
56563439b6

+ 4 - 1
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()),

+ 6 - 5
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";
         }
         

+ 1 - 0
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 });