diff --git a/sql/ry_20180524.sql b/sql/ry_20180524.sql index 4b271687..642adb09 100644 --- a/sql/ry_20180524.sql +++ b/sql/ry_20180524.sql @@ -48,23 +48,22 @@ create table sys_user ( avatar varchar(100) default '' comment '头像路径', password varchar(100) default '' comment '密码', salt varchar(100) default '' comment '盐加密', - user_type char(1) default 'N' comment '类型:Y默认用户,N非默认用户', - status int(1) default 0 comment '帐号状态:0正常,1禁用', - refuse_des varchar(500) default '' comment '拒绝登录描述', + status int(1) default 0 comment '帐号状态(0正常 1禁用 2删除)', login_ip varchar(100) default '' comment '最后登陆IP', login_date datetime comment '最后登陆时间', create_by varchar(64) default '' comment '创建者', create_time datetime comment '创建时间', update_by varchar(64) default '' comment '更新者', update_time datetime comment '更新时间', + remark varchar(500) default '' comment '备注', primary key (user_id) ) engine=innodb auto_increment=100 default charset=utf8 comment = '用户信息表'; -- ---------------------------- -- 初始化-用户信息表数据 -- ---------------------------- -insert into sys_user values(1, 106, 'admin', '若依', 'ry@163.com', '15888888888', '1', '', '29c67a30398638269fe600f73a054934', '111111', 'Y', 0, '正常', '127.0.0.1', '2018-03-16 11-33-00', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00'); -insert into sys_user values(2, 108, 'ry', '若依', 'ry@qq.com', '15666666666', '1', '', '8e6d98b90472783cc73c17047ddccf36', '222222', 'N', 0, '正常', '127.0.0.1', '2018-03-16 11-33-00', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00'); +insert into sys_user values(1, 106, 'admin', '若依', 'ry@163.com', '15888888888', '1', '', '29c67a30398638269fe600f73a054934', '111111', 0, '127.0.0.1', '2018-03-16 11-33-00', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00', '管理员'); +insert into sys_user values(2, 108, 'ry', '若依', 'ry@qq.com', '15666666666', '1', '', '8e6d98b90472783cc73c17047ddccf36', '222222', 0, '127.0.0.1', '2018-03-16 11-33-00', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00', '测试员'); -- ---------------------------- -- 3、岗位信息表 diff --git a/src/main/java/com/ruoyi/framework/shiro/service/LoginService.java b/src/main/java/com/ruoyi/framework/shiro/service/LoginService.java index e5aba618..0997a9e7 100644 --- a/src/main/java/com/ruoyi/framework/shiro/service/LoginService.java +++ b/src/main/java/com/ruoyi/framework/shiro/service/LoginService.java @@ -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); diff --git a/src/main/java/com/ruoyi/project/system/user/controller/UserController.java b/src/main/java/com/ruoyi/project/system/user/controller/UserController.java index 756fefb7..639bcfb2 100644 --- a/src/main/java/com/ruoyi/project/system/user/controller/UserController.java +++ b/src/main/java/com/ruoyi/project/system/user/controller/UserController.java @@ -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; } - /** * 校验手机号码 */ diff --git a/src/main/java/com/ruoyi/project/system/user/domain/User.java b/src/main/java/com/ruoyi/project/system/user/domain/User.java index 902928a9..e0b98f8b 100644 --- a/src/main/java/com/ruoyi/project/system/user/domain/User.java +++ b/src/main/java/com/ruoyi/project/system/user/domain/User.java @@ -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) + "]"; } diff --git a/src/main/java/com/ruoyi/project/system/user/domain/UserStatus.java b/src/main/java/com/ruoyi/project/system/user/domain/UserStatus.java new file mode 100644 index 00000000..c833632e --- /dev/null +++ b/src/main/java/com/ruoyi/project/system/user/domain/UserStatus.java @@ -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; + } +} diff --git a/src/main/resources/mybatis/system/UserMapper.xml b/src/main/resources/mybatis/system/UserMapper.xml index b8ae00c1..86544601 100644 --- a/src/main/resources/mybatis/system/UserMapper.xml +++ b/src/main/resources/mybatis/system/UserMapper.xml @@ -15,15 +15,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - - + @@ -36,19 +35,18 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"