新增用户名校验
This commit is contained in:
parent
10761200dd
commit
877dd3a8a3
|
|
@ -33,8 +33,8 @@ drop table if exists sys_user;
|
|||
create table sys_user (
|
||||
user_id int(11) not null auto_increment comment '用户ID',
|
||||
dept_id int(20) default null comment '部门ID',
|
||||
login_name varchar(30) default '' comment '登录名',
|
||||
user_name varchar(30) default '' comment '用户名称',
|
||||
login_name varchar(30) default '' comment '登录账号',
|
||||
user_name varchar(30) default '' comment '用户昵称',
|
||||
email varchar(100) default '' comment '用户邮箱',
|
||||
phonenumber varchar(20) default '' comment '手机号码',
|
||||
password varchar(100) default '' comment '密码',
|
||||
|
|
@ -187,7 +187,7 @@ create table sys_oper_log (
|
|||
action varchar(100) default '' comment '功能请求',
|
||||
method varchar(100) default '' comment '方法名称',
|
||||
channel varchar(20) default '' comment '来源渠道',
|
||||
login_name varchar(50) default '' comment '登录名称',
|
||||
login_name varchar(50) default '' comment '登录账号',
|
||||
dept_name varchar(50) default '' comment '部门名称',
|
||||
oper_url varchar(255) default '' comment '请求URL',
|
||||
oper_ip varchar(30) default '' comment '主机地址',
|
||||
|
|
@ -242,7 +242,7 @@ insert into sys_code values('system-operlog-status', '1', '失败', '', '', '2')
|
|||
drop table if exists sys_logininfor;
|
||||
create table sys_logininfor (
|
||||
info_id int(11) not null auto_increment comment '访问ID',
|
||||
login_name varchar(50) default '' comment '登录名',
|
||||
login_name varchar(50) default '' comment '登录账号',
|
||||
ipaddr varchar(50) default '' comment '登录IP地址',
|
||||
browser varchar(50) default '' comment '浏览器类型',
|
||||
os varchar(50) default '' comment '操作系统',
|
||||
|
|
@ -260,7 +260,7 @@ insert into sys_logininfor values(1, 'admin', '127.0.0.1', 'Chrome 45', 'Windows
|
|||
drop table if exists sys_user_online;
|
||||
create table sys_user_online (
|
||||
sessionId varchar(50) default '' comment '用户会话id',
|
||||
login_name varchar(50) default '' comment '登录名称',
|
||||
login_name varchar(50) default '' comment '登录账号',
|
||||
dept_name varchar(50) default '' comment '部门名称',
|
||||
ipaddr varchar(50) default '' comment '登录IP地址',
|
||||
browser varchar(50) default '' comment '浏览器类型',
|
||||
|
|
|
|||
|
|
@ -20,15 +20,16 @@ public class UserConstants
|
|||
/** 角色封禁状态 */
|
||||
public static final String ROLE_BLOCKED = "1";
|
||||
|
||||
/** 名称是否唯一的返回结果码 */
|
||||
public final static String NAME_UNIQUE = "0";
|
||||
|
||||
/**
|
||||
* 用户名长度限制
|
||||
*/
|
||||
public static final int USERNAME_MIN_LENGTH = 2;
|
||||
public static final int USERNAME_MAX_LENGTH = 10;
|
||||
|
||||
/** 名称是否唯一的返回结果码 */
|
||||
public final static String NAME_UNIQUE = "0";
|
||||
public final static String NAME_NOT_UNIQUE = "1";
|
||||
|
||||
/**
|
||||
* 密码长度限制
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -128,6 +128,21 @@ public class UserController extends BaseController
|
|||
return JSON.error();
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验用户名
|
||||
*/
|
||||
@PostMapping("/checkNameUnique")
|
||||
@ResponseBody
|
||||
public String checkNameUnique(User user)
|
||||
{
|
||||
String uniqueFlag = "0";
|
||||
if (user != null)
|
||||
{
|
||||
uniqueFlag = userService.checkNameUnique(user.getLoginName());
|
||||
}
|
||||
return uniqueFlag;
|
||||
}
|
||||
|
||||
/**
|
||||
* 选择部门树
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -87,4 +87,12 @@ public interface IUserDao
|
|||
*/
|
||||
public int batchUserRole(List<UserRole> userRoleList);
|
||||
|
||||
/**
|
||||
* 校验用户名称是否唯一
|
||||
*
|
||||
* @param userName 用户名
|
||||
* @return 结果
|
||||
*/
|
||||
public int checkNameUnique(String loginName);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -128,4 +128,15 @@ public class UserDaoImpl extends DynamicObjectBaseDao implements IUserDao
|
|||
return this.batchSave("SystemUserRoleMapper.batchUserRole", userRoleList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验用户名称是否唯一
|
||||
*
|
||||
* @param userName 用户名
|
||||
* @return 结果
|
||||
*/
|
||||
public int checkNameUnique(String loginName)
|
||||
{
|
||||
return this.count("SystemUserMapper.checkNameUnique", loginName);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,4 +60,12 @@ public interface IUserService
|
|||
*/
|
||||
public int saveUser(User user);
|
||||
|
||||
/**
|
||||
* 校验用户名称是否唯一
|
||||
*
|
||||
* @param userName 用户名
|
||||
* @return 结果
|
||||
*/
|
||||
public String checkNameUnique(String loginName);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import java.util.List;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.ruoyi.common.constant.UserConstants;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.framework.web.page.PageUtilEntity;
|
||||
import com.ruoyi.framework.web.page.TableDataInfo;
|
||||
|
|
@ -129,4 +130,19 @@ public class UserServiceImpl implements IUserService
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验用户名称是否唯一
|
||||
*
|
||||
* @param userName 用户名
|
||||
* @return
|
||||
*/
|
||||
public String checkNameUnique(String loginName)
|
||||
{
|
||||
int count = userDao.checkNameUnique(loginName);
|
||||
if (count > 0)
|
||||
{
|
||||
return UserConstants.NAME_NOT_UNIQUE;
|
||||
}
|
||||
return UserConstants.NAME_UNIQUE;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,6 +48,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
where u.login_name = #{userName}
|
||||
</select>
|
||||
|
||||
<select id="checkNameUnique" parameterType="String" resultType="int">
|
||||
select count(*) from sys_user where login_name=#{loginName}
|
||||
</select>
|
||||
|
||||
<select id="selectUserById" parameterType="Long" resultMap="UserResult">
|
||||
select u.user_id, u.dept_id, u.login_name, u.user_name, u.email, u.phonenumber, u.password, u.salt, u.status, u.refuse_des, u.create_time,
|
||||
d.dept_id, d.parent_id, d.dept_name, d.order_num, d.status as dept_status
|
||||
|
|
|
|||
|
|
@ -2,20 +2,42 @@ $("#form-user-add").validate({
|
|||
rules:{
|
||||
loginName:{
|
||||
required:true,
|
||||
minlength: 5,
|
||||
remote: {
|
||||
url: "/system/user/checkNameUnique",
|
||||
type: "post",
|
||||
dataType: "text",
|
||||
data: {
|
||||
name : function() {
|
||||
return $.trim($("#loginName").val());
|
||||
}
|
||||
},
|
||||
dataFilter: function(data, type) {
|
||||
if (data == "0") return true;
|
||||
else return false;
|
||||
}
|
||||
}
|
||||
},
|
||||
userName:{
|
||||
required:true,
|
||||
},
|
||||
password:{
|
||||
required:true,
|
||||
minlength: 6
|
||||
},
|
||||
email:{
|
||||
required:true,
|
||||
email:true
|
||||
},
|
||||
phonenumber:{
|
||||
required:true,
|
||||
},
|
||||
},
|
||||
messages: {
|
||||
"loginName": {
|
||||
remote: "该用户已经存在"
|
||||
}
|
||||
},
|
||||
submitHandler:function(form){
|
||||
add();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue