|
@@ -4,10 +4,7 @@ import cn.hutool.core.util.IdUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.zhentao.domain.UserLogin;
|
|
|
-import com.zhentao.dto.user.NoteDto;
|
|
|
-import com.zhentao.dto.user.UserLoginDto;
|
|
|
-import com.zhentao.dto.user.UserPassDto;
|
|
|
-import com.zhentao.dto.user.UserRegister;
|
|
|
+import com.zhentao.dto.user.*;
|
|
|
import com.zhentao.enums.ApiServerException;
|
|
|
import com.zhentao.exception.AsynException;
|
|
|
import com.zhentao.service.UserLoginService;
|
|
@@ -226,6 +223,41 @@ public class UserLoginServiceImpl extends ServiceImpl<UserLoginMapper, UserLogin
|
|
|
lock.unlock();
|
|
|
}
|
|
|
}
|
|
|
+//忘记密码
|
|
|
+ @Override
|
|
|
+ public Result ForgetPass(ForgetPassDto forgetPassDto) {
|
|
|
+ RLock lock = redissonClient.getLock(forgetPassDto.getPhone() + "Phone");
|
|
|
+ try {
|
|
|
+ boolean b = lock.tryLock(10, 20, TimeUnit.SECONDS);
|
|
|
+ if (b) {
|
|
|
+ QueryWrapper<UserLogin> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("user_mobile", forgetPassDto.getPhone());
|
|
|
+ UserLogin one = this.getOne(queryWrapper);
|
|
|
+ if (one == null) {
|
|
|
+ return Result.ERR("用户不存在", null);
|
|
|
+ }
|
|
|
+ // 获取Redis中的验证码
|
|
|
+ String s = stringRedisTemplate.opsForValue().get(forgetPassDto.getPhone());
|
|
|
+ // 验证码不匹配则抛出异常
|
|
|
+ if (!s.equals(forgetPassDto.getCode())) {
|
|
|
+ throw new AsynException(ApiServerException.NOTE_ERROR);
|
|
|
+ }
|
|
|
+ // 获取用户信息,根据手机号
|
|
|
+ String salt = one.getSalt();
|
|
|
+ String s1 = DigestUtils.md5DigestAsHex((salt + forgetPassDto.getPassword()).getBytes());
|
|
|
+ one.setUserPassword(s1);
|
|
|
+ boolean b1 = this.updateById(one);
|
|
|
+ if (b1){
|
|
|
+ return Result.OK("修改成功", null);
|
|
|
+ }else {
|
|
|
+ return Result.ERR("修改失败", null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
|
|
|
|
|
|
}
|