|
@@ -8,10 +8,12 @@ import com.zhongzheng.common.core.domain.entity.SysUser;
|
|
|
import com.zhongzheng.common.core.domain.model.LoginBody;
|
|
|
import com.zhongzheng.common.utils.DateUtils;
|
|
|
import com.zhongzheng.framework.manager.factory.AsyncFactory;
|
|
|
+import com.zhongzheng.modules.system.service.ISysConfigService;
|
|
|
import com.zhongzheng.modules.system.service.ISysUserService;
|
|
|
import com.zhongzheng.common.utils.AES;
|
|
|
import com.zhongzheng.framework.manager.factory.AsyncFactory;
|
|
|
import com.zhongzheng.modules.user.bo.UserBusinessLoginBo;
|
|
|
+import com.zhongzheng.modules.user.service.IUserLoginErrorService;
|
|
|
import org.apache.commons.compress.utils.IOUtils;
|
|
|
import org.bouncycastle.jcajce.provider.asymmetric.rsa.RSAUtil;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -53,8 +55,11 @@ public class SysLoginService
|
|
|
@Autowired
|
|
|
private ISysUserService iSysUserService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ISysConfigService configService;
|
|
|
|
|
|
-
|
|
|
+ @Autowired
|
|
|
+ private IUserLoginErrorService iUserLoginErrorService;
|
|
|
/**
|
|
|
* 登录验证
|
|
|
*
|
|
@@ -64,7 +69,7 @@ public class SysLoginService
|
|
|
* @param uuid 唯一标识
|
|
|
* @return 结果
|
|
|
*/
|
|
|
- public String login(String username, String password, String code, String uuid)
|
|
|
+ public String login(String username, String password, String code, String uuid,String smsCode,String tel)
|
|
|
{
|
|
|
String verifyKey = Constants.CAPTCHA_CODE_KEY + uuid;
|
|
|
String captcha = redisCache.getCacheObject(verifyKey);
|
|
@@ -79,6 +84,7 @@ public class SysLoginService
|
|
|
AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.error")));
|
|
|
throw new CaptchaException();
|
|
|
}
|
|
|
+ iUserLoginErrorService.checkLimit(username);
|
|
|
// 用户验证
|
|
|
Authentication authentication = null;
|
|
|
try
|
|
@@ -101,6 +107,7 @@ public class SysLoginService
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
+ iUserLoginErrorService.saveErrorLog(username);
|
|
|
if (e instanceof BadCredentialsException)
|
|
|
{
|
|
|
AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.not.match")));
|
|
@@ -115,6 +122,23 @@ public class SysLoginService
|
|
|
AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")));
|
|
|
LoginUser loginUser = (LoginUser) authentication.getPrincipal();
|
|
|
SysUser user = iSysUserService.updateLoginTimeIp(loginUser.getUser().getUserId());
|
|
|
+ String dualAuth = configService.selectConfigByKey("login.dual.auth");
|
|
|
+ if(Validator.isNotEmpty(dualAuth)&&dualAuth.equals("1")){
|
|
|
+ if(Validator.isEmpty(tel)){
|
|
|
+ throw new CustomException("手机号码不能为空");
|
|
|
+ }
|
|
|
+ String key = Constants.LOGIN_SMS + tel;
|
|
|
+ String localSmsCode = redisCache.getCacheObject(key);
|
|
|
+ if(smsCode==null){
|
|
|
+ throw new CustomException("验证码不能为空");
|
|
|
+ }
|
|
|
+ if(!localSmsCode.equals(smsCode)){
|
|
|
+ throw new CustomException("验证码错误");
|
|
|
+ }
|
|
|
+ if(!tel.equals(user.getPhonenumber())){
|
|
|
+ throw new CustomException("手机号码和登录账号不匹配");
|
|
|
+ }
|
|
|
+ }
|
|
|
loginUser.setUser(user);
|
|
|
// 生成token
|
|
|
return tokenService.createToken(loginUser);
|