update 修改个人中心重置密码redis key 问题
This commit is contained in:
@@ -139,7 +139,7 @@ public class TokenController {
|
||||
public R<?> resetPwd(@Valid @RequestBody ResetPwdBody resetPwdBody)
|
||||
{
|
||||
// 重置密码
|
||||
sysLoginService.resetPwd(resetPwdBody);
|
||||
sysLoginService.resetPwd(resetPwdBody,true);
|
||||
return R.success("账号"+ resetPwdBody.getEmail()+"密码重置成功");
|
||||
}
|
||||
|
||||
@@ -151,7 +151,7 @@ public class TokenController {
|
||||
resetPwdBody.setEmail(email);
|
||||
|
||||
// 修改密码
|
||||
sysLoginService.resetPwd(resetPwdBody);
|
||||
sysLoginService.resetPwd(resetPwdBody,false);
|
||||
return R.success("账号"+ resetPwdBody.getEmail()+"密码修改成功");
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,8 @@ public class ResetPwdBody {
|
||||
|
||||
private String resetPwdCode;
|
||||
|
||||
private String updatePwdCode;
|
||||
|
||||
/** 新密码 */
|
||||
private String password;
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ import com.m2pool.system.api.RemoteUserService;
|
||||
import com.m2pool.system.api.entity.SysLogininfor;
|
||||
import com.m2pool.system.api.entity.SysUser;
|
||||
import com.m2pool.system.api.model.LoginUser;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -41,6 +42,7 @@ import java.util.concurrent.TimeUnit;
|
||||
* @Date 2024/6/12 16:19
|
||||
* @Author dy
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class SysLoginService {
|
||||
|
||||
@@ -404,11 +406,11 @@ public class SysLoginService {
|
||||
|
||||
|
||||
/**
|
||||
* 重置密码
|
||||
*
|
||||
*/
|
||||
public void resetPwd(ResetPwdBody resetPwdBody)
|
||||
public void resetPwd(ResetPwdBody resetPwdBody,boolean isUpdate)
|
||||
{
|
||||
|
||||
log.info("验证码{},重置密码{},重置者邮箱{}",resetPwdBody.getResetPwdCode(),resetPwdBody.getPassword(),resetPwdBody.getEmail());
|
||||
String password = resetPwdBody.getPassword();
|
||||
try {
|
||||
password = RsaUtils.decryptByPrivateKey(resetPwdBody.getPassword());
|
||||
@@ -419,6 +421,7 @@ public class SysLoginService {
|
||||
|
||||
String email = resetPwdBody.getEmail();
|
||||
String resetPwdCode = resetPwdBody.getResetPwdCode();
|
||||
String updatePwdCode = resetPwdBody.getUpdatePwdCode();
|
||||
// 邮箱或密码为空 错误
|
||||
if (StringUtils.isAnyBlank(email, password))
|
||||
{
|
||||
@@ -466,8 +469,9 @@ public class SysLoginService {
|
||||
//
|
||||
//System.out.println(checkCodeResult);
|
||||
|
||||
if(redisService.hasKey(RedisTransKey.getResetPwdKey(email))){
|
||||
|
||||
log.info("重置密码{},修改验证码{},重置验证码{}",isUpdate,redisService.hasKey(RedisTransKey.getResetPwdKey(email)),redisService.hasKey(RedisTransKey.getUpdatePwdKey(email)));
|
||||
// 如果是true代表就是忘记密码 false 就是个人中心重置密码
|
||||
if(isUpdate && redisService.hasKey(RedisTransKey.getResetPwdKey(email))){
|
||||
Object o = redisService.getCacheObject(RedisTransKey.getResetPwdKey(email));//user:emailCode:username
|
||||
|
||||
EmailCodeEntity emailCodeEntity = JSON.parseObject(JSON.toJSONString(o), EmailCodeEntity.class);
|
||||
@@ -493,6 +497,32 @@ public class SysLoginService {
|
||||
}else {
|
||||
throw new ServiceException("请勿修改已输入的邮箱");
|
||||
}
|
||||
}else if(!isUpdate && redisService.hasKey(RedisTransKey.getUpdatePwdKey(email))){
|
||||
Object o = redisService.getCacheObject(RedisTransKey.getUpdatePwdKey(email));//user:emailCode:username
|
||||
|
||||
EmailCodeEntity emailCodeEntity = JSON.parseObject(JSON.toJSONString(o), EmailCodeEntity.class);
|
||||
if (email.equals(emailCodeEntity.getEmail())) {
|
||||
//邮箱必须和刚刚传的一致
|
||||
//验证验证码
|
||||
if(updatePwdCode.equals(emailCodeEntity.getEmailCode())){
|
||||
// 重置用户密码
|
||||
SysUser sysUser = new SysUser();
|
||||
sysUser.setEmail(email);
|
||||
sysUser.setPassword(SecurityUtils.encryptPassword(password));
|
||||
|
||||
R<?> resetPwdResult = remoteUserService.resetPwdByEmail(sysUser);
|
||||
|
||||
if (R.FAIL == resetPwdResult.getCode())
|
||||
{
|
||||
throw new ServiceException(resetPwdResult.getMsg());
|
||||
}
|
||||
//recordLogininfor(username, Constants.REGISTER, "注册成功");
|
||||
}else {
|
||||
throw new ServiceException("邮箱验证码错误");
|
||||
}
|
||||
}else {
|
||||
throw new ServiceException("请勿修改已输入的邮箱");
|
||||
}
|
||||
}else {
|
||||
////判断是邮箱不存在还是操作超时
|
||||
////通过邮箱获取用户
|
||||
@@ -503,7 +533,6 @@ public class SysLoginService {
|
||||
//}
|
||||
throw new ServiceException("验证码校验失败:操作超时,请重新操作");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user