From 3692386628cfdcbf497a5d8bbbc087a3ff75176a Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期五, 30 八月 2024 20:27:57 +0800 Subject: [PATCH] 重置密码 --- se-modules/se-system/src/main/java/com/se/system/controller/SysProfileController.java | 64 +++++++++++++++---------------- 1 files changed, 31 insertions(+), 33 deletions(-) diff --git a/se-modules/se-system/src/main/java/com/se/system/controller/SysProfileController.java b/se-modules/se-system/src/main/java/com/se/system/controller/SysProfileController.java index 2cfdc41..6201f36 100644 --- a/se-modules/se-system/src/main/java/com/se/system/controller/SysProfileController.java +++ b/se-modules/se-system/src/main/java/com/se/system/controller/SysProfileController.java @@ -1,7 +1,10 @@ package com.se.system.controller; import java.util.Arrays; + +import com.se.common.core.utils.AesUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; @@ -33,25 +36,30 @@ */ @RestController @RequestMapping("/user/profile") -public class SysProfileController extends BaseController -{ +public class SysProfileController extends BaseController { @Autowired private ISysUserService userService; - + @Autowired private TokenService tokenService; - + @Autowired private RemoteFileService remoteFileService; + + @Value("${enableEncrypt}") + boolean enableEncrypt; /** * 涓汉淇℃伅 */ @GetMapping - public AjaxResult profile() - { + public AjaxResult profile() { String username = SecurityUtils.getUsername(); SysUser user = userService.selectUserByUserName(username); + if (null != user) { + // 璁剧疆瀵嗙爜涓虹┖ + user.setPassword(null); + } AjaxResult ajax = AjaxResult.success(user); ajax.put("roleGroup", userService.selectUserRoleGroup(username)); ajax.put("postGroup", userService.selectUserPostGroup(username)); @@ -63,24 +71,20 @@ */ @Log(title = "涓汉淇℃伅", businessType = BusinessType.UPDATE) @PutMapping - public AjaxResult updateProfile(@RequestBody SysUser user) - { + public AjaxResult updateProfile(@RequestBody SysUser user) { LoginUser loginUser = SecurityUtils.getLoginUser(); SysUser currentUser = loginUser.getSysUser(); currentUser.setNickName(user.getNickName()); currentUser.setEmail(user.getEmail()); currentUser.setPhonenumber(user.getPhonenumber()); currentUser.setSex(user.getSex()); - if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(currentUser)) - { + if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(currentUser)) { return error("淇敼鐢ㄦ埛'" + loginUser.getUsername() + "'澶辫触锛屾墜鏈哄彿鐮佸凡瀛樺湪"); } - if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(currentUser)) - { + if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(currentUser)) { return error("淇敼鐢ㄦ埛'" + loginUser.getUsername() + "'澶辫触锛岄偖绠辫处鍙峰凡瀛樺湪"); } - if (userService.updateUserProfile(currentUser)) - { + if (userService.updateUserProfile(currentUser)) { // 鏇存柊缂撳瓨鐢ㄦ埛淇℃伅 tokenService.setLoginUser(loginUser); return success(); @@ -93,22 +97,21 @@ */ @Log(title = "涓汉淇℃伅", businessType = BusinessType.UPDATE) @PutMapping("/updatePwd") - public AjaxResult updatePwd(String oldPassword, String newPassword) - { + public AjaxResult updatePwd(String oldPassword, String newPassword) throws Exception { String username = SecurityUtils.getUsername(); SysUser user = userService.selectUserByUserName(username); + if (enableEncrypt && !StringUtils.isEmpty(user.getPassword())) { + user.setPassword(AesUtils.decrypt(user.getPassword())); + } String password = user.getPassword(); - if (!SecurityUtils.matchesPassword(oldPassword, password)) - { + if (!SecurityUtils.matchesPassword(oldPassword, password)) { return error("淇敼瀵嗙爜澶辫触锛屾棫瀵嗙爜閿欒"); } - if (SecurityUtils.matchesPassword(newPassword, password)) - { + if (SecurityUtils.matchesPassword(newPassword, password)) { return error("鏂板瘑鐮佷笉鑳戒笌鏃у瘑鐮佺浉鍚�"); } newPassword = SecurityUtils.encryptPassword(newPassword); - if (userService.resetUserPwd(username, newPassword) > 0) - { + if (userService.resetUserPwd(username, newPassword) > 0) { // 鏇存柊缂撳瓨鐢ㄦ埛瀵嗙爜 LoginUser loginUser = SecurityUtils.getLoginUser(); loginUser.getSysUser().setPassword(newPassword); @@ -117,30 +120,25 @@ } return error("淇敼瀵嗙爜寮傚父锛岃鑱旂郴绠$悊鍛�"); } - + /** * 澶村儚涓婁紶 */ @Log(title = "鐢ㄦ埛澶村儚", businessType = BusinessType.UPDATE) @PostMapping("/avatar") - public AjaxResult avatar(@RequestParam("avatarfile") MultipartFile file) - { - if (!file.isEmpty()) - { + public AjaxResult avatar(@RequestParam("avatarfile") MultipartFile file) { + if (!file.isEmpty()) { LoginUser loginUser = SecurityUtils.getLoginUser(); String extension = FileTypeUtils.getExtension(file); - if (!StringUtils.equalsAnyIgnoreCase(extension, MimeTypeUtils.IMAGE_EXTENSION)) - { + if (!StringUtils.equalsAnyIgnoreCase(extension, MimeTypeUtils.IMAGE_EXTENSION)) { return error("鏂囦欢鏍煎紡涓嶆纭紝璇蜂笂浼�" + Arrays.toString(MimeTypeUtils.IMAGE_EXTENSION) + "鏍煎紡"); } R<SysFile> fileResult = remoteFileService.upload(file); - if (StringUtils.isNull(fileResult) || StringUtils.isNull(fileResult.getData())) - { + if (StringUtils.isNull(fileResult) || StringUtils.isNull(fileResult.getData())) { return error("鏂囦欢鏈嶅姟寮傚父锛岃鑱旂郴绠$悊鍛�"); } String url = fileResult.getData().getUrl(); - if (userService.updateUserAvatar(loginUser.getUsername(), url)) - { + if (userService.updateUserAvatar(loginUser.getUsername(), url)) { AjaxResult ajax = AjaxResult.success(); ajax.put("imgUrl", url); // 鏇存柊缂撳瓨鐢ㄦ埛澶村儚 -- Gitblit v1.9.3