|
|
@@ -140,17 +140,17 @@ public class AuthServiceImpl implements AuthService {
|
|
|
private void validValidCode(String phoneOrEmail, String validCode, String validCodeReqNo) {
|
|
|
// 依据请求号,取出缓存中的验证码进行校验
|
|
|
Object existValidCode;
|
|
|
- if(ObjectUtil.isEmpty(phoneOrEmail)) {
|
|
|
+ if (ObjectUtil.isEmpty(phoneOrEmail)) {
|
|
|
existValidCode = commonCacheOperator.get(AUTH_VALID_CODE_CACHE_KEY + validCodeReqNo);
|
|
|
} else {
|
|
|
existValidCode = commonCacheOperator.get(AUTH_VALID_CODE_CACHE_KEY + phoneOrEmail + StrUtil.UNDERLINE + validCodeReqNo);
|
|
|
}
|
|
|
// 为空则直接验证码错误
|
|
|
- if(ObjectUtil.isEmpty(existValidCode)) {
|
|
|
+ if (ObjectUtil.isEmpty(existValidCode)) {
|
|
|
throw new CommonException(AuthExceptionEnum.VALID_CODE_ERROR.getValue());
|
|
|
}
|
|
|
// 移除该验证码
|
|
|
- if(ObjectUtil.isEmpty(phoneOrEmail)) {
|
|
|
+ if (ObjectUtil.isEmpty(phoneOrEmail)) {
|
|
|
commonCacheOperator.remove(AUTH_VALID_CODE_CACHE_KEY + validCodeReqNo);
|
|
|
} else {
|
|
|
commonCacheOperator.remove(AUTH_VALID_CODE_CACHE_KEY + phoneOrEmail + StrUtil.UNDERLINE + validCodeReqNo);
|
|
|
@@ -169,23 +169,23 @@ public class AuthServiceImpl implements AuthService {
|
|
|
**/
|
|
|
private void validPhoneValidCodeParam(String phoneOrEmail, String validCode, String validCodeReqNo, String type) {
|
|
|
// 验证码正确则校验手机号格式
|
|
|
- if(ObjectUtil.isEmpty(phoneOrEmail)) {
|
|
|
+ if (ObjectUtil.isEmpty(phoneOrEmail)) {
|
|
|
// 执行校验验证码
|
|
|
validValidCode(null, validCode, validCodeReqNo);
|
|
|
} else {
|
|
|
- if(!PhoneUtil.isMobile(phoneOrEmail) && !CommonEmailUtil.isEmail(phoneOrEmail)) {
|
|
|
+ if (!PhoneUtil.isMobile(phoneOrEmail) && !CommonEmailUtil.isEmail(phoneOrEmail)) {
|
|
|
throw new CommonException(AuthExceptionEnum.PHONE_FORMAT_ERROR.getValue());
|
|
|
}
|
|
|
// 执行校验验证码
|
|
|
validValidCode(phoneOrEmail, validCode, validCodeReqNo);
|
|
|
|
|
|
// 根据手机号获取用户信息,判断用户是否存在,根据B端或C端判断
|
|
|
- if(SaClientTypeEnum.B.getValue().equals(type)) {
|
|
|
- if(ObjectUtil.isEmpty(loginUserApi.getUserByPhone(phoneOrEmail))) {
|
|
|
+ if (SaClientTypeEnum.B.getValue().equals(type)) {
|
|
|
+ if (ObjectUtil.isEmpty(loginUserApi.getUserByPhone(phoneOrEmail))) {
|
|
|
throw new CommonException(AuthExceptionEnum.PHONE_ERROR.getValue());
|
|
|
}
|
|
|
} else {
|
|
|
- if(ObjectUtil.isEmpty(clientLoginUserApi.getClientUserByPhone(phoneOrEmail))) {
|
|
|
+ if (ObjectUtil.isEmpty(clientLoginUserApi.getClientUserByPhone(phoneOrEmail))) {
|
|
|
throw new CommonException(AuthExceptionEnum.PHONE_ERROR.getValue());
|
|
|
}
|
|
|
}
|
|
|
@@ -203,25 +203,25 @@ public class AuthServiceImpl implements AuthService {
|
|
|
// 获取设备
|
|
|
String device = authAccountPasswordLoginParam.getDevice();
|
|
|
// 默认指定为PC,如在小程序跟移动端的情况下,自行指定即可
|
|
|
- if(ObjectUtil.isEmpty(device)) {
|
|
|
+ if (ObjectUtil.isEmpty(device)) {
|
|
|
device = AuthDeviceTypeEnum.PC.getValue();
|
|
|
} else {
|
|
|
AuthDeviceTypeEnum.validate(device);
|
|
|
}
|
|
|
// 校验验证码
|
|
|
String defaultCaptchaOpen = devConfigApi.getValueByKey(SNOWY_SYS_DEFAULT_CAPTCHA_OPEN_KEY);
|
|
|
- if(ObjectUtil.isNotEmpty(defaultCaptchaOpen)) {
|
|
|
- if(Convert.toBool(defaultCaptchaOpen)) {
|
|
|
+ if (ObjectUtil.isNotEmpty(defaultCaptchaOpen)) {
|
|
|
+ if (Convert.toBool(defaultCaptchaOpen)) {
|
|
|
// 获取验证码
|
|
|
String validCode = authAccountPasswordLoginParam.getValidCode();
|
|
|
// 获取验证码请求号
|
|
|
String validCodeReqNo = authAccountPasswordLoginParam.getValidCodeReqNo();
|
|
|
// 开启验证码则必须传入验证码
|
|
|
- if(ObjectUtil.isEmpty(validCode)) {
|
|
|
+ if (ObjectUtil.isEmpty(validCode)) {
|
|
|
throw new CommonException(AuthExceptionEnum.VALID_CODE_EMPTY.getValue());
|
|
|
}
|
|
|
// 开启验证码则必须传入验证码请求号
|
|
|
- if(ObjectUtil.isEmpty(validCodeReqNo)) {
|
|
|
+ if (ObjectUtil.isEmpty(validCodeReqNo)) {
|
|
|
throw new CommonException(AuthExceptionEnum.VALID_CODE_REQ_NO_EMPTY.getValue());
|
|
|
}
|
|
|
// 执行校验验证码
|
|
|
@@ -237,9 +237,9 @@ public class AuthServiceImpl implements AuthService {
|
|
|
throw new CommonException(AuthExceptionEnum.PWD_DECRYPT_ERROR.getValue());
|
|
|
}
|
|
|
// 根据账号获取用户信息,根据B端或C端判断
|
|
|
- if(SaClientTypeEnum.B.getValue().equals(type)) {
|
|
|
+ if (SaClientTypeEnum.B.getValue().equals(type)) {
|
|
|
SaBaseLoginUser saBaseLoginUser = loginUserApi.getUserByAccount(account);
|
|
|
- if(ObjectUtil.isEmpty(saBaseLoginUser)) {
|
|
|
+ if (ObjectUtil.isEmpty(saBaseLoginUser)) {
|
|
|
throw new CommonException(AuthExceptionEnum.ACCOUNT_ERROR.getValue());
|
|
|
}
|
|
|
if (!saBaseLoginUser.getPassword().equals(passwordHash)) {
|
|
|
@@ -253,7 +253,7 @@ public class AuthServiceImpl implements AuthService {
|
|
|
return execLoginB(saBaseLoginUser, device);
|
|
|
} else {
|
|
|
SaBaseClientLoginUser saBaseClientLoginUser = clientLoginUserApi.getClientUserByAccount(account);
|
|
|
- if(ObjectUtil.isEmpty(saBaseClientLoginUser)) {
|
|
|
+ if (ObjectUtil.isEmpty(saBaseClientLoginUser)) {
|
|
|
throw new CommonException(AuthExceptionEnum.ACCOUNT_ERROR.getValue());
|
|
|
}
|
|
|
if (!saBaseClientLoginUser.getPassword().equals(passwordHash)) {
|
|
|
@@ -273,22 +273,22 @@ public class AuthServiceImpl implements AuthService {
|
|
|
// 设备
|
|
|
String device = authPhoneValidCodeLoginParam.getDevice();
|
|
|
// 默认指定为PC,如在小程序跟移动端的情况下,自行指定即可
|
|
|
- if(ObjectUtil.isEmpty(device)) {
|
|
|
+ if (ObjectUtil.isEmpty(device)) {
|
|
|
device = AuthDeviceTypeEnum.PC.getValue();
|
|
|
} else {
|
|
|
AuthDeviceTypeEnum.validate(device);
|
|
|
}
|
|
|
// 根据手机号获取用户信息,根据B端或C端判断
|
|
|
- if(SaClientTypeEnum.B.getValue().equals(type)) {
|
|
|
+ if (SaClientTypeEnum.B.getValue().equals(type)) {
|
|
|
SaBaseLoginUser saBaseLoginUser = loginUserApi.getUserByPhone(phone);
|
|
|
- if(ObjectUtil.isEmpty(saBaseLoginUser)) {
|
|
|
+ if (ObjectUtil.isEmpty(saBaseLoginUser)) {
|
|
|
throw new CommonException(AuthExceptionEnum.ACCOUNT_ERROR.getValue());
|
|
|
}
|
|
|
// 执行B端登录
|
|
|
return execLoginB(saBaseLoginUser, device);
|
|
|
} else {
|
|
|
SaBaseClientLoginUser saBaseClientLoginUser = clientLoginUserApi.getClientUserByPhone(phone);
|
|
|
- if(ObjectUtil.isEmpty(saBaseClientLoginUser)) {
|
|
|
+ if (ObjectUtil.isEmpty(saBaseClientLoginUser)) {
|
|
|
throw new CommonException(AuthExceptionEnum.ACCOUNT_ERROR.getValue());
|
|
|
}
|
|
|
// 执行C端登录
|
|
|
@@ -296,6 +296,14 @@ public class AuthServiceImpl implements AuthService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public String doLoginByOpenId(String openId, SaBaseLoginUser user) {
|
|
|
+ // 设备
|
|
|
+ String device = AuthDeviceTypeEnum.MINI.getValue();
|
|
|
+ // 执行B端登录
|
|
|
+ return execLoginB(user, device);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 是否封禁状态
|
|
|
* 如果被封禁了,执行以下逻辑,返回前端还需等待的时间
|
|
|
@@ -305,25 +313,25 @@ public class AuthServiceImpl implements AuthService {
|
|
|
long disableTime = StpUtil.getDisableTime(userAccount);
|
|
|
if (disableTime > 0) {
|
|
|
if (disableTime > 60) {
|
|
|
- throw new CommonException(userAccount + "账号已被封禁, 请再"+ disableTime/60+ "分钟后重新尝试登录!!");
|
|
|
+ throw new CommonException(userAccount + "账号已被封禁, 请再" + disableTime / 60 + "分钟后重新尝试登录!!");
|
|
|
}
|
|
|
- throw new CommonException(userAccount + "账号已被封禁, 请再"+ disableTime+ "秒后重新尝试登录!!");
|
|
|
+ throw new CommonException(userAccount + "账号已被封禁, 请再" + disableTime + "秒后重新尝试登录!!");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// redis中保存登录错误次数
|
|
|
- private void saveLoginTimes(String userAccount){
|
|
|
+ private void saveLoginTimes(String userAccount) {
|
|
|
String loginErrorKey = LOGIN_ERROR_TIMES_KEY_PREFIX + userAccount;
|
|
|
Integer number = (Integer) commonCacheOperator.get(loginErrorKey);
|
|
|
if (number == null) {
|
|
|
// 如果redis中没有保存,代表失败第一次
|
|
|
number = 2;
|
|
|
- commonCacheOperator.put(loginErrorKey, number,5 * 60);
|
|
|
+ commonCacheOperator.put(loginErrorKey, number, 5 * 60);
|
|
|
return;
|
|
|
}
|
|
|
if (number < 5) {
|
|
|
number++;
|
|
|
- commonCacheOperator.put(loginErrorKey, number,5 * 60);
|
|
|
+ commonCacheOperator.put(loginErrorKey, number, 5 * 60);
|
|
|
return;
|
|
|
}
|
|
|
// 第五次封禁账号,第六次进入isDisableTime方法,返回用户还需等待时间
|
|
|
@@ -335,6 +343,7 @@ public class AuthServiceImpl implements AuthService {
|
|
|
|
|
|
/**
|
|
|
* 登录成功、清空登录次数
|
|
|
+ *
|
|
|
* @param userAccount 账号
|
|
|
*/
|
|
|
private void clearLoginErrorTimes(String userAccount) {
|
|
|
@@ -351,7 +360,7 @@ public class AuthServiceImpl implements AuthService {
|
|
|
**/
|
|
|
private String execLoginB(SaBaseLoginUser saBaseLoginUser, String device) {
|
|
|
// 校验状态
|
|
|
- if(!saBaseLoginUser.getEnabled()) {
|
|
|
+ if (!saBaseLoginUser.getEnabled()) {
|
|
|
throw new CommonException(AuthExceptionEnum.ACCOUNT_DISABLED.getValue());
|
|
|
}
|
|
|
// 执行登录
|
|
|
@@ -390,7 +399,7 @@ public class AuthServiceImpl implements AuthService {
|
|
|
// 设置权限码
|
|
|
saBaseLoginUser.setPermissionCodeList(permissionCodeList);
|
|
|
// 权限码列表存入缓存
|
|
|
- commonCacheOperator.put(CacheConstant.AUTH_B_PERMISSION_LIST_CACHE_KEY + saBaseLoginUser.getId(),permissionCodeList);
|
|
|
+ commonCacheOperator.put(CacheConstant.AUTH_B_PERMISSION_LIST_CACHE_KEY + saBaseLoginUser.getId(), permissionCodeList);
|
|
|
// 获取角色码
|
|
|
saBaseLoginUser.setRoleCodeList(roleCodeList);
|
|
|
// 缓存用户信息,此处使用TokenSession为了指定时间内无操作则自动下线
|
|
|
@@ -405,7 +414,7 @@ public class AuthServiceImpl implements AuthService {
|
|
|
**/
|
|
|
private String execLoginC(SaBaseClientLoginUser saBaseClientLoginUser, String device) {
|
|
|
// 校验状态
|
|
|
- if(!saBaseClientLoginUser.getEnabled()) {
|
|
|
+ if (!saBaseClientLoginUser.getEnabled()) {
|
|
|
throw new CommonException(AuthExceptionEnum.ACCOUNT_DISABLED.getValue());
|
|
|
}
|
|
|
// 执行登录
|
|
|
@@ -444,7 +453,7 @@ public class AuthServiceImpl implements AuthService {
|
|
|
// 设置权限码
|
|
|
saBaseClientLoginUser.setPermissionCodeList(permissionCodeList);
|
|
|
// 权限码列表存入缓存
|
|
|
- commonCacheOperator.put(CacheConstant.AUTH_C_PERMISSION_LIST_CACHE_KEY + saBaseClientLoginUser.getId(),permissionCodeList);
|
|
|
+ commonCacheOperator.put(CacheConstant.AUTH_C_PERMISSION_LIST_CACHE_KEY + saBaseClientLoginUser.getId(), permissionCodeList);
|
|
|
// 获取角色码
|
|
|
saBaseClientLoginUser.setRoleCodeList(roleCodeList);
|
|
|
// 缓存用户信息,此处使用TokenSession为了指定时间内无操作则自动下线
|
|
|
@@ -502,7 +511,7 @@ public class AuthServiceImpl implements AuthService {
|
|
|
@Override
|
|
|
public String doLoginById(String userId, String device, String type) {
|
|
|
// 根据id获取用户信息,根据B端或C端判断
|
|
|
- if(SaClientTypeEnum.B.getValue().equals(type)) {
|
|
|
+ if (SaClientTypeEnum.B.getValue().equals(type)) {
|
|
|
SaBaseLoginUser saBaseLoginUser = loginUserApi.getUserById(userId);
|
|
|
if (ObjectUtil.isEmpty(saBaseLoginUser)) {
|
|
|
throw new CommonException(AuthExceptionEnum.ACCOUNT_ERROR.getValue());
|