|
@@ -9,6 +9,7 @@ import cn.kdan.cloud.pdf.office.api.email.bo.EmailSendBO;
|
|
|
import cn.kdan.cloud.pdf.office.api.email.feign.EmailApi;
|
|
|
import cn.kdan.cloud.pdf.office.common.constant.CommonConstant;
|
|
|
import cn.kdan.cloud.pdf.office.common.dto.UserRegisterDTO;
|
|
|
+import cn.kdan.cloud.pdf.office.common.dto.UserResetPasswordDTO;
|
|
|
import cn.kdan.cloud.pdf.office.common.enums.EmailCodeTypeEnum;
|
|
|
import cn.kdan.cloud.pdf.office.common.exception.BackendRuntimeException;
|
|
|
import cn.kdan.cloud.pdf.office.common.pojo.CustomUserDetails;
|
|
@@ -20,6 +21,7 @@ import cn.kdan.cloud.pdf.office.common.vo.UserInfoVO;
|
|
|
import cn.kdan.cloud.pdf.office.sso.constant.AuthConstant;
|
|
|
import cn.kdan.cloud.pdf.office.sso.enums.VerifyTypeEnum;
|
|
|
import cn.kdan.cloud.pdf.office.sso.service.AuthService;
|
|
|
+import cn.kdan.cloud.pdf.office.sso.utils.RSAUtils;
|
|
|
import cn.kdan.cloud.pdf.office.sso.utils.TokenUtils;
|
|
|
import com.alibaba.nacos.common.utils.CollectionUtils;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
@@ -135,6 +137,7 @@ public class AuthServiceImpl implements AuthService {
|
|
|
UserInfoVO userInfoVO = userApi.getByAppAccount(email,appId,platformType).getResult();
|
|
|
//检查用户存在
|
|
|
checkUser(userInfoVO);
|
|
|
+ checkPassword(password,userInfoVO.getDigestPassword());
|
|
|
//检查邮件验证码
|
|
|
// checkEmailCodeValid(EmailCodeTypeEnum.LOGIN,email,code);
|
|
|
// 检查设备是否达到上限
|
|
@@ -145,9 +148,16 @@ public class AuthServiceImpl implements AuthService {
|
|
|
return vo;
|
|
|
}
|
|
|
|
|
|
+ private void checkPassword (String userPassword,String realPassword){
|
|
|
+ realPassword = new RSAUtils().decrypt(realPassword);
|
|
|
+ if(!userPassword.equals(realPassword)){
|
|
|
+ throw new BackendRuntimeException(AuthConstant.EXCEPTION_MSG_PASSWORD_ERROR);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
public TokenVO emailRegister(UserRegisterDTO userRegisterDTO) {
|
|
|
+ validUserRegisterParam(userRegisterDTO);
|
|
|
ResultMap<Boolean> resultMap = userApi.register(userRegisterDTO);
|
|
|
if(resultMap.getCode() == CommonConstant.SUCCESS){
|
|
|
//如果是管理平台就去查管理平台的用户表
|
|
@@ -162,6 +172,55 @@ public class AuthServiceImpl implements AuthService {
|
|
|
throw new BackendRuntimeException(AuthConstant.EMAIL_REGISTER_ERROR);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void resetPassword(UserResetPasswordDTO userResetPasswordDTO) {
|
|
|
+ //检查验证码
|
|
|
+ checkEmailCodeValid(EmailCodeTypeEnum.USER_RESET_PASSWORD,userResetPasswordDTO.getAccount(),userResetPasswordDTO.getVerifyCode(), userResetPasswordDTO.getAppId());
|
|
|
+ if(!userResetPasswordDTO.getFirstPassword().equals(userResetPasswordDTO.getSecondPassword())){
|
|
|
+ throw new BackendRuntimeException(AuthConstant.EXCEPTION_MSG_PASSWORD_NOT_INCONSISTENT);
|
|
|
+ }
|
|
|
+ //检查密码长度
|
|
|
+ if(userResetPasswordDTO.getFirstPassword().length()>6&&userResetPasswordDTO.getFirstPassword().length()<6){
|
|
|
+ throw new BackendRuntimeException(AuthConstant.EXCEPTION_MSG_PASSWORD_SIZE_MIN);
|
|
|
+ }
|
|
|
+ if(userResetPasswordDTO.getFirstPassword().length()>6&&userResetPasswordDTO.getFirstPassword().length()>24){
|
|
|
+ throw new BackendRuntimeException(AuthConstant.EXCEPTION_MSG_PASSWORD_SIZE_MAX);
|
|
|
+ }
|
|
|
+ UserInfoVO userInfoVO = userApi.getByAppAccount(userResetPasswordDTO.getAccount(),userResetPasswordDTO.getAppId(),userResetPasswordDTO.getPlatformType()).getResult();
|
|
|
+ //修改密码
|
|
|
+ userInfoVO.setUpdatedAt(new Date());
|
|
|
+ userInfoVO.setDigestPassword(new RSAUtils().encrypt(userResetPasswordDTO.getFirstPassword()));
|
|
|
+ userApi.updateUser(userInfoVO);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void validUserRegisterParam(UserRegisterDTO param) {
|
|
|
+ //邮箱是否被注册
|
|
|
+ if (!ObjectUtils.isEmpty(userApi.getByAppAccount(param.getUsername(),param.getAppId(),param.getPlatformType()).getResult())) {
|
|
|
+ throw new BackendRuntimeException(AuthConstant.EXCEPTION_MSG_EMAIL_EXIST);
|
|
|
+ }
|
|
|
+ //验证邮箱格式
|
|
|
+ String emailRegex = CommonConstant.emailRegex;
|
|
|
+ if (!param.getUsername().matches(emailRegex)) {
|
|
|
+ throw new BackendRuntimeException(AuthConstant.EXCEPTION_MSG_EMAIL_INVALID);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void validUserLoginParam(UserRegisterDTO param) {
|
|
|
+ //邮箱是否被注册
|
|
|
+ if (ObjectUtils.isEmpty(userApi.getByAppAccount(param.getUsername(),param.getAppId(),param.getPlatformType()).getResult())) {
|
|
|
+ throw new BackendRuntimeException(AuthConstant.EXCEPTION_MSG_EMAIL_NOT_REGISTER);
|
|
|
+ }
|
|
|
+ //验证邮箱格式
|
|
|
+ String emailRegex = CommonConstant.emailRegex;
|
|
|
+ if (!param.getUsername().matches(emailRegex)) {
|
|
|
+ throw new BackendRuntimeException(AuthConstant.EXCEPTION_MSG_EMAIL_INVALID);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public boolean getVerifyCode(EmailCodeTypeEnum action, VerifyTypeEnum type, String receiver, String appId) {
|
|
|
boolean flag = false;
|
|
@@ -236,7 +295,7 @@ public class AuthServiceImpl implements AuthService {
|
|
|
*/
|
|
|
private void checkUser(UserInfoVO userInfoVO) {
|
|
|
if (ObjectUtils.isEmpty(userInfoVO)) {
|
|
|
- throw new BackendRuntimeException(AuthConstant.EXCEPTION_MSG_USER_NOT_FOUND);
|
|
|
+ throw new BackendRuntimeException(AuthConstant.EXCEPTION_MSG_EMAIL_EXIST);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -261,12 +320,12 @@ public class AuthServiceImpl implements AuthService {
|
|
|
* @param account 用户
|
|
|
* @param code 验证码
|
|
|
*/
|
|
|
- private void checkEmailCodeValid(EmailCodeTypeEnum type, String account, String code) {
|
|
|
+ private void checkEmailCodeValid(EmailCodeTypeEnum type, String account, String code, String appId) {
|
|
|
//获取用户存在redis中的登录邮箱验证码
|
|
|
- String captchaCode = redisUtils.hget(CommonConstant.EMAIL_VERIFY_CODE_KEY + type.value(), account);
|
|
|
+ String captchaCode = redisUtils.hget(CommonConstant.EMAIL_VERIFY_CODE_KEY + type.value() + CommonConstant.STRIKE_THROUGH + appId, account);
|
|
|
if(StringUtils.isNotEmpty(code) && code.equals(captchaCode)){
|
|
|
//验证通过删除
|
|
|
- redisUtils.hdel(CommonConstant.EMAIL_VERIFY_CODE_KEY + type.value(), account);
|
|
|
+ redisUtils.hdel(CommonConstant.EMAIL_VERIFY_CODE_KEY + type.value() + CommonConstant.STRIKE_THROUGH + appId, account);
|
|
|
}else{
|
|
|
throw new BackendRuntimeException(CommonConstant.EMAIL_VERIFY_CODE_KEY_ERROR);
|
|
|
}
|