添加了用户忘记密码的功能模块

This commit is contained in:
XinYi Song 2021-12-24 15:12:34 +08:00
parent 0f18736aa1
commit cc95d1016b
3 changed files with 47 additions and 0 deletions

View File

@ -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()

View File

@ -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);
}
}

View File

@ -163,4 +163,13 @@ public interface SysUserDao extends JpaRepository<SysUserEntity,Integer> {
@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);
}