用户逻辑删除&不允许删除修改管理员
This commit is contained in:
@ -16,6 +16,7 @@ import com.ruoyi.common.utils.ServletUtils;
|
||||
import com.ruoyi.common.utils.SystemLogUtils;
|
||||
import com.ruoyi.common.utils.security.ShiroUtils;
|
||||
import com.ruoyi.project.system.user.domain.User;
|
||||
import com.ruoyi.project.system.user.domain.UserStatus;
|
||||
import com.ruoyi.project.system.user.service.IUserService;
|
||||
|
||||
/**
|
||||
@ -78,7 +79,7 @@ public class LoginService
|
||||
user = userService.selectUserByEmail(username);
|
||||
}
|
||||
|
||||
if (user == null)
|
||||
if (user == null || UserStatus.DELETED.getCode() == user.getStatus())
|
||||
{
|
||||
SystemLogUtils.log(username, CommonConstant.LOGIN_FAIL, MessageUtils.message("user.not.exists"));
|
||||
throw new UserNotExistsException();
|
||||
@ -86,10 +87,10 @@ public class LoginService
|
||||
|
||||
passwordService.validate(user, password);
|
||||
|
||||
if (UserConstants.USER_BLOCKED == user.getStatus())
|
||||
if (UserStatus.DISABLE.getCode() == user.getStatus())
|
||||
{
|
||||
SystemLogUtils.log(username, CommonConstant.LOGIN_FAIL, MessageUtils.message("user.blocked", user.getRefuseDes()));
|
||||
throw new UserBlockedException(user.getRefuseDes());
|
||||
SystemLogUtils.log(username, CommonConstant.LOGIN_FAIL, MessageUtils.message("user.blocked", user.getRemark()));
|
||||
throw new UserBlockedException(user.getRemark());
|
||||
}
|
||||
SystemLogUtils.log(username, CommonConstant.LOGIN_SUCCESS, MessageUtils.message("user.login.success"));
|
||||
recordLoginInfo(user);
|
||||
|
@ -12,6 +12,8 @@ import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.framework.aspectj.lang.annotation.Log;
|
||||
import com.ruoyi.framework.web.controller.BaseController;
|
||||
import com.ruoyi.framework.web.domain.Message;
|
||||
@ -21,6 +23,7 @@ import com.ruoyi.project.system.post.service.IPostService;
|
||||
import com.ruoyi.project.system.role.domain.Role;
|
||||
import com.ruoyi.project.system.role.service.IRoleService;
|
||||
import com.ruoyi.project.system.user.domain.User;
|
||||
import com.ruoyi.project.system.user.domain.UserStatus;
|
||||
import com.ruoyi.project.system.user.service.IUserService;
|
||||
|
||||
/**
|
||||
@ -129,11 +132,12 @@ public class UserController extends BaseController
|
||||
{
|
||||
return Message.error("用户不存在");
|
||||
}
|
||||
if (userService.deleteUserById(userId) > 0)
|
||||
else if (User.isAdmin(userId))
|
||||
{
|
||||
return Message.success();
|
||||
return Message.error("不允许删除超级管理员用户");
|
||||
}
|
||||
return Message.error();
|
||||
user.setStatus(UserStatus.DELETED.getCode());
|
||||
return userService.updateUser(user) > 0 ? Message.success() : Message.error();
|
||||
}
|
||||
|
||||
@RequiresPermissions("system:user:batchRemove")
|
||||
@ -161,11 +165,11 @@ public class UserController extends BaseController
|
||||
@ResponseBody
|
||||
public Message save(User user)
|
||||
{
|
||||
if (userService.saveUser(user) > 0)
|
||||
if (StringUtils.isNotNull(user.getUserId()) && User.isAdmin(user.getUserId()))
|
||||
{
|
||||
return Message.success();
|
||||
return Message.error("不允许修改超级管理员用户");
|
||||
}
|
||||
return Message.error();
|
||||
return userService.saveUser(user) > 0 ? Message.success() : Message.error();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -183,7 +187,6 @@ public class UserController extends BaseController
|
||||
return uniqueFlag;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 校验手机号码
|
||||
*/
|
||||
|
@ -36,12 +36,8 @@ public class User extends BaseEntity
|
||||
private String password;
|
||||
/** 盐加密 */
|
||||
private String salt;
|
||||
/** 类型:Y默认用户,N非默认用户 */
|
||||
private String userType;
|
||||
/** 帐号状态:0正常,1禁用 */
|
||||
/** 帐号状态:0正常,1禁用,2删除 */
|
||||
private int status;
|
||||
/** 拒绝登录描述 */
|
||||
private String refuseDes;
|
||||
/** 最后登陆IP */
|
||||
private String loginIp;
|
||||
/** 最后登陆时间 */
|
||||
@ -63,6 +59,16 @@ public class User extends BaseEntity
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public boolean isAdmin()
|
||||
{
|
||||
return isAdmin(this.userId);
|
||||
}
|
||||
|
||||
public static boolean isAdmin(Long userId)
|
||||
{
|
||||
return userId != null && 1L == userId;
|
||||
}
|
||||
|
||||
public Long getDeptId()
|
||||
{
|
||||
return deptId;
|
||||
@ -174,16 +180,6 @@ public class User extends BaseEntity
|
||||
setSalt(hex);
|
||||
}
|
||||
|
||||
public String getUserType()
|
||||
{
|
||||
return userType;
|
||||
}
|
||||
|
||||
public void setUserType(String userType)
|
||||
{
|
||||
this.userType = userType;
|
||||
}
|
||||
|
||||
public int getStatus()
|
||||
{
|
||||
return status;
|
||||
@ -194,16 +190,6 @@ public class User extends BaseEntity
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getRefuseDes()
|
||||
{
|
||||
return refuseDes;
|
||||
}
|
||||
|
||||
public void setRefuseDes(String refuseDes)
|
||||
{
|
||||
this.refuseDes = refuseDes;
|
||||
}
|
||||
|
||||
public String getLoginIp()
|
||||
{
|
||||
return loginIp;
|
||||
@ -259,8 +245,8 @@ public class User extends BaseEntity
|
||||
{
|
||||
return "User [userId=" + userId + ", deptId=" + deptId + ", parentId=" + parentId + ", loginName=" + loginName
|
||||
+ ", userName=" + userName + ", email=" + email + ", phonenumber=" + phonenumber + ", sex=" + sex
|
||||
+ ", avatar=" + avatar + ", password=" + password + ", salt=" + salt + ", userType=" + userType
|
||||
+ ", status=" + status + ", refuseDes=" + refuseDes + ", dept=" + dept + ", roleIds="
|
||||
+ ", avatar=" + avatar + ", password=" + password + ", salt=" + salt + ", status=" + status
|
||||
+ ", loginIp=" + loginIp + ", loginDate=" + loginDate + ", dept=" + dept + ", roleIds="
|
||||
+ Arrays.toString(roleIds) + ", postIds=" + Arrays.toString(postIds) + "]";
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,31 @@
|
||||
package com.ruoyi.project.system.user.domain;
|
||||
|
||||
/**
|
||||
* 用户状态
|
||||
*
|
||||
* @author ruoyi
|
||||
*
|
||||
*/
|
||||
public enum UserStatus
|
||||
{
|
||||
OK(0, "正常"), DISABLE(1, "禁用"), DELETED(2, "删除");
|
||||
|
||||
private final int code;
|
||||
private final String info;
|
||||
|
||||
UserStatus(int code, String info)
|
||||
{
|
||||
this.code = code;
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public int getCode()
|
||||
{
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getInfo()
|
||||
{
|
||||
return info;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user