|
@@ -41,7 +41,8 @@ import com.xingyuv.captcha.model.vo.CaptchaVO;
|
|
|
import com.xingyuv.captcha.service.CaptchaService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
-import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
+import org.springframework.context.annotation.Lazy;
|
|
|
+import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
@@ -92,7 +93,8 @@ public class MdeAuthServiceImpl implements MdeAuthService {
|
|
|
@Resource
|
|
|
protected CaptchaService captchaService;
|
|
|
@Resource
|
|
|
- private StringRedisTemplate redisTemplate;
|
|
|
+ @Lazy
|
|
|
+ private RedisTemplate<String, String> redisTemplate;
|
|
|
|
|
|
@VisibleForTesting
|
|
|
protected void validateCaptcha(AppMdeAuthLoginReqVO reqVO) {
|
|
@@ -146,6 +148,12 @@ public class MdeAuthServiceImpl implements MdeAuthService {
|
|
|
createLoginLog(null, account, logTypeEnum, LoginResultEnum.BAD_CREDENTIALS);
|
|
|
throw exception(MDE_USER_MOBILE_NOT_EXISTS);
|
|
|
}
|
|
|
+ // 校验是否禁用
|
|
|
+ if (ObjectUtil.notEqual(user.getStatus(), MendunerStatusEnum.ENABLE.getStatus())) {
|
|
|
+ createLoginLog(user.getId(), account, logTypeEnum, LoginResultEnum.USER_DISABLED);
|
|
|
+ throw exception(MDE_AUTH_LOGIN_USER_DISABLED);
|
|
|
+ }
|
|
|
+
|
|
|
if (!userService.isPasswordMatch(password, user.getPassword())) {
|
|
|
// 只有输错密码并且是首次才提示修改密码
|
|
|
if (null == user.getLoginDate()) {
|
|
@@ -155,15 +163,15 @@ public class MdeAuthServiceImpl implements MdeAuthService {
|
|
|
// 获取错误次数
|
|
|
String num =
|
|
|
redisTemplate.opsForValue()
|
|
|
- .get(String.format(MDE_AUTH_USER_PWD_LOCK, user.getPhone()));
|
|
|
+ .get(String.format(MDE_AUTH_USER_PWD_LOCK, user.getId()));
|
|
|
Integer numInt = Integer.parseInt(null == num ? "0" : num) + 1;
|
|
|
|
|
|
redisTemplate.opsForValue()
|
|
|
- .setIfAbsent(MDE_AUTH_USER_PWD_LOCK, String.valueOf(numInt), 8, TimeUnit.HOURS);
|
|
|
+ .set(String.format(MDE_AUTH_USER_PWD_LOCK, user.getId()), String.valueOf(numInt), 8, TimeUnit.HOURS);
|
|
|
if (numInt >= 5) {
|
|
|
// 8个小时内输错5次 锁定
|
|
|
userService.disable(Collections.singletonList(user.getId()));
|
|
|
- createLoginLog(user.getId(),account,logTypeEnum, LoginResultEnum.USER_DISABLED);
|
|
|
+ createLoginLog(user.getId(), account, logTypeEnum, LoginResultEnum.USER_DISABLED);
|
|
|
throw exception(MDE_AUTH_LOGIN_USER_DISABLED);
|
|
|
} else {
|
|
|
// 提示账户密码错误
|
|
@@ -173,11 +181,8 @@ public class MdeAuthServiceImpl implements MdeAuthService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 校验是否禁用
|
|
|
- if (ObjectUtil.notEqual(user.getStatus(), MendunerStatusEnum.ENABLE.getStatus())) {
|
|
|
- createLoginLog(user.getId(), account, logTypeEnum, LoginResultEnum.USER_DISABLED);
|
|
|
- throw exception(MDE_AUTH_LOGIN_USER_DISABLED);
|
|
|
- }
|
|
|
+ // 登录成功就清理
|
|
|
+ redisTemplate.delete(String.format(MDE_AUTH_USER_PWD_LOCK, user.getId()));
|
|
|
return user;
|
|
|
|
|
|
}
|
|
@@ -207,7 +212,6 @@ public class MdeAuthServiceImpl implements MdeAuthService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- @DSTransactional
|
|
|
public AppMdeAuthLoginRespVO smsLogin(AppMdeAuthSmsLoginReqVO reqVO) {
|
|
|
// 校验验证码
|
|
|
String userIp = getClientIP();
|
|
@@ -228,15 +232,21 @@ public class MdeAuthServiceImpl implements MdeAuthService {
|
|
|
Assert.notNull(user, "获取用户失败,结果为空");
|
|
|
}
|
|
|
|
|
|
+ // 是否禁用
|
|
|
+ if (ObjectUtil.notEqual(user.getStatus(), MendunerStatusEnum.ENABLE.getStatus())) {
|
|
|
+ createLoginLog(user.getId(), user.getPhone(), LoginLogTypeEnum.LOGIN_SMS, LoginResultEnum.USER_DISABLED);
|
|
|
+ throw exception(MDE_AUTH_LOGIN_USER_DISABLED);
|
|
|
+ }
|
|
|
+
|
|
|
if (result.isError()) {
|
|
|
// 获取错误次数
|
|
|
String num =
|
|
|
redisTemplate.opsForValue()
|
|
|
- .get(String.format(MDE_AUTH_USER_SMS_CODE_LOCK, reqVO.getPhone()));
|
|
|
+ .get(String.format(MDE_AUTH_USER_SMS_CODE_LOCK, user.getId()));
|
|
|
Integer numInt = Integer.parseInt(null == num ? "0" : num) + 1;
|
|
|
|
|
|
redisTemplate.opsForValue()
|
|
|
- .setIfAbsent(MDE_AUTH_USER_SMS_CODE_LOCK, String.valueOf(numInt), 8, TimeUnit.HOURS);
|
|
|
+ .set(String.format(MDE_AUTH_USER_SMS_CODE_LOCK, user.getId()), String.valueOf(numInt), 8, TimeUnit.HOURS);
|
|
|
|
|
|
if (numInt >= 5) {
|
|
|
// 8个小时内输错5次 锁定
|
|
@@ -249,12 +259,6 @@ public class MdeAuthServiceImpl implements MdeAuthService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 是否禁用
|
|
|
- if (ObjectUtil.notEqual(user.getStatus(), MendunerStatusEnum.ENABLE.getStatus())) {
|
|
|
- createLoginLog(user.getId(), user.getPhone(), LoginLogTypeEnum.LOGIN_SMS, LoginResultEnum.USER_DISABLED);
|
|
|
- throw exception(MDE_AUTH_LOGIN_USER_DISABLED);
|
|
|
- }
|
|
|
-
|
|
|
// 如果 socialType 非空,说明需要绑定社交用户
|
|
|
String openid = null;
|
|
|
if (reqVO.getSocialType() != null) {
|
|
@@ -262,7 +266,7 @@ public class MdeAuthServiceImpl implements MdeAuthService {
|
|
|
reqVO.getSocialType(), reqVO.getSocialCode(), reqVO.getSocialState())).getCheckedData();
|
|
|
}
|
|
|
// 登录成功就清理
|
|
|
- redisTemplate.delete(MDE_AUTH_USER_SMS_CODE_LOCK);
|
|
|
+ redisTemplate.delete(String.format(MDE_AUTH_USER_SMS_CODE_LOCK, user.getId()));
|
|
|
// 创建 Token 令牌,记录登录日志
|
|
|
return createTokenAfterLoginSuccess(user, reqVO.getPhone(), LoginLogTypeEnum.LOGIN_SMS, openid);
|
|
|
}
|