From edc9a6674eb9b40e33a74c5f022d279712ed3b7c Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期一, 30 十二月 2024 17:01:13 +0800 Subject: [PATCH] 添加许可工具 --- se-modules/se-system/src/main/java/com/se/system/controller/SysProfileController.java | 68 +++++++++++++++++----------------- 1 files changed, 34 insertions(+), 34 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..8b07d1e 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; @@ -24,7 +27,7 @@ import com.se.system.api.domain.SysFile; import com.se.system.api.domain.SysUser; import com.se.system.api.model.LoginUser; -import com.se.system.service.ISysUserService; +import com.se.system.service.inte.ISysUserService; /** * 涓汉淇℃伅 涓氬姟澶勭悊 @@ -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,23 @@ */ @Log(title = "涓汉淇℃伅", businessType = BusinessType.UPDATE) @PutMapping("/updatePwd") - public AjaxResult updatePwd(String oldPassword, String newPassword) - { + public AjaxResult updatePwd(String oldPassword, String newPassword) throws Exception { + if (enableEncrypt) { + oldPassword = AesUtils.decrypt(oldPassword); + newPassword = AesUtils.decrypt(newPassword); + } + String username = SecurityUtils.getUsername(); SysUser user = userService.selectUserByUserName(username); 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 +122,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