|
|
|
|
@ -2,7 +2,9 @@ package com.ruoyi.web.controller.system;
|
|
|
|
|
|
|
|
|
|
import cn.dev33.satoken.secure.BCrypt;
|
|
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import com.ruoyi.common.annotation.Log;
|
|
|
|
|
import com.ruoyi.common.annotation.RepeatSubmit;
|
|
|
|
|
import com.ruoyi.common.constant.UserConstants;
|
|
|
|
|
import com.ruoyi.common.core.controller.BaseController;
|
|
|
|
|
import com.ruoyi.common.core.domain.R;
|
|
|
|
|
@ -59,10 +61,10 @@ public class SysProfileController extends BaseController {
|
|
|
|
|
@PutMapping
|
|
|
|
|
public R<Void> updateProfile(@RequestBody SysUser user) {
|
|
|
|
|
if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) {
|
|
|
|
|
return R.fail("修改用户'" + user.getUserName() + "'失败,手机号码已存在");
|
|
|
|
|
return R.fail("手机已存在");
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user)) {
|
|
|
|
|
return R.fail("修改用户'" + user.getUserName() + "'失败,邮箱账号已存在");
|
|
|
|
|
return R.fail("邮箱已存在");
|
|
|
|
|
}
|
|
|
|
|
user.setUserId(getUserId());
|
|
|
|
|
user.setUserName(null);
|
|
|
|
|
@ -72,8 +74,32 @@ public class SysProfileController extends BaseController {
|
|
|
|
|
if (userService.updateUserProfile(user) > 0) {
|
|
|
|
|
return R.ok();
|
|
|
|
|
}
|
|
|
|
|
return R.fail("修改个人信息异常,请联系管理员");
|
|
|
|
|
return R.fail("修改个人异常");
|
|
|
|
|
}
|
|
|
|
|
@Log(title = "绑定用户名", businessType = BusinessType.UPDATE)
|
|
|
|
|
@RepeatSubmit
|
|
|
|
|
@PutMapping("bindUserName")
|
|
|
|
|
public R<Void> bindUserName(String userName) {
|
|
|
|
|
SysUser u = new SysUser();
|
|
|
|
|
u.setUserId(getUserId());
|
|
|
|
|
u.setUserName(userName);
|
|
|
|
|
String oldUsername = userService.selectUserById(u.getUserId()).getUserName();
|
|
|
|
|
if(!(StrUtil.isBlank(oldUsername) || oldUsername.startsWith("_"))) {
|
|
|
|
|
return R.fail("只能绑定一次");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(!userService.checkUserNameUnique(u)){
|
|
|
|
|
return R.fail("账户已存在");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (userService.updateUserProfile(u) > 0) {
|
|
|
|
|
return R.ok();
|
|
|
|
|
}
|
|
|
|
|
return R.fail("绑定帐号异常");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 重置密码
|
|
|
|
|
@ -87,17 +113,17 @@ public class SysProfileController extends BaseController {
|
|
|
|
|
SysUser user = userService.selectUserById(LoginHelper.getUserId());
|
|
|
|
|
String userName = user.getUserName();
|
|
|
|
|
String password = user.getPassword();
|
|
|
|
|
if (!BCrypt.checkpw(oldPassword, password)) {
|
|
|
|
|
return R.fail("修改密码失败,旧密码错误");
|
|
|
|
|
if (StrUtil.isNotBlank(password) && !BCrypt.checkpw(oldPassword, password)) {
|
|
|
|
|
return R.fail("旧密码错误");
|
|
|
|
|
}
|
|
|
|
|
if (BCrypt.checkpw(newPassword, password)) {
|
|
|
|
|
return R.fail("新密码不能与旧密码相同");
|
|
|
|
|
return R.fail("新旧密码相同");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (userService.resetUserPwd(userName, BCrypt.hashpw(newPassword)) > 0) {
|
|
|
|
|
return R.ok();
|
|
|
|
|
}
|
|
|
|
|
return R.fail("修改密码异常,请联系管理员");
|
|
|
|
|
return R.fail("修改密码异常");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|