1、添加了手机号获取验证码用于用户忘记密码的功能模块

2、添加了用户忘记密码的功能模块
This commit is contained in:
XinYi Song 2021-12-06 15:55:27 +08:00
parent c77b05a87b
commit 81725702d9
3 changed files with 73 additions and 3 deletions

View File

@ -61,6 +61,9 @@ class WebSecurityConfig extends WebSecurityConfigurerAdapter {
.antMatchers(HttpMethod.POST,"/importCityExcel").permitAll()
.antMatchers(HttpMethod.POST,"/deleteShuiTi").permitAll()
.antMatchers(HttpMethod.GET,"/selectBeijing").permitAll()
.antMatchers(HttpMethod.GET,"/api/user/verificationCodeUpdate").permitAll()
.antMatchers(HttpMethod.GET,"/api/user/getVerificationCode").permitAll()
.antMatchers(HttpMethod.POST,"/api/user/userUnRememberPassword").permitAll()
// 所有其它请求需要身份认证
.anyRequest().authenticated()
.and()

View File

@ -15,6 +15,7 @@ import com.xkrs.service.SysUserService;
import com.xkrs.utils.RandomUtil;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
@ -29,6 +30,7 @@ import java.util.concurrent.TimeUnit;
import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulationErrorList;
import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulationObject;
import static com.xkrs.utils.AliYunSmsUtils.sendSms;
import static com.xkrs.utils.EncryptDecryptUtil.encry256;
/**
* 系统用户Controller
@ -238,6 +240,32 @@ public class SysUserController {
return sysUserService.adminUpdatePassword(userId,newPassword,confirmPassword);
}
/**
* 用户忘记密码
* @param map
* @param
* @return
*/
@Transactional(rollbackFor=Exception.class)
@PostMapping("/userUnRememberPassword")
public String userUnRememberPassword(@RequestBody Map map){
// 获取区域信息
Locale locale = LocaleContextHolder.getLocale();
String phone = (String) map.get("phone");
String newPassword = (String) map.get("newPassword");
String confirmPassword = (String) map.get("confirmPassword");
SysUserEntity sysUserEntity = sysUserDao.selectByUserName(phone);
if(sysUserEntity == null){
return outputEncapsulationObject(PromptMessageEnum.USER_LOGIN_ERROR,"您还没有注册登录,请先注册登录",locale);
}
if(!newPassword.equals(confirmPassword)){
return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL,"两次密码输入不一致",locale);
}
String newAfterPassword = encry256(newPassword + sysUserEntity.getSalt());
sysUserDao.updatePassword(sysUserEntity.getId(),newAfterPassword);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"密码修改成功",locale);
}
/**
* 发送手机号
* @param phone
@ -254,6 +282,45 @@ public class SysUserController {
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"",locale);
}
/**
* 填写手机号发送验证码用于用户忘记密码
* @param phone
* @return
* @throws ClientException
*/
@GetMapping("/verificationCodeUpdate")
public String verificationCodeUpdate(@RequestParam("phone") String phone) throws ClientException {
// 获取区域信息
Locale locale = LocaleContextHolder.getLocale();
SysUserVo sysUserVo = sysUserDao.selectUserByUserName(phone);
if(sysUserVo == null){
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"手机号错误,请使用您注册的手机号",locale);
}
String optCode = String.valueOf(RandomUtil.returnCode());
redisService.set(phone,optCode,10, TimeUnit.MINUTES);
SendSmsResponse response =sendSms(phone,optCode);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"",locale);
}
/**
* 输入验证码进行判断
* @param phone
* @param verificationCode
* @return
*/
@GetMapping("/getVerificationCode")
public String getVerificationCode(@RequestParam("phone") String phone, @RequestParam("verificationCode") String verificationCode){
Locale locale = LocaleContextHolder.getLocale();
String o = (String) redisService.get(phone);
if("".equals(o) || o == null){
return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG,"请先发送验证码!",locale);
}
if(!redisService.get(phone).equals(verificationCode)){
return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG,"验证码错误,请重新输入!",locale);
}
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"true",locale);
}
/**
* 更改账号过期时间
* @return

View File

@ -33,12 +33,12 @@ spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy
#spring.jpa.properties.hibernate.dialect = org.hibernate.spatial.dialect.postgis.PostgisDialect
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults = false
## Redis配置
## Redis配置 12
spring.cache.type = redis
spring.redis.database = 12
spring.redis.database = 8
spring.redis.host = localhost
spring.redis.port = 6379
spring.redis.password=sdust2020
#spring.redis.password=sdust2020
spring.redis.timeout = 10000
spring.redis.lettuce.pool.max-active = 100
spring.redis.lettuce.pool.max-wait = 10000