public ResultModel ResetPassowrd(string account, string password) { ResultModel result = new ResultModel() { Status = false }; S_UserInfoViewModel u = S_UserInfoDal.GetUserByUserAccount(account); if (u != null) { var enPwd = Utility.Encrypt(password + u.UserSalt); result.Status = S_UserInfoDal.UpdatePassword(enPwd, u.UserId); } return(result); }
internal List <S_UserInfoViewModel> GetUsersByUserP() { List <S_UserInfoViewModel> resultList = new List <S_UserInfoViewModel>(); StringBuilder cmdText = new StringBuilder(); cmdText.Append("SELECT UserID,UserName FROM S_UserInfo WHERE UserClass like '%2%' "); DataSet data = db.Query(cmdText.ToString()); if (data != null && data.Tables[0].Rows.Count > 0) { DataRowCollection rows = data.Tables[0].Rows; foreach (DataRow row in rows) { S_UserInfoViewModel user = new S_UserInfoViewModel(); user.UserId = Convert.IsDBNull(row["UserId"]) ? "" : Convert.ToString(row["UserId"]); user.UserName = Convert.IsDBNull(row["UserName"]) ? "" : Convert.ToString(row["UserName"]); resultList.Add(user); } } return(resultList); }
public ResultModel ResetPwd(string newPassword, string oldPassword) { ResultModel resultValue = new ResultModel() { Status = false }; S_UserInfoViewModel u = S_UserInfoDal.GetUserByUserAccount(GetRoleMenuInfo(GetUserID()).UserAccount); string password = Utility.Encrypt(oldPassword + u.UserSalt); if (u.UserPwd == password) { password = Utility.Encrypt(newPassword + u.UserSalt); bool res = S_UserInfoDal.UpdatePassword(password, u.UserId); resultValue.Status = res; } else { resultValue.ReMsg = "旧密码错误!"; } return(resultValue); }
internal S_UserInfoViewModel GetUserByUserAccount(string userAccount) { S_UserInfoViewModel user = new S_UserInfoViewModel(); StringBuilder cmdText = new StringBuilder(); cmdText.AppendFormat("SELECT * FROM S_UserInfo WHERE UserAccount='{0}'", userAccount); DataSet data = db.Query(cmdText.ToString()); if (data != null && data.Tables[0].Rows.Count > 0) { DataRowCollection rows = data.Tables[0].Rows; foreach (DataRow row in rows) { user.UserId = Convert.IsDBNull(row["UserId"]) ? "" : Convert.ToString(row["UserId"]); user.UserName = Convert.IsDBNull(row["UserName"]) ? "" : Convert.ToString(row["UserName"]); user.UserAccount = Convert.IsDBNull(row["UserAccount"]) ? "" : Convert.ToString(row["UserAccount"]); user.UserPwd = Convert.IsDBNull(row["UserPwd"]) ? "" : Convert.ToString(row["UserPwd"]); user.UserEmail = Convert.IsDBNull(row["UserEmail"]) ? "" : Convert.ToString(row["UserEmail"]); user.SendEmailTime = Convert.IsDBNull(row["SendEmailTime"]) ? "1900-01-01" : Convert.ToString(row["SendEmailTime"]); user.UserSalt = Convert.IsDBNull(row["UserSalt"]) ? "" : Convert.ToString(row["UserSalt"]); user.UserNick = Convert.IsDBNull(row["UserNick"]) ? "" : Convert.ToString(row["UserNick"]); user.UserStatus = Convert.IsDBNull(row["UserStatus"]) ? "" : Convert.ToString(row["UserStatus"]); user.UserLogin = Convert.IsDBNull(row["UserLogin"]) ? 0 : Convert.ToInt32(row["UserLogin"]); user.RoleID = Convert.IsDBNull(row["RoleID"]) ? 0 : Convert.ToInt32(row["RoleID"]); user.UserImg = Convert.IsDBNull(row["UserImg"]) ? "" : Convert.ToString(row["UserImg"]); user.DepartmentID = Convert.IsDBNull(row["DepartmentID"]) ? 0 : Convert.ToInt32(row["DepartmentID"]); user.UserClass = Convert.IsDBNull(row["UserClass"]) ? "" : Convert.ToString(row["UserClass"]); user.UserGroupID = Convert.IsDBNull(row["UserGroupID"]) ? 0 : Convert.ToInt32(row["UserGroupID"]); } return(user); } else { return(null); } }
/// <summary> /// 获取用户列表信息 /// </summary> /// <param name="userName">用户名称</param> /// <param name="userClass">用户类型</param> /// <param name="roleID">角色id</param> /// <param name="userGroupId">用户组id</param> /// <param name="orderByField">排序字段</param> /// <param name="orderByDescending">排序方式</param> /// <param name="pageIndex">当前页</param> /// <param name="pageSize">每个显示个数</param> /// <param name="total">总条数</param> /// <returns></returns> public List <S_UserInfoViewModel> GetViewModelList(string userName, int userClass, int roleID, string userGroupId, string userStatus, string orderByField, string orderByDescending, int pageIndex, int pageSize, out int total) { var list = new List <S_UserInfoViewModel>(); StringBuilder strSql = new StringBuilder(); //StringBuilder strSql2 = new StringBuilder(); //strSql.Append("select * from ("); //strSql.Append("select row_number() over (ORDER BY " + orderByField + " " + orderByDescending + ") as nums ,* from ("); strSql.Append("select {func} from ("); strSql.Append("select case UserClass when '1' then'超级管理员' when '2' then '判图员' when '3' then '开包员' else '' end as roles1 ,(select RoleName from S_RoleInfo r where r.RoleID = u.RoleID) as roles2, UserClass, RoleID, u.UserID, UserName, UserPhone,UserEmail, u.CreateTime, UserStatus, UserLogin, UpdateTime, UserImg,d.DepartName, g.UserGroupName,u.UserGroupID,(select top 1 logintime from S_UserLoginInfo s1 where s1.userid=u.userid ORDER BY logintime desc) LoginTime from S_UserInfo u LEFT JOIN S_UserGroup g on u.usergroupId = g.UserGroupID LEFT JOIN S_DepartmentInfo d on u.departmentId = d.DepartID where u.UserID is not null "); if (!string.IsNullOrEmpty(userName)) { strSql.Append(" and u.UserName like '%" + userName + "%' "); } if (!string.IsNullOrEmpty(userGroupId)) { if (userGroupId == "-1") { strSql.Append(" and (u.UserGroupID <=0 or u.UserGroupID is null) "); } else if (userGroupId == "0") { } else { strSql.Append(" and u.UserGroupID = '" + userGroupId + "' "); } } if (!string.IsNullOrEmpty(userStatus)) { //禁用 if (userStatus == "2") { strSql.Append(" and u.UserStatus = 0 "); }//在线 else if (userStatus == "1") { strSql.Append(" and u.UserStatus = 1 and UserLogin=1"); }//离线 else if (userStatus == "0") { strSql.Append(" and (u.UserStatus = 1 and (userLogin=0 or userlogin is null) or u.UserStatus=0)"); } } if (userClass > 0) { strSql.Append(" and u.UserClass like '%" + userClass + "%' "); } else { if (roleID > 0) { strSql.Append(" and u.RoleID = " + roleID + " "); } } strSql.Append(" ) T "); var str01 = strSql.ToString().Replace("{func}", " count(1) "); var obj = db.GetSingle(str01); if (obj == null) { total = 0; } else { total = Convert.ToInt32(obj); } strSql.Insert(0, "select * from ( "); strSql.AppendFormat(" ) TT where nums between {0} and {1}", ((pageIndex - 1) * pageSize) + 1, pageIndex * pageSize); var str02 = strSql.ToString().Replace("{func}", " row_number() over (ORDER BY " + orderByField + " " + orderByDescending + ") as nums ,* "); DataSet ds = db.Query(str02); if (ds.Tables[0].Rows.Count > 0) { foreach (var item in ds.Tables[0].Rows) { S_UserInfoViewModel model = new S_UserInfoViewModel(); var row = (DataRow)item; if (row != null) { if (row["UserID"] != null && row["UserID"].ToString() != "") { model.UserId = row["UserID"].ToString(); } if (row["UserName"] != null) { model.UserName = row["UserName"].ToString(); } if (row["UserPhone"] != null) { model.UserPhone = row["UserPhone"].ToString(); } if (row["UserEmail"] != null) { model.UserEmail = row["UserEmail"].ToString(); } if (row["UserClass"] != null && !string.IsNullOrEmpty(row["UserClass"].ToString())) { var names = new StringBuilder(); var ucs = row["UserClass"].ToString().Split(','); foreach (var uc in ucs) { switch (uc) { case "1": names.Append("超级管理员"); names.Append(","); break; case "2": names.Append("判图员"); names.Append(","); break; case "3": names.Append("开包员"); names.Append(","); break; default: break; } } if (row["roles2"] != null && !string.IsNullOrEmpty(row["roles2"].ToString())) { names.Append(row["roles2"].ToString()); } model.RoleName = names.ToString().TrimEnd(','); } else { if (row["roles2"] != null && !string.IsNullOrEmpty(row["roles2"].ToString())) { model.RoleName = row["roles2"].ToString(); } } if (row["CreateTime"] != null && row["CreateTime"].ToString() != "") { model.CreateTime = DateTime.Parse(row["CreateTime"].ToString()); } if (row["UserStatus"] != null && row["UserStatus"].ToString() != "") { model.UserStatus = row["UserStatus"].ToString(); //if (row["UserStatus"].ToString() == "0" || string.IsNullOrEmpty(row["UserStatus"].ToString())) //{ // model.UserStatus = "禁用"; //} //else //{ // if (row["UserLogin"].ToString() == "0" || string.IsNullOrEmpty(row["UserLogin"].ToString())) // { // model.UserStatus = "离线"; // } // else // { // model.UserStatus = "在线"; // } //} } else { model.UserStatus = ""; } if (row["UserLogin"] != null && !string.IsNullOrEmpty(row["UserLogin"].ToString())) { var tmp = 0; int.TryParse(row["UserLogin"].ToString(), out tmp); model.UserLogin = tmp; } else { model.UserLogin = 0; } if (row["UpdateTime"] != null && row["UpdateTime"].ToString() != "") { model.UpdateTime = DateTime.Parse(row["UpdateTime"].ToString()); } if (row["UserImg"] != null) { model.UserIcon = row["UserImg"].ToString(); } //UserGroupID if (row["DepartName"] != null && row["DepartName"].ToString() != "") { model.DepartMent = row["DepartName"].ToString(); } if (row["UserGroupName"] != null && row["UserGroupName"].ToString() != "") { model.UserGroupName = row["UserGroupName"].ToString(); } else { model.UserGroupName = "未分组"; } if (row["UserGroupID"] != null && row["UserGroupID"].ToString() != "") { model.UserGroupID = Convert.ToInt32(row["UserGroupID"].ToString()); } if (row["LoginTime"] != null && row["LoginTime"].ToString() != "") { model.LoginTime = row["LoginTime"].ToString(); } else { model.LoginTime = "--"; } list.Add(model); } } } return(list); }
public ResultModel Login(string userName, string password, bool isRememberLogin) { ResultModel rm = new ResultModel() { Status = false }; try { S_UserInfoViewModel u = S_UserInfoDal.GetUserByUserAccount(userName); if (u == null) { rm.ReMsg = "1|此账号不存在,请重新输入!"; return(rm); } password = Utility.Encrypt(password + u.UserSalt); if (u.UserPwd != password) { rm.ReMsg = "2|密码不正确,请重新输入!"; return(rm); } if (u.UserStatus == "0") { rm.ReMsg = "1|此账户已禁用,请联系管理员!"; return(rm); } if (u.UserClass == "" && u.RoleID == 0) { rm.ReMsg = "1|此账户无权登陆,请联系管理员!"; return(rm); } if (u.UserClass.Contains("1")) { u.RoleID = -1; // -1 为超级管理员 } List <S_TreeInfoViewModel> treeList = new List <S_TreeInfoViewModel>(); treeList = treeInfoBiz.GetListByRoleId(u.RoleID); if (treeList.Count == 0) { rm.ReMsg = "1|此账户无权登陆,请重新输入!"; return(rm); } var tree = treeList.Where(i => i.ParentID != 0).OrderBy(i => i.TreeSort).FirstOrDefault(); rm.ReturnUrl = tree.TreeUrl + "?treeId=" + treeList.FirstOrDefault(i => i.TreeId == tree.ParentID).TreeId; SetUserID(u.UserId); SetRoleMenuInfo(new LoginUserViewModel { UserAccount = u.UserAccount, UserName = u.UserName, UserId = u.UserId, RoleName = u.RoleName, TreeInfo = treeList }); rm.Status = true; } catch (SqlException sqlException) { rm.ReMsg = sqlException.Message; Logger.Error(string.Format("[User]:Login:{0}", " Login Failed,userName:" + userName)); } catch (Exception ex) { rm.ReMsg = ex.Message; } return(rm); }