From 81725702d908b2b1b5f9f85630725ce6518c9183 Mon Sep 17 00:00:00 2001 From: XinYi Song <2037158277@qq.com> Date: Mon, 6 Dec 2021 15:55:27 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E6=B7=BB=E5=8A=A0=E4=BA=86=E6=89=8B?= =?UTF-8?q?=E6=9C=BA=E5=8F=B7=E8=8E=B7=E5=8F=96=E9=AA=8C=E8=AF=81=E7=A0=81?= =?UTF-8?q?=E7=94=A8=E4=BA=8E=E7=94=A8=E6=88=B7=E5=BF=98=E8=AE=B0=E5=AF=86?= =?UTF-8?q?=E7=A0=81=E7=9A=84=E5=8A=9F=E8=83=BD=E6=A8=A1=E5=9D=97=202?= =?UTF-8?q?=E3=80=81=E6=B7=BB=E5=8A=A0=E4=BA=86=E7=94=A8=E6=88=B7=E5=BF=98?= =?UTF-8?q?=E8=AE=B0=E5=AF=86=E7=A0=81=E7=9A=84=E5=8A=9F=E8=83=BD=E6=A8=A1?= =?UTF-8?q?=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xkrs/common/config/WebSecurityConfig.java | 3 + .../xkrs/controller/SysUserController.java | 67 +++++++++++++++++++ src/main/resources/application.properties | 6 +- 3 files changed, 73 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/xkrs/common/config/WebSecurityConfig.java b/src/main/java/com/xkrs/common/config/WebSecurityConfig.java index 0cd052b..2c54efd 100644 --- a/src/main/java/com/xkrs/common/config/WebSecurityConfig.java +++ b/src/main/java/com/xkrs/common/config/WebSecurityConfig.java @@ -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() diff --git a/src/main/java/com/xkrs/controller/SysUserController.java b/src/main/java/com/xkrs/controller/SysUserController.java index b2a7e52..e1acbf5 100644 --- a/src/main/java/com/xkrs/controller/SysUserController.java +++ b/src/main/java/com/xkrs/controller/SysUserController.java @@ -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 diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index dc4dca0..dfb719f 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -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