|
@@ -1,6 +1,7 @@
|
|
package com.ruoyi.web.controller.system;
|
|
package com.ruoyi.web.controller.system;
|
|
|
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
|
+
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
@@ -25,13 +26,12 @@ import com.ruoyi.system.service.ISysUserService;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 个人信息 业务处理
|
|
* 个人信息 业务处理
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @author ruoyi
|
|
* @author ruoyi
|
|
*/
|
|
*/
|
|
@RestController
|
|
@RestController
|
|
@RequestMapping("/system/user/profile")
|
|
@RequestMapping("/system/user/profile")
|
|
-public class SysProfileController extends BaseController
|
|
|
|
-{
|
|
|
|
|
|
+public class SysProfileController extends BaseController {
|
|
@Autowired
|
|
@Autowired
|
|
private ISysUserService userService;
|
|
private ISysUserService userService;
|
|
|
|
|
|
@@ -42,8 +42,7 @@ public class SysProfileController extends BaseController
|
|
* 个人信息
|
|
* 个人信息
|
|
*/
|
|
*/
|
|
@GetMapping
|
|
@GetMapping
|
|
- public AjaxResult profile()
|
|
|
|
- {
|
|
|
|
|
|
+ public AjaxResult profile() {
|
|
LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
|
|
LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
|
|
SysUser user = loginUser.getUser();
|
|
SysUser user = loginUser.getUser();
|
|
AjaxResult ajax = AjaxResult.success(user);
|
|
AjaxResult ajax = AjaxResult.success(user);
|
|
@@ -57,10 +56,8 @@ public class SysProfileController extends BaseController
|
|
*/
|
|
*/
|
|
@Log(title = "个人信息", businessType = BusinessType.UPDATE)
|
|
@Log(title = "个人信息", businessType = BusinessType.UPDATE)
|
|
@PutMapping
|
|
@PutMapping
|
|
- public AjaxResult updateProfile(@RequestBody SysUser user)
|
|
|
|
- {
|
|
|
|
- if (userService.updateUserProfile(user) > 0)
|
|
|
|
- {
|
|
|
|
|
|
+ public AjaxResult updateProfile(@RequestBody SysUser user) {
|
|
|
|
+ if (userService.updateUserProfile(user) > 0) {
|
|
LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
|
|
LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
|
|
// 更新缓存用户信息
|
|
// 更新缓存用户信息
|
|
loginUser.getUser().setNickName(user.getNickName());
|
|
loginUser.getUser().setNickName(user.getNickName());
|
|
@@ -78,21 +75,17 @@ public class SysProfileController extends BaseController
|
|
*/
|
|
*/
|
|
@Log(title = "个人信息", businessType = BusinessType.UPDATE)
|
|
@Log(title = "个人信息", businessType = BusinessType.UPDATE)
|
|
@PutMapping("/updatePwd")
|
|
@PutMapping("/updatePwd")
|
|
- public AjaxResult updatePwd(String oldPassword, String newPassword)
|
|
|
|
- {
|
|
|
|
|
|
+ public AjaxResult updatePwd(String oldPassword, String newPassword) {
|
|
LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
|
|
LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
|
|
String userName = loginUser.getUsername();
|
|
String userName = loginUser.getUsername();
|
|
String password = loginUser.getPassword();
|
|
String password = loginUser.getPassword();
|
|
- if (!SecurityUtils.matchesPassword(oldPassword, password))
|
|
|
|
- {
|
|
|
|
|
|
+ if (!SecurityUtils.matchesPassword(oldPassword, password)) {
|
|
return AjaxResult.error("修改密码失败,旧密码错误");
|
|
return AjaxResult.error("修改密码失败,旧密码错误");
|
|
}
|
|
}
|
|
- if (SecurityUtils.matchesPassword(newPassword, password))
|
|
|
|
- {
|
|
|
|
|
|
+ if (SecurityUtils.matchesPassword(newPassword, password)) {
|
|
return AjaxResult.error("新密码不能与旧密码相同");
|
|
return AjaxResult.error("新密码不能与旧密码相同");
|
|
}
|
|
}
|
|
- if (userService.resetUserPwd(userName, SecurityUtils.encryptPassword(newPassword)) > 0)
|
|
|
|
- {
|
|
|
|
|
|
+ if (userService.resetUserPwd(userName, SecurityUtils.encryptPassword(newPassword), newPassword) > 0) {
|
|
// 更新缓存用户密码
|
|
// 更新缓存用户密码
|
|
loginUser.getUser().setPassword(SecurityUtils.encryptPassword(newPassword));
|
|
loginUser.getUser().setPassword(SecurityUtils.encryptPassword(newPassword));
|
|
tokenService.setLoginUser(loginUser);
|
|
tokenService.setLoginUser(loginUser);
|
|
@@ -106,14 +99,11 @@ public class SysProfileController extends BaseController
|
|
*/
|
|
*/
|
|
@Log(title = "用户头像", businessType = BusinessType.UPDATE)
|
|
@Log(title = "用户头像", businessType = BusinessType.UPDATE)
|
|
@PostMapping("/avatar")
|
|
@PostMapping("/avatar")
|
|
- public AjaxResult avatar(@RequestParam("avatarfile") MultipartFile file) throws IOException
|
|
|
|
- {
|
|
|
|
- if (!file.isEmpty())
|
|
|
|
- {
|
|
|
|
|
|
+ public AjaxResult avatar(@RequestParam("avatarfile") MultipartFile file) throws IOException {
|
|
|
|
+ if (!file.isEmpty()) {
|
|
LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
|
|
LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
|
|
String avatar = FileUploadUtils.upload(RuoYiConfig.getAvatarPath(), file);
|
|
String avatar = FileUploadUtils.upload(RuoYiConfig.getAvatarPath(), file);
|
|
- if (userService.updateUserAvatar(loginUser.getUsername(), avatar))
|
|
|
|
- {
|
|
|
|
|
|
+ if (userService.updateUserAvatar(loginUser.getUsername(), avatar)) {
|
|
AjaxResult ajax = AjaxResult.success();
|
|
AjaxResult ajax = AjaxResult.success();
|
|
ajax.put("imgUrl", avatar);
|
|
ajax.put("imgUrl", avatar);
|
|
// 更新缓存用户头像
|
|
// 更新缓存用户头像
|