/// <summary> /// 验证登录信息 /// </summary> /// <param name="data"></param> /// <returns></returns> private async Task <Result> VerifyLogin(LoginIn data) { Result result = new Result(); if (data == null) { result.msg = "参数错误"; return(result); } if (string.IsNullOrWhiteSpace(data.user_name?.Trim())) { result.msg = "用户名不能为空"; return(result); } data.user_name = data.user_name?.Trim(); if (string.IsNullOrWhiteSpace(data.password?.Trim())) { result.msg = "密码不能为空"; return(result); } data.password = data.password?.Trim(); if (!VerifyCommon.UserName(data.user_name)) { result.msg = "用户名或密码错误"; return(result); } if (data.user_name.Length < 5 || data.user_name.Length > 12) { result.msg = "用户名或密码错误"; return(result); } if (!VerifyCommon.Password(data.password)) { result.msg = "用户名或密码错误"; return(result); } if (data.password.Length < 6 || data.password.Length > 18) { result.msg = "用户名或密码错误"; return(result); } DBHelper db = new DBHelper(); bool user_exist_flag = await UserDao.IsExist(db, data.user_name); db.Close(); if (!user_exist_flag) { result.msg = "用户名或密码错误"; return(result); } result.result = true; return(result); }
/// <summary> /// 验证添加用户数据 /// </summary> /// <param name="data"></param> /// <returns></returns> private async Task <Result> VerifyAddUser(AddUserIn data) { Result result = new Result(); if (data == null) { result.msg = "参数错误"; return(result); } if (string.IsNullOrWhiteSpace(data.name?.Trim())) { result.msg = "姓名不能为空"; return(result); } data.name = data.name?.Trim(); if (!VerifyCommon.Name(data.name)) { result.msg = "姓名只能为中文"; return(result); } if (data.name.Length < 2 || data.name.Length > 4) { result.msg = "姓名只能为2-4个字符"; return(result); } if (string.IsNullOrWhiteSpace(data.user_name?.Trim())) { result.msg = "用户名不能为空"; return(result); } data.user_name = data.user_name?.Trim(); if (!VerifyCommon.UserName(data.user_name)) { result.msg = "用户名只能由英文、数字、下划线组成"; return(result); } if (data.user_name.Length < 5 || data.user_name.Length > 12) { result.msg = "用户名只能为5-12个字符"; return(result); } if (string.IsNullOrWhiteSpace(data.password?.Trim())) { result.msg = "密码不能为空"; return(result); } data.password = data.password?.Trim(); if (!VerifyCommon.Password(data.password)) { result.msg = "密码只能由英文、数字、下划线组成"; return(result); } if (data.password.Length < 6 || data.password.Length > 18) { result.msg = "密码只能为6-18个字符"; return(result); } if (string.IsNullOrWhiteSpace(data.position_id?.Trim())) { result.msg = "请填写职位"; return(result); } if (!int.TryParse(data.position_id, out int position_id) || position_id <= 0) { result.msg = "职位信息错误"; return(result); } DBHelper db = new DBHelper(); bool position_exist_flag = await PositionDao.IsExist(db, position_id); db.Close(); if (!position_exist_flag) { result.msg = "职位不存在"; return(result); } result.result = true; return(result); }