|
@@ -1,11 +1,8 @@
|
|
|
package com.jiayue.ssi.controller;
|
|
|
|
|
|
import cn.hutool.core.lang.Validator;
|
|
|
-import cn.hutool.core.text.PasswdStrength;
|
|
|
import cn.hutool.crypto.SmUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.jiayue.ssi.annotation.InterfaceLimit;
|
|
|
import com.jiayue.ssi.config.SendMailUtil;
|
|
@@ -19,13 +16,13 @@ import org.springframework.web.bind.annotation.*;
|
|
|
import java.util.Date;
|
|
|
|
|
|
/**
|
|
|
- * 用户信息controller
|
|
|
+ * 用户信息接口
|
|
|
*
|
|
|
* @author xsl
|
|
|
- * @version 3.0
|
|
|
+ * @since 2023/03/13
|
|
|
*/
|
|
|
@RestController
|
|
|
-@RequestMapping("/sysUserController" )
|
|
|
+@RequestMapping("/sysUserController")
|
|
|
@Slf4j
|
|
|
public class SysUserController {
|
|
|
@Autowired
|
|
@@ -40,19 +37,20 @@ public class SysUserController {
|
|
|
*/
|
|
|
@GetMapping(value = "/getAll")
|
|
|
@InterfaceLimit
|
|
|
- public ResponseVO getAll(Integer currentPage, Integer pageSize, String username,String phonenumber,String status) {
|
|
|
+ public ResponseVO getAll(Integer currentPage, Integer pageSize, String username, String phonenumber,
|
|
|
+ String status) {
|
|
|
try {
|
|
|
QueryWrapper<SysUser> wrapper = new QueryWrapper<>();
|
|
|
- if(StringUtils.isNotEmpty(username)){
|
|
|
- wrapper.eq("username",username);
|
|
|
+ if (StringUtils.isNotEmpty(username)) {
|
|
|
+ wrapper.eq("username", username);
|
|
|
}
|
|
|
- if(StringUtils.isNotEmpty(phonenumber)){
|
|
|
- wrapper.eq("phonenumber",phonenumber);
|
|
|
+ if (StringUtils.isNotEmpty(phonenumber)) {
|
|
|
+ wrapper.eq("phonenumber", phonenumber);
|
|
|
}
|
|
|
- if(StringUtils.isNotEmpty(status)){
|
|
|
- wrapper.eq("status",status);
|
|
|
+ if (StringUtils.isNotEmpty(status)) {
|
|
|
+ wrapper.eq("status", status);
|
|
|
}
|
|
|
- Page<SysUser> result = sysUserService.page(new Page<>(currentPage,pageSize),wrapper);
|
|
|
+ Page<SysUser> result = sysUserService.page(new Page<>(currentPage, pageSize), wrapper);
|
|
|
return ResponseVO.success(result);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
@@ -60,6 +58,7 @@ public class SysUserController {
|
|
|
return ResponseVO.error(null);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 获取当前用户信息
|
|
|
*
|
|
@@ -84,53 +83,47 @@ public class SysUserController {
|
|
|
@PostMapping
|
|
|
@InterfaceLimit
|
|
|
public ResponseVO add(@RequestBody SysUser user) {
|
|
|
- if (StringUtils.isEmpty(user.getUsername())){
|
|
|
+ if (StringUtils.isEmpty(user.getUsername())) {
|
|
|
return ResponseVO.fail("用户账号不能为空!");
|
|
|
- }
|
|
|
- else if (sysUserService.queryUserName(user.getUsername())!=null){
|
|
|
+ } else if (sysUserService.queryUserName(user.getUsername()) != null) {
|
|
|
return ResponseVO.fail(user.getUsername() + "账号已存在!");
|
|
|
- }
|
|
|
- else if (user.getUsername().length()<5 || user.getUsername().length()>20){
|
|
|
+ } else if (user.getUsername().length() < 5 || user.getUsername().length() > 20) {
|
|
|
return ResponseVO.fail(user.getUsername() + "用户账号长度必须介于5和20之间!");
|
|
|
}
|
|
|
|
|
|
if (StringUtils.isEmpty(user.getPhonenumber())) {
|
|
|
return ResponseVO.fail("手机号码不能为空!");
|
|
|
- }
|
|
|
- else if (!Validator.isMobile(user.getPhonenumber())){
|
|
|
+ } else if (!Validator.isMobile(user.getPhonenumber())) {
|
|
|
return ResponseVO.fail("请输入正确的手机号码!");
|
|
|
}
|
|
|
|
|
|
if (StringUtils.isEmpty(user.getNickname())) {
|
|
|
return ResponseVO.fail("姓名不能为空!");
|
|
|
- }
|
|
|
- else if (user.getNickname().length()>30){
|
|
|
+ } else if (user.getNickname().length() > 30) {
|
|
|
return ResponseVO.fail("姓名长度不能超过30个字符!");
|
|
|
}
|
|
|
|
|
|
- if (StringUtils.isEmpty(user.getMailbox())){
|
|
|
+ if (StringUtils.isEmpty(user.getMailbox())) {
|
|
|
return ResponseVO.fail("邮箱不能为空!");
|
|
|
- }
|
|
|
- else if (!Validator.isEmail(user.getMailbox())){
|
|
|
+ } else if (!Validator.isEmail(user.getMailbox())) {
|
|
|
return ResponseVO.fail("请输入正确的邮箱地址!");
|
|
|
- }
|
|
|
- else if (user.getMailbox().length()>50){
|
|
|
+ } else if (user.getMailbox().length() > 50) {
|
|
|
return ResponseVO.fail("邮箱长度不能超过50个字符!");
|
|
|
- }
|
|
|
- else if (sysUserService.queryMailBox(user.getMailbox())!=null){
|
|
|
+ } else if (sysUserService.queryMailBox(user.getMailbox()) != null) {
|
|
|
return ResponseVO.fail(user.getMailbox() + "邮箱已存在!");
|
|
|
}
|
|
|
|
|
|
// 生成8位初始密码
|
|
|
String randomPwd = RandomPwd.getRandomPwd(8);
|
|
|
user.setPassword(SmUtil.sm3(randomPwd).toUpperCase());
|
|
|
+ user.setErrNum(0);
|
|
|
+ user.setLockTime(0L);
|
|
|
|
|
|
try {
|
|
|
boolean bo = sysUserService.save(user);
|
|
|
- if (bo){
|
|
|
+ if (bo) {
|
|
|
return ResponseVO.success("添加用户信息成功");
|
|
|
- }
|
|
|
- else{
|
|
|
+ } else {
|
|
|
log.error("添加用户信息失败");
|
|
|
return ResponseVO.fail("添加用户信息失败");
|
|
|
}
|
|
@@ -150,57 +143,53 @@ public class SysUserController {
|
|
|
@PutMapping
|
|
|
public ResponseVO update(@RequestBody SysUser user) {
|
|
|
SysUser existUser = sysUserService.getById(user.getId());
|
|
|
- if (existUser==null){
|
|
|
+ if (existUser == null) {
|
|
|
return ResponseVO.fail("非法访问不能修改!");
|
|
|
}
|
|
|
|
|
|
- if (StringUtils.isEmpty(user.getUsername())){
|
|
|
+ if (StringUtils.isEmpty(user.getUsername())) {
|
|
|
return ResponseVO.fail("用户账号不能为空!");
|
|
|
- }
|
|
|
- else if (user.getUsername().length()<5 || user.getUsername().length()>20){
|
|
|
+ } else if (user.getUsername().length() < 5 || user.getUsername().length() > 20) {
|
|
|
return ResponseVO.fail(user.getUsername() + "用户账号长度必须介于5和20之间!");
|
|
|
- }
|
|
|
- else if (!existUser.getUsername().equals(user.getUsername())){
|
|
|
- if (sysUserService.queryUserName(user.getUsername())!=null){
|
|
|
+ } else if (!existUser.getUsername().equals(user.getUsername())) {
|
|
|
+ if (sysUserService.queryUserName(user.getUsername()) != null) {
|
|
|
return ResponseVO.fail(user.getUsername() + "账号已存在!");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (StringUtils.isEmpty(user.getMailbox())){
|
|
|
+ if (StringUtils.isEmpty(user.getMailbox())) {
|
|
|
return ResponseVO.fail("邮箱不能为空!");
|
|
|
- }
|
|
|
- else if (!Validator.isEmail(user.getMailbox())){
|
|
|
+ } else if (!Validator.isEmail(user.getMailbox())) {
|
|
|
return ResponseVO.fail("请输入正确的邮箱地址!");
|
|
|
- }
|
|
|
- else if (user.getMailbox().length()>50){
|
|
|
+ } else if (user.getMailbox().length() > 50) {
|
|
|
return ResponseVO.fail("邮箱长度不能超过50个字符!");
|
|
|
- }
|
|
|
- else if (!existUser.getMailbox().equals(user.getMailbox())){
|
|
|
- if (sysUserService.queryMailBox(user.getMailbox())!=null){
|
|
|
+ } else if (!existUser.getMailbox().equals(user.getMailbox())) {
|
|
|
+ if (sysUserService.queryMailBox(user.getMailbox()) != null) {
|
|
|
return ResponseVO.fail(user.getMailbox() + "邮箱已存在!");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (StringUtils.isEmpty(user.getPhonenumber())) {
|
|
|
return ResponseVO.fail("手机号码不能为空!");
|
|
|
- }
|
|
|
- else if (!Validator.isMobile(user.getPhonenumber())){
|
|
|
+ } else if (!Validator.isMobile(user.getPhonenumber())) {
|
|
|
return ResponseVO.fail("请输入正确的手机号码!");
|
|
|
}
|
|
|
|
|
|
if (StringUtils.isEmpty(user.getNickname())) {
|
|
|
return ResponseVO.fail("姓名不能为空!");
|
|
|
- }
|
|
|
- else if (user.getNickname().length()>30){
|
|
|
+ } else if (user.getNickname().length() > 30) {
|
|
|
return ResponseVO.fail("姓名长度不能超过30个字符!");
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
+ if ("0".equals(user.getStatus())) {
|
|
|
+ user.setErrNum(0);
|
|
|
+ user.setLockTime(0L);
|
|
|
+ }
|
|
|
boolean bo = sysUserService.updateUser(user);
|
|
|
- if (bo){
|
|
|
+ if (bo) {
|
|
|
return ResponseVO.success("修改用户信息成功");
|
|
|
- }
|
|
|
- else{
|
|
|
+ } else {
|
|
|
log.error("修改用户信息失败");
|
|
|
return ResponseVO.fail("修改用户信息失败");
|
|
|
}
|
|
@@ -217,22 +206,22 @@ public class SysUserController {
|
|
|
@PostMapping(value = "/resetPassword")
|
|
|
@InterfaceLimit
|
|
|
public ResponseVO resetPassword(String id) {
|
|
|
- if (StringUtils.isEmpty(id)){
|
|
|
+ if (StringUtils.isEmpty(id)) {
|
|
|
return ResponseVO.fail("重置密码缺失id!");
|
|
|
}
|
|
|
// id获取用户
|
|
|
SysUser sysUser = sysUserService.getById(id);
|
|
|
- if (sysUser == null){
|
|
|
+ if (sysUser == null) {
|
|
|
return ResponseVO.fail("重置密码失败!");
|
|
|
}
|
|
|
// 生成8位初始密码
|
|
|
String randomPwd = RandomPwd.getRandomPwd(8);
|
|
|
- boolean bo = sysUserService.resetPassword(Integer.parseInt(id),SmUtil.sm3(randomPwd).toUpperCase());
|
|
|
- if (!bo){
|
|
|
+ boolean bo = sysUserService.resetPassword(Integer.parseInt(id), SmUtil.sm3(randomPwd).toUpperCase());
|
|
|
+ if (!bo) {
|
|
|
return ResponseVO.fail("密码生成失败!");
|
|
|
}
|
|
|
try {
|
|
|
- sendMailUtil.executeSendMail(sysUser.getMailbox(),"系统登录密码","密码:" + randomPwd);
|
|
|
+ sendMailUtil.executeSendMail(sysUser.getMailbox(), "系统登录密码", "密码:" + randomPwd);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
return ResponseVO.fail("发送邮箱失败");
|
|
@@ -244,16 +233,16 @@ public class SysUserController {
|
|
|
* 删除用户信息
|
|
|
*/
|
|
|
@PostMapping(value = "/delUser")
|
|
|
+ @InterfaceLimit
|
|
|
public ResponseVO delete(String id) {
|
|
|
- if (StringUtils.isEmpty(id)){
|
|
|
+ if (StringUtils.isEmpty(id)) {
|
|
|
return ResponseVO.fail("id不能为空!");
|
|
|
}
|
|
|
try {
|
|
|
boolean bo = sysUserService.removeUserById(Integer.parseInt(id));
|
|
|
- if (bo){
|
|
|
+ if (bo) {
|
|
|
return ResponseVO.success("删除用户信息成功");
|
|
|
- }
|
|
|
- else{
|
|
|
+ } else {
|
|
|
log.error("删除用户信息失败");
|
|
|
return ResponseVO.fail("删除用户信息失败");
|
|
|
}
|
|
@@ -269,56 +258,50 @@ public class SysUserController {
|
|
|
*/
|
|
|
@PostMapping(value = "/updatePassword")
|
|
|
@InterfaceLimit
|
|
|
- public ResponseVO updatePassword(String id,String oldPassword,String newPassword,String confirmPassword) {
|
|
|
- if (StringUtils.isEmpty(id)){
|
|
|
+ public ResponseVO updatePassword(String id, String oldPassword, String newPassword, String confirmPassword) {
|
|
|
+ if (StringUtils.isEmpty(id)) {
|
|
|
return ResponseVO.fail("修改密码缺失id!");
|
|
|
}
|
|
|
// id获取用户
|
|
|
SysUser sysUser = sysUserService.getById(id);
|
|
|
- if (sysUser == null){
|
|
|
+ if (sysUser == null) {
|
|
|
return ResponseVO.fail("修改密码失败!");
|
|
|
}
|
|
|
|
|
|
- if (StringUtils.isEmpty(oldPassword)){
|
|
|
+ if (StringUtils.isEmpty(oldPassword)) {
|
|
|
return ResponseVO.fail("旧密码不能为空!");
|
|
|
- }
|
|
|
- else if (!sysUser.getPassword().equals(SmUtil.sm3(oldPassword).toUpperCase())){
|
|
|
+ } else if (!sysUser.getPassword().equals(SmUtil.sm3(oldPassword).toUpperCase())) {
|
|
|
return ResponseVO.fail("旧密码不正确!");
|
|
|
}
|
|
|
|
|
|
- if (StringUtils.isEmpty(newPassword)){
|
|
|
+ if (StringUtils.isEmpty(newPassword)) {
|
|
|
return ResponseVO.fail("新密码不能为空!");
|
|
|
- }
|
|
|
- else if (StringUtils.isEmpty(confirmPassword)){
|
|
|
+ } else if (StringUtils.isEmpty(confirmPassword)) {
|
|
|
return ResponseVO.fail("确认密码不能为空!");
|
|
|
- }
|
|
|
- else if (!newPassword.equals(confirmPassword)){
|
|
|
+ } else if (!newPassword.equals(confirmPassword)) {
|
|
|
return ResponseVO.fail("新密码两次输入的密码不一致!");
|
|
|
}
|
|
|
// 对新密码规则验证
|
|
|
- if (newPassword.contains(sysUser.getUsername())){
|
|
|
+ if (newPassword.contains(sysUser.getUsername())) {
|
|
|
return ResponseVO.fail("密码不能含有账号!");
|
|
|
}
|
|
|
- if (SmUtil.sm3(newPassword).toUpperCase().equals(sysUser.getPassword())){
|
|
|
+ if (SmUtil.sm3(newPassword).toUpperCase().equals(sysUser.getPassword())) {
|
|
|
return ResponseVO.fail("新密码不能与上次密码相同!");
|
|
|
}
|
|
|
- if (RegexUtil.sameReg(newPassword)){
|
|
|
+ if (RegexUtil.sameReg(newPassword)) {
|
|
|
return ResponseVO.fail("新密码不能含有连续4位相同的数字或字母!");
|
|
|
- }
|
|
|
- else if (RegexUtil.keyboardSlopeArr(newPassword)){
|
|
|
+ } else if (RegexUtil.keyboardSlopeArr(newPassword)) {
|
|
|
return ResponseVO.fail("新密码不能含有4位斜方向连续的字符!");
|
|
|
- }
|
|
|
- else if (RegexUtil.keyboardHorizontalReg(newPassword)){
|
|
|
+ } else if (RegexUtil.keyboardHorizontalReg(newPassword)) {
|
|
|
return ResponseVO.fail("新密码不能含有4位连续的字符!");
|
|
|
- }
|
|
|
- else if (!RegexUtil.checkPwd(newPassword)){
|
|
|
+ } else if (!RegexUtil.checkPwd(newPassword)) {
|
|
|
return ResponseVO.fail("新密码不满足8~20位大写字母、小写字母、数字、特殊字符三种以上的组合!");
|
|
|
}
|
|
|
|
|
|
sysUser.setPassword(SmUtil.sm3(newPassword).toUpperCase());
|
|
|
sysUser.setLastUpdatePwdTime(new Date());
|
|
|
boolean bo = sysUserService.updateById(sysUser);
|
|
|
- if (!bo){
|
|
|
+ if (!bo) {
|
|
|
return ResponseVO.fail("修改密码失败!");
|
|
|
}
|
|
|
return ResponseVO.success();
|