Commit a07aae54 by weisong
parents b7178819 8b2a105c
......@@ -2,6 +2,7 @@ package com.cnooc.expert.auth.service.impl;
import cn.hutool.core.lang.Validator;
import cn.hutool.core.util.IdcardUtil;
import com.cnooc.expert.auth.service.AccountLockService;
import com.cnooc.expert.common.constant.TokenConstants;
import com.cnooc.expert.common.exception.BusinessException;
import com.cnooc.expert.common.exception.GlobalErrorCodeConstants;
......@@ -44,6 +45,9 @@ public class LoginServiceImpl implements LoginService {
private SmsService smsService;
@Autowired
private AccountLockService accountLockService;
@Autowired
private SysCaptchaService sysCaptchaService;
@Autowired
......@@ -166,6 +170,11 @@ public class LoginServiceImpl implements LoginService {
if(expertInfoResp == null){
throw new BusinessException(GlobalErrorCodeConstants.USER_NOT_EXISTS.getCode(),GlobalErrorCodeConstants.USER_NOT_EXISTS.getMsg());
}
boolean isAccountLocked = accountLockService.isAccountLocked(expertInfoResp.getZhuanJiaGuid());
if(isAccountLocked){
//如果账号锁定了,返回错误信息
throw new BusinessException(GlobalErrorCodeConstants.USER_LOCKED.getCode(),GlobalErrorCodeConstants.USER_LOCKED.getMsg());
}
ExpertInfoAppResp expertInfoAppResp = loginServicesClient.getZhuanJiaInfoAppById(expertInfoResp.getZhuanJiaGuid());
if(expertInfoAppResp == null){
throw new BusinessException(GlobalErrorCodeConstants.PASSWORD_NOT_EXIST.getCode(),GlobalErrorCodeConstants.PASSWORD_NOT_EXIST.getMsg());
......@@ -174,8 +183,6 @@ public class LoginServiceImpl implements LoginService {
boolean flag = sysCaptchaService.validate(loginVO.getKey(), loginVO.getCaptcha());
if (!flag) {
// 保存登录日志
//sysLogLoginService.save(login.getUsername(), Constant.FAIL, LoginOperationEnum.CAPTCHA_FAIL.getValue());
throw new BusinessException(GlobalErrorCodeConstants.CAPTCHA_EXPIRED.getCode(),GlobalErrorCodeConstants.CAPTCHA_EXPIRED.getMsg());
}
//1.需要去库中查询,是否存在
......@@ -185,7 +192,7 @@ public class LoginServiceImpl implements LoginService {
flag = passwordEncoder.matches(pwd, expertInfoAppResp.getPassword());
if (!flag) {
// 登录日志
//sysLogLoginService.savePortal(login.getAccountName(), Constant.FAIL, LoginOperationEnum.ACCOUNT_FAIL.getValue(), 1);
accountLockService.handleLoginFailure(expertInfoResp.getZhuanJiaGuid());
throw new BusinessException(GlobalErrorCodeConstants.PASSWORD_ERROR.getCode(),GlobalErrorCodeConstants.PASSWORD_ERROR.getMsg());
}
......@@ -197,6 +204,7 @@ public class LoginServiceImpl implements LoginService {
UserUtils.setUserId(zhuanJiaUser);
String token = JwtUtils.createToken(expertInfoResp.getZhuanJiaGuid(),uuidKey);
//6.返回token
accountLockService.handleLoginSuccess(expertInfoResp.getZhuanJiaGuid());
return token;
}
......@@ -215,10 +223,15 @@ public class LoginServiceImpl implements LoginService {
if(expertInfoResp == null){
throw new BusinessException(GlobalErrorCodeConstants.USER_NOT_EXISTS.getCode(),GlobalErrorCodeConstants.USER_NOT_EXISTS.getMsg());
}
boolean isAccountLocked = accountLockService.isAccountLocked(expertInfoResp.getZhuanJiaGuid());
if(isAccountLocked){
//如果账号锁定了,返回错误信息
throw new BusinessException(GlobalErrorCodeConstants.USER_LOCKED.getCode(),GlobalErrorCodeConstants.USER_LOCKED.getMsg());
}
//2.存在校验验证码
if (!smsService.verifySmsCode(loginVO.getPhoneNumber(), loginVO.getPhoneCode())) {
//登录日志
//sysLogLoginService.savePortal(login.getPhone(), Constant.FAIL, LoginOperationEnum.CAPTCHA_FAIL.getValue(), 1);
accountLockService.handleLoginFailure(expertInfoResp.getZhuanJiaGuid());
throw new BusinessException(GlobalErrorCodeConstants.CAPTCHA_EXPIRED.getCode(),GlobalErrorCodeConstants.CAPTCHA_EXPIRED.getMsg());
}
//3.生成相应的uuid作为redis的key
......@@ -229,7 +242,7 @@ public class LoginServiceImpl implements LoginService {
redisTemplate.opsForValue().set(TokenConstants.LOGIN_USER_KEY_ + expertInfoResp.getZhuanJiaGuid(), zhuanJiaUser, 48, TimeUnit.HOURS);
UserUtils.setUserId(zhuanJiaUser);
String token = JwtUtils.createToken(expertInfoResp.getZhuanJiaGuid(),uuidKey);
accountLockService.handleLoginSuccess(expertInfoResp.getZhuanJiaGuid());
return token;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment