Commit bde8b9b5 by weisong

t Merge branch 'master' of…

t Merge branch 'master' of http://git.gdatac.com/sundelong/cnooc_zydeepen-cggl_expert-manage-miniapp
parents 862ae7c0 654783e3
......@@ -4,6 +4,7 @@ import cn.hutool.core.lang.Validator;
import cn.hutool.core.util.IdcardUtil;
import com.cnooc.expert.common.constant.TokenConstants;
import com.cnooc.expert.common.exception.BusinessException;
import com.cnooc.expert.common.exception.GlobalErrorCodeConstants;
import com.cnooc.expert.common.utils.JwtUtils;
import com.cnooc.expert.common.utils.Sm2Util;
import com.cnooc.expert.common.utils.ValidUtils;
......@@ -64,6 +65,7 @@ public class LoginServiceImpl implements LoginService {
@Override
public String login(LoginVO loginVO) {
log.info("开始执行登录逻辑");
ValidUtils.isNotNull(loginVO.getLoginType(), GlobalErrorCodeConstants.PARAM_REQUIRED);
String token;
switch (loginVO.getLoginType()) {
case ID_NUMBER_PASSWORD:
......@@ -93,11 +95,11 @@ public class LoginServiceImpl implements LoginService {
//return Result.success("验证码已发送");
boolean flag = sysCaptchaService.validate(vo.getKey(), vo.getCaptcha());
if(!flag){
return "验证码错误";
throw new BusinessException(GlobalErrorCodeConstants.CAPTCHA_EXPIRED.getCode(),GlobalErrorCodeConstants.CAPTCHA_EXPIRED.getMsg());
}else{
boolean smsfalg = smsService.sendSmsCode(vo.getPhoneNumber());
if(!smsfalg) {
return "短信验证码发送失败";
throw new BusinessException(GlobalErrorCodeConstants.SEND_SMS_ERROR.getCode(),GlobalErrorCodeConstants.SEND_SMS_ERROR.getMsg());
} else {
return "短信验证码发送成功";
}
......@@ -111,10 +113,11 @@ public class LoginServiceImpl implements LoginService {
ValidUtils.isText(loginVO.getPhoneCode(), "请输入验证码");
ValidUtils.isTrue(Validator.isMobile(loginVO.getPhoneNumber()), "请输入正确格式的手机号");
ValidUtils.isText(loginVO.getPassword(), "请输入密码");
ValidUtils.isValidPassword(loginVO.getPassword(),GlobalErrorCodeConstants.PARAM_PASSWORD_FORMAT_ERROR);
//1.根据手机号去库中查询是否存在
ExpertInfoResp expertInfoResp = loginServicesClient.querySingleByShengFenZhengOrMobile(loginVO.getPhoneNumber(),null);
if(expertInfoResp == null){
return "用户信息不存在";
throw new BusinessException(GlobalErrorCodeConstants.USER_NOT_EXISTS.getCode(),GlobalErrorCodeConstants.USER_NOT_EXISTS.getMsg());
}
//2.判断密码是否存在
ExpertInfoAppResp expertInfoAppResp = loginServicesClient.getZhuanJiaInfoAppById(expertInfoResp.getZhuanJiaGuid());
......@@ -130,15 +133,18 @@ public class LoginServiceImpl implements LoginService {
//判断密码是否符合规则
//进行解密处理
//调用数据库更新密码
return "ok";
return "密码重置成功";
}
@Override
public String verifyCode(VerifyCodeVO codeVO) {
log.info("手机验证码验证逻辑");
ValidUtils.isText(codeVO.getPhoneNumber(), "请输入手机号");
ValidUtils.isText(codeVO.getPhoneCode(), "请输入验证码");
ValidUtils.isTrue(Validator.isMobile(codeVO.getPhoneNumber()), "请输入正确格式的手机号");
boolean smsfalg = smsService.verifySmsCode(codeVO.getPhoneNumber(),codeVO.getPhoneCode());
if(!smsfalg){
return "短信验证码验证失败";
throw new BusinessException(GlobalErrorCodeConstants.CAPTCHA_EXPIRED.getCode(),GlobalErrorCodeConstants.CAPTCHA_EXPIRED.getMsg());
}else{
return "短信验证码验证成功";
}
......@@ -155,20 +161,21 @@ public class LoginServiceImpl implements LoginService {
ValidUtils.isText(loginVO.getIdNumber(), "请输入身份证号");
ValidUtils.isText(loginVO.getPassword(), "请输入密码");
ValidUtils.isTrue(IdcardUtil.isValidCard(loginVO.getIdNumber()), "请输入正确的身份证号");
ValidUtils.isValidPassword(loginVO.getPassword(),GlobalErrorCodeConstants.PARAM_PASSWORD_FORMAT_ERROR);
ExpertInfoResp expertInfoResp = loginServicesClient.querySingleByShengFenZhengOrMobile(null,loginVO.getIdNumber());
if(expertInfoResp == null){
return "用户信息不存在";
throw new BusinessException(GlobalErrorCodeConstants.USER_NOT_EXISTS.getCode(),GlobalErrorCodeConstants.USER_NOT_EXISTS.getMsg());
}
ExpertInfoAppResp expertInfoAppResp = loginServicesClient.getZhuanJiaInfoAppById(expertInfoResp.getZhuanJiaGuid());
if(expertInfoAppResp == null){
return "该用户还没有设置密码";
throw new BusinessException(GlobalErrorCodeConstants.PASSWORD_NOT_EXIST.getCode(),GlobalErrorCodeConstants.PASSWORD_NOT_EXIST.getMsg());
}
// 验证码效验
boolean flag = sysCaptchaService.validate(loginVO.getKey(), loginVO.getCaptcha());
if (!flag) {
// 保存登录日志
//sysLogLoginService.save(login.getUsername(), Constant.FAIL, LoginOperationEnum.CAPTCHA_FAIL.getValue());
throw new BusinessException("图形验证码错误");
throw new BusinessException(GlobalErrorCodeConstants.CAPTCHA_EXPIRED.getCode(),GlobalErrorCodeConstants.CAPTCHA_EXPIRED.getMsg());
}
//1.需要去库中查询,是否存在
//2.存在校验密码
......@@ -178,7 +185,7 @@ public class LoginServiceImpl implements LoginService {
if (!flag) {
// 登录日志
//sysLogLoginService.savePortal(login.getAccountName(), Constant.FAIL, LoginOperationEnum.ACCOUNT_FAIL.getValue(), 1);
throw new BusinessException("密码错误");
throw new BusinessException(GlobalErrorCodeConstants.PASSWORD_ERROR.getCode(),GlobalErrorCodeConstants.PASSWORD_ERROR.getMsg());
}
//3.生成相应的uuid作为redis的key
......@@ -205,13 +212,13 @@ public class LoginServiceImpl implements LoginService {
//1.根据手机号去库中查询是否存在
ExpertInfoResp expertInfoResp = loginServicesClient.querySingleByShengFenZhengOrMobile(loginVO.getPhoneNumber(),null);
if(expertInfoResp == null){
return "用户信息不存在";
throw new BusinessException(GlobalErrorCodeConstants.USER_NOT_EXISTS.getCode(),GlobalErrorCodeConstants.USER_NOT_EXISTS.getMsg());
}
//2.存在校验验证码
if (!smsService.verifySmsCode(loginVO.getPhoneNumber(), loginVO.getPhoneCode())) {
//登录日志
//sysLogLoginService.savePortal(login.getPhone(), Constant.FAIL, LoginOperationEnum.CAPTCHA_FAIL.getValue(), 1);
throw new IllegalArgumentException("手机验证码错误");
throw new BusinessException(GlobalErrorCodeConstants.CAPTCHA_EXPIRED.getCode(),GlobalErrorCodeConstants.CAPTCHA_EXPIRED.getMsg());
}
//3.生成相应的uuid作为redis的key
String uuidKey = UUID.randomUUID().toString();
......
......@@ -18,17 +18,20 @@ public interface GlobalErrorCodeConstants {
ErrorCode CAPTCHA_EXPIRED = new ErrorCode(1011, "验证码错误");
ErrorCode CODE_REDIS_KEY = new ErrorCode(1011, "验证码已过期");
ErrorCode SYSTEM_ERROR = new ErrorCode(1012, "系统内部异常");
ErrorCode SEND_SMS_ERROR = new ErrorCode(1013, "发送短信验证码失败");
// ========== 用户认证相关错误 (2000-2999) ==========
ErrorCode LOGIN_EXPIRED = new ErrorCode(2001, "请先登录");
ErrorCode USER_NOT_EXISTS = new ErrorCode(2002, "用户不存在");
ErrorCode PASSWORD_ERROR = new ErrorCode(2003, "密码错误");
ErrorCode USER_DISABLED = new ErrorCode(2004, "用户已被禁用");
ErrorCode PASSWORD_NOT_EXIST = new ErrorCode(2005, "密码不存在,请先重置密码");
// ========== 参数校验错误 (3000-3999) ==========
ErrorCode PARAM_REQUIRED = new ErrorCode(3001, "必填字段不能为空");
ErrorCode PARAM_FORMAT_ERROR = new ErrorCode(3002, "参数格式不正确");
ErrorCode PARAM_RANGE_ERROR = new ErrorCode(3003, "参数超出范围");
ErrorCode PARAM_PASSWORD_FORMAT_ERROR = new ErrorCode(3004, "密码强度不符合要求:密码必须包含大小写字母、数字和特殊字符,且长度不少于8位");
// ========== 业务逻辑错误 (4000-4999) ==========
ErrorCode OPERATION_TOO_FREQUENT = new ErrorCode(4001, "操作太频繁,请稍后再试");
......
......@@ -90,5 +90,11 @@ public class ValidUtils {
}
}
//判断是否有效的密码
public static void isValidPassword(String password, ErrorCode errorCode) {
String passwordRegex = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[!@#$%^&*()_+\\-=\\[\\]{};':\"\\\\|,.<>\\/?~`])[a-zA-Z\\d!@#$%^&*()_+\\-=\\[\\]{};':\"\\\\|,.<>\\/?~`]{8,}$";
if (!password.matches(passwordRegex)) {
throw new BusinessException(errorCode.getCode(), errorCode.getMsg());
}
}
}
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