1、添加了手机号获取验证码用于用户忘记密码的功能模块
2、添加了用户忘记密码的功能模块
This commit is contained in:
parent
c77b05a87b
commit
81725702d9
@ -61,6 +61,9 @@ class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
|||||||
.antMatchers(HttpMethod.POST,"/importCityExcel").permitAll()
|
.antMatchers(HttpMethod.POST,"/importCityExcel").permitAll()
|
||||||
.antMatchers(HttpMethod.POST,"/deleteShuiTi").permitAll()
|
.antMatchers(HttpMethod.POST,"/deleteShuiTi").permitAll()
|
||||||
.antMatchers(HttpMethod.GET,"/selectBeijing").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()
|
.anyRequest().authenticated()
|
||||||
.and()
|
.and()
|
||||||
|
@ -15,6 +15,7 @@ import com.xkrs.service.SysUserService;
|
|||||||
import com.xkrs.utils.RandomUtil;
|
import com.xkrs.utils.RandomUtil;
|
||||||
import org.springframework.context.i18n.LocaleContextHolder;
|
import org.springframework.context.i18n.LocaleContextHolder;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.validation.BindingResult;
|
import org.springframework.validation.BindingResult;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
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.outputEncapsulationErrorList;
|
||||||
import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulationObject;
|
import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulationObject;
|
||||||
import static com.xkrs.utils.AliYunSmsUtils.sendSms;
|
import static com.xkrs.utils.AliYunSmsUtils.sendSms;
|
||||||
|
import static com.xkrs.utils.EncryptDecryptUtil.encry256;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 系统用户Controller
|
* 系统用户Controller
|
||||||
@ -238,6 +240,32 @@ public class SysUserController {
|
|||||||
return sysUserService.adminUpdatePassword(userId,newPassword,confirmPassword);
|
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
|
* @param phone
|
||||||
@ -254,6 +282,45 @@ public class SysUserController {
|
|||||||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"",locale);
|
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
|
* @return
|
||||||
|
@ -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.dialect = org.hibernate.spatial.dialect.postgis.PostgisDialect
|
||||||
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults = false
|
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults = false
|
||||||
|
|
||||||
## Redis配置
|
## Redis配置 12
|
||||||
spring.cache.type = redis
|
spring.cache.type = redis
|
||||||
spring.redis.database = 12
|
spring.redis.database = 8
|
||||||
spring.redis.host = localhost
|
spring.redis.host = localhost
|
||||||
spring.redis.port = 6379
|
spring.redis.port = 6379
|
||||||
spring.redis.password=sdust2020
|
#spring.redis.password=sdust2020
|
||||||
spring.redis.timeout = 10000
|
spring.redis.timeout = 10000
|
||||||
spring.redis.lettuce.pool.max-active = 100
|
spring.redis.lettuce.pool.max-active = 100
|
||||||
spring.redis.lettuce.pool.max-wait = 10000
|
spring.redis.lettuce.pool.max-wait = 10000
|
||||||
|
Loading…
Reference in New Issue
Block a user