邮箱-重置密码
This commit is contained in:
@@ -24,11 +24,13 @@ import com.accompany.core.service.common.JedisService;
|
||||
import com.accompany.core.service.user.UserCancelRecordService;
|
||||
import com.accompany.core.service.user.UsersBaseService;
|
||||
import com.accompany.core.util.MD5;
|
||||
import com.accompany.email.service.EmailService;
|
||||
import com.accompany.oauth2.constant.LoginTypeEnum;
|
||||
import com.accompany.oauth2.dto.DayIpMaxRegisterLimitConfig;
|
||||
import com.accompany.oauth2.dto.RepeatedDeviceIpRegisterLimitConfig;
|
||||
import com.accompany.oauth2.event.UserRegisterSuccessEvent;
|
||||
import com.accompany.oauth2.exception.CustomOAuth2Exception;
|
||||
import com.accompany.sms.service.SmsService;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.google.gson.Gson;
|
||||
import lombok.SneakyThrows;
|
||||
@@ -50,33 +52,28 @@ public class AccountManageService {
|
||||
|
||||
@Autowired
|
||||
private JedisService jedisService;
|
||||
|
||||
@Autowired
|
||||
private JedisLockService jedisLockService;
|
||||
|
||||
@Autowired
|
||||
private AccountMapper accountMapper;
|
||||
|
||||
@Autowired
|
||||
private NetEaseService netEaseService;
|
||||
|
||||
@Autowired
|
||||
private ErBanNoService erBanNoService;
|
||||
|
||||
@Autowired
|
||||
private AccountService accountService;
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Autowired
|
||||
private UsersBaseService usersBaseService;
|
||||
|
||||
@Autowired
|
||||
private UserCancelRecordService userCancelRecordService;
|
||||
|
||||
@Autowired
|
||||
private SysConfService sysConfService;
|
||||
@Autowired
|
||||
private SmsService smsService;
|
||||
@Autowired
|
||||
private EmailService emailService;
|
||||
|
||||
protected Gson gson = new Gson();
|
||||
|
||||
@@ -380,16 +377,54 @@ public class AccountManageService {
|
||||
throw new ServiceException(BusiStatus.PHONE_BIND_ERROR);
|
||||
}
|
||||
|
||||
uid = account.getUid();
|
||||
//检验验证码
|
||||
if (!accountService.verifySmsCodeByCache(phone, resetCode, uid)) {
|
||||
if (!smsService.verifySmsCodeByCache(phone, resetCode)) {
|
||||
throw new ServiceException(BusiStatus.INVALID_IDENTIFYING_CODE);
|
||||
}
|
||||
|
||||
accountService.resetAccountPwd(account.getUid(), password);
|
||||
//成功后删除验证码缓存
|
||||
accountService.delSmsCodeCache(phone, account.getUid());
|
||||
//accountService.delNickPasswordCache(account.getErbanNo());
|
||||
smsService.delSmsCodeCache(phone);
|
||||
|
||||
// 删除用户信息缓存
|
||||
jedisService.hdel(RedisKey.user.getKey(), account.getUid().toString());
|
||||
jedisService.hdel(RedisKey.user_summary.getKey(), account.getUid().toString());
|
||||
accountService.delNickPasswordCache(account.getErbanNo());
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置密码
|
||||
* 两个场景调用 => 客户端未登录 忘记密码, 此时uid 为 null 登录状态下忘记密码 uid有值
|
||||
* @param uid
|
||||
* @param email
|
||||
* @param password
|
||||
* @param code
|
||||
* @return 1:成功 2:重置码无效 3:用户不存在
|
||||
*/
|
||||
public void resetPasswordByEmailCode(Long uid, String email, String password, String code) {
|
||||
if (!CommonUtil.checkEmailFormat(email)){
|
||||
throw new ServiceException(BusiStatus.ACCOUNT_NOT_BIND_PHONE);
|
||||
}
|
||||
|
||||
long count = accountService.countByEmail(email);
|
||||
if (count > 1L) {
|
||||
throw new ServiceException(BusiStatus.PHONE_BIND_TOO_MANY_ACCOUNT);
|
||||
}
|
||||
|
||||
Account account = accountService.getAccountByEmail(email);
|
||||
if (null == account || !account.getUid().equals(uid)) {
|
||||
throw new ServiceException(BusiStatus.PHONE_BIND_ERROR);
|
||||
}
|
||||
|
||||
//检验验证码
|
||||
if (!emailService.verifyCodeByCache(email, code)) {
|
||||
throw new ServiceException(BusiStatus.INVALID_IDENTIFYING_CODE);
|
||||
}
|
||||
|
||||
accountService.resetAccountPwd(account.getUid(), password);
|
||||
//成功后删除验证码缓存
|
||||
emailService.delCodeCache(email);
|
||||
|
||||
// 删除用户信息缓存
|
||||
jedisService.hdel(RedisKey.user.getKey(), account.getUid().toString());
|
||||
jedisService.hdel(RedisKey.user_summary.getKey(), account.getUid().toString());
|
||||
|
@@ -42,7 +42,6 @@ public class PwdController extends BaseController {
|
||||
* 重置码
|
||||
* @return 1:成功 2:重置码无效 3:不存在该用户 4:其它错误
|
||||
*/
|
||||
//@Authorization
|
||||
@PostMapping("/reset")
|
||||
@SneakyThrows
|
||||
public BusiResult<Void> resetPassword(HttpServletRequest request,
|
||||
@@ -65,6 +64,37 @@ public class PwdController extends BaseController {
|
||||
return new BusiResult<>(BusiStatus.SUCCESS);
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置密码接口,用于用户忘记密码,找回密码服务
|
||||
*
|
||||
* @param newPwd
|
||||
* 新密码
|
||||
* @param email
|
||||
* 邮箱
|
||||
* @return 1:成功 2:重置码无效 3:不存在该用户 4:其它错误
|
||||
*/
|
||||
@PostMapping("/resetByEmail")
|
||||
@SneakyThrows
|
||||
public BusiResult<Void> resetPasswordByEmail(HttpServletRequest request,
|
||||
String email, String newPwd, String code) {
|
||||
if (StringUtils.isBlank(email) || StringUtils.isBlank(newPwd) || StringUtils.isBlank(code)){
|
||||
throw new ServiceException(BusiStatus.PARAMERROR);
|
||||
}
|
||||
|
||||
Long uid = getUid(request);
|
||||
email = decryptSensitiveInfo(request, email);
|
||||
newPwd = DESUtils.DESAndBase64Decrypt(newPwd, KeyStore.DES_ENCRYPT_KEY);
|
||||
|
||||
// 密码长度检查
|
||||
if(!newPwd.matches(PASSWORD_REGIX_V2)){
|
||||
return new BusiResult<>(BusiStatus.WEAK_PASSWORD);
|
||||
}
|
||||
|
||||
accountManageService.resetPasswordByEmailCode(uid, email, newPwd, code);
|
||||
|
||||
return new BusiResult<>(BusiStatus.SUCCESS);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置新密码
|
||||
* @param newPwd
|
||||
|
Reference in New Issue
Block a user