From cc95d1016bbb26b1d216c7d72b7be92f7fb5fd93 Mon Sep 17 00:00:00 2001 From: XinYi Song <2037158277@qq.com> Date: Fri, 24 Dec 2021 15:12:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E5=BF=98=E8=AE=B0=E5=AF=86=E7=A0=81=E7=9A=84=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xkrs/common/config/WebSecurityConfig.java | 1 + .../xkrs/controller/SysUserController.java | 37 +++++++++++++++++++ src/main/java/com/xkrs/dao/SysUserDao.java | 9 +++++ 3 files changed, 47 insertions(+) diff --git a/src/main/java/com/xkrs/common/config/WebSecurityConfig.java b/src/main/java/com/xkrs/common/config/WebSecurityConfig.java index fe1b900..85c8dfb 100644 --- a/src/main/java/com/xkrs/common/config/WebSecurityConfig.java +++ b/src/main/java/com/xkrs/common/config/WebSecurityConfig.java @@ -45,6 +45,7 @@ class WebSecurityConfig extends WebSecurityConfigurerAdapter { .antMatchers(HttpMethod.POST,"/api/user/loginByPhone").permitAll() .antMatchers(HttpMethod.POST,"/qiNiuUploadFile").permitAll() .antMatchers(HttpMethod.POST,"/merchantSettlement").permitAll() + .antMatchers(HttpMethod.POST,"/api/user/updateRememberPassword").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 2b86dff..af97cd6 100644 --- a/src/main/java/com/xkrs/controller/SysUserController.java +++ b/src/main/java/com/xkrs/controller/SysUserController.java @@ -16,6 +16,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.*; @@ -32,6 +33,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 @@ -346,4 +348,39 @@ public class SysUserController { return sysUserService.updatePassword(oldPassword,newPassword,confirmPassword,userName,sysUserEntity); } + + /** + * 用户忘记密码 + * @param map + * @return + */ + @Transactional(rollbackFor=Exception.class) + @PostMapping("/updateRememberPassword") + public String updateRememberPassword(@RequestBody Map map){ + // 获取区域信息 + Locale locale = LocaleContextHolder.getLocale(); + String phone = (String) map.get("phone"); + String verificationCode = (String) map.get("verificationCode"); + String newPassword = (String) map.get("newPassword"); + String confirmPassword = (String) map.get("confirmPassword"); + SysUserEntity byTelephone = sysUserDao.findByTelephone(phone); + if(byTelephone == null){ + return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"您未绑定该手机号!",locale); + } + if(!newPassword.equals(confirmPassword)){ + return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL,"两次密码输入不一致",locale); + } + String newAfterPassword = encry256(newPassword + byTelephone.getSalt()); + + String o = (String) redisUtil.get(phone); + if("".equals(o) || o == null){ + return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG,"请先发送验证码!",locale); + } + if(!redisUtil.get(phone).equals(verificationCode)){ + return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG,"验证码错误,请重新输入!",locale); + } + sysUserDao.updateRememberPassword(phone,newAfterPassword); + return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"密码修改成功",locale); + } + } diff --git a/src/main/java/com/xkrs/dao/SysUserDao.java b/src/main/java/com/xkrs/dao/SysUserDao.java index fb7cf90..a6ceea2 100644 --- a/src/main/java/com/xkrs/dao/SysUserDao.java +++ b/src/main/java/com/xkrs/dao/SysUserDao.java @@ -163,4 +163,13 @@ public interface SysUserDao extends JpaRepository { @Modifying(clearAutomatically=true) void updatePassword(Integer userId,String newPassword,String userName); + /** + * 用户忘记密码 + * @param phone + * @param password + */ + @Query(value = "update sys_user set password = ?2 where telephone = ?1",nativeQuery = true) + @Modifying(clearAutomatically=true) + void updateRememberPassword(String phone,String password); + }