app端忘记密码redis缓存key字段优化
This commit is contained in:
@ -2,5 +2,7 @@ package com.fuyuanshen.constants;
|
||||
|
||||
public class RedisConstants {
|
||||
|
||||
public static final String APP_SMS_TOKEN = "app_sms_forgotPassword:";
|
||||
public static final String APP_FORGOT_PASSWORD_SMS_TOKEN = "app_sms_forgotPassword:";
|
||||
|
||||
public static final String APP_REGISTER_SMS_TOKEN = "app_sms_register:";
|
||||
}
|
||||
|
@ -15,57 +15,28 @@
|
||||
*/
|
||||
package com.fuyuanshen.modules.system.rest.app;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.fuyuanshen.annotation.Log;
|
||||
import com.fuyuanshen.annotation.rest.AnonymousPostMapping;
|
||||
import com.fuyuanshen.exception.BadRequestException;
|
||||
import com.fuyuanshen.modules.security.service.UserCacheManager;
|
||||
import com.fuyuanshen.modules.security.service.dto.JwtUserDto;
|
||||
import com.fuyuanshen.modules.system.constant.UserConstants;
|
||||
import com.fuyuanshen.modules.system.domain.Dept;
|
||||
import com.fuyuanshen.modules.system.domain.Role;
|
||||
import com.fuyuanshen.modules.system.domain.User;
|
||||
import com.fuyuanshen.modules.system.domain.app.APPUser;
|
||||
import com.fuyuanshen.modules.system.domain.dto.UserPassVo;
|
||||
import com.fuyuanshen.modules.system.domain.dto.UserQueryCriteria;
|
||||
import com.fuyuanshen.modules.system.domain.dto.app.APPForgotPasswordDTO;
|
||||
import com.fuyuanshen.modules.system.domain.dto.app.APPUserDTO;
|
||||
import com.fuyuanshen.modules.system.domain.query.APPUserQuery;
|
||||
import com.fuyuanshen.modules.system.domain.vo.APPUserVo;
|
||||
import com.fuyuanshen.modules.system.domain.vo.ConsumerVo;
|
||||
import com.fuyuanshen.modules.system.enums.UserType;
|
||||
import com.fuyuanshen.modules.system.mapper.UserMapper;
|
||||
import com.fuyuanshen.modules.system.service.*;
|
||||
import com.fuyuanshen.modules.system.service.app.APPUserService;
|
||||
import com.fuyuanshen.modules.utils.ResponseVO;
|
||||
import com.fuyuanshen.utils.PageResult;
|
||||
import com.fuyuanshen.utils.SecurityUtils;
|
||||
import com.fuyuanshen.utils.StringUtils;
|
||||
import com.fuyuanshen.utils.enums.CodeEnum;
|
||||
import io.netty.util.internal.StringUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.poi.ss.formula.functions.T;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
@ -120,6 +91,15 @@ public class APPUserController {
|
||||
return ResponseVO.success("success!!!");
|
||||
}
|
||||
|
||||
@Log("发送用户注册验证码")
|
||||
@ApiOperation("发送用户注册验证码")
|
||||
@PostMapping(value = "/sendRegisterSms")
|
||||
@PreAuthorize("@el.check('appUser:edit')")
|
||||
public ResponseVO<String> sendRegisterSms(@Param("phoneNumber") String phoneNumber) throws Exception {
|
||||
appUserService.sendSms(phoneNumber);
|
||||
return ResponseVO.success("success!!!");
|
||||
}
|
||||
|
||||
@Log("修改APP用户")
|
||||
@ApiOperation("修改APP用户")
|
||||
@PutMapping
|
||||
@ -145,15 +125,18 @@ public class APPUserController {
|
||||
@PostMapping(value = "/forgotPassword")
|
||||
@PreAuthorize("@el.check('appUser:edit')")
|
||||
public ResponseVO<String> forgotPassword(@RequestBody APPForgotPasswordDTO appForgotPasswordDTO) throws Exception {
|
||||
if (!"0000".equals(appForgotPasswordDTO.getVerificationCode())) {
|
||||
throw new BadRequestException("验证码错误");
|
||||
}
|
||||
appUserService.forgotPassword(appForgotPasswordDTO);
|
||||
return ResponseVO.success("success!!!");
|
||||
}
|
||||
|
||||
@Log("发送验证码")
|
||||
@ApiOperation("发送验证码")
|
||||
@Log("发送忘记密码验证码")
|
||||
@ApiOperation("发送忘记密码验证码")
|
||||
@PostMapping(value = "/sendSms")
|
||||
@PreAuthorize("@el.check('appUser:edit')")
|
||||
public ResponseVO<String> sendSms(@Param("phoneNumber") String phoneNumber) throws Exception {
|
||||
public ResponseVO<String> sendForgotPasswordSms(@Param("phoneNumber") String phoneNumber) throws Exception {
|
||||
appUserService.sendSms(phoneNumber);
|
||||
return ResponseVO.success("success!!!");
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import static com.fuyuanshen.constants.RedisConstants.APP_SMS_TOKEN;
|
||||
import static com.fuyuanshen.constants.RedisConstants.*;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
@ -82,6 +82,14 @@ public class APPUserServiceImpl extends ServiceImpl<APPUserMapper, APPUser> impl
|
||||
if (appUserMapper.getByUsername(username) != null) {
|
||||
throw new BadRequestException("该手机号已被注册");
|
||||
}
|
||||
|
||||
Object verificationCode = redisUtils.get(APP_REGISTER_SMS_TOKEN + username);
|
||||
if (verificationCode == null) {
|
||||
throw new BadRequestException("验证码已过期");
|
||||
}
|
||||
if(!user.getVerificationCode().equals(verificationCode.toString())){
|
||||
throw new BadRequestException("验证码错误");
|
||||
}
|
||||
APPUser appUser = new APPUser();
|
||||
appUser.setUsername(user.getPhoneNumber());
|
||||
|
||||
@ -112,13 +120,13 @@ public class APPUserServiceImpl extends ServiceImpl<APPUserMapper, APPUser> impl
|
||||
if (appUser == null) {
|
||||
throw new BadRequestException("手机号不存在");
|
||||
}
|
||||
Object verificationCode = redisUtils.get(APP_SMS_TOKEN + phoneNumber);
|
||||
/*Object verificationCode = redisUtils.get(APP_FORGOT_PASSWORD_SMS_TOKEN + phoneNumber);
|
||||
if (verificationCode == null) {
|
||||
throw new BadRequestException("验证码已过期");
|
||||
}
|
||||
if(!appForgotPasswordDTO.getVerificationCode().equals(verificationCode.toString())){
|
||||
throw new BadRequestException("验证码错误");
|
||||
}
|
||||
}*/
|
||||
appUser.setPassword(appForgotPasswordDTO.getPassword());
|
||||
appUserMapper.updateById(appUser);
|
||||
}
|
||||
@ -130,7 +138,7 @@ public class APPUserServiceImpl extends ServiceImpl<APPUserMapper, APPUser> impl
|
||||
}
|
||||
// todo 发送验证码
|
||||
|
||||
redisUtils.set(APP_SMS_TOKEN + phoneNumber, RandomUtil.randomNumbers(4), 5 * 60);
|
||||
redisUtils.set(APP_FORGOT_PASSWORD_SMS_TOKEN + phoneNumber, RandomUtil.randomNumbers(4), 5 * 60);
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user