public void GetUserInfo() { QJVRMS.Business.MemberShipManager msm = new QJVRMS.Business.MemberShipManager(); QJVRMS.Business.User user = msm.GetUser(CurrentUser.UserId); loginname.Text = user.UserLoginName; name.Text = user.UserName; tel.Text = user.Telphone; email.Text = user.Email; if (user.IsLocked) { state.Text = "无效"; } else { state.Text = "有效"; } userGroup.Text = user.GroupName; // Response.Write(CurrentUser.UserId.ToString()+" "+CurrentUser.UserGroupId.ToString() + " " + CurrentUser.GroupName); }
protected void btnAddUsers_Click(object sender, EventArgs e) { QJVRMS.Business.User user = null; ArrayList userList = new ArrayList(this.userList.Rows.Count); foreach (GridViewRow row in this.userList.Rows) { string userId = this.userList.DataKeys[row.RowIndex].Value.ToString(); string userName = row.Cells[0].Text; string loginId = row.Cells[1].Text; string email = row.Cells[2].Text; user = new QJVRMS.Business.User(); user.UserId = new Guid(userId); user.UserName = userName; user.UserLoginName = loginId; user.Email = email; userList.Add(user); } if (QJVRMS.Business.MemberShipManager.AddADUserToDB(userList, new Guid("AE636EC4-1B0F-4BFD-A571-1F4BB66C59F5"))) { ShowMessage("添加AD用户成功!"); } else { ShowMessage("添加AD用户失败!"); } }
///// <summary> ///// 绑定组 ///// </summary> //protected void BindGroupList() //{ // labGroupOwn.Visible = true; // groupDDL.Visible = true; // using (DataTable dt = Group.GetGroupList()) // { // this.groupDDL.DataSource = dt; // this.groupDDL.DataTextField = "GroupName"; // this.groupDDL.DataValueField = "GroupID"; // this.groupDDL.DataBind(); // } //} /// <summary> /// 绑定组中的用户组 /// </summary> protected void BindRoleList() { RoleCollection rc = Role.GetRoleCollection(CurrentGroupId); QJVRMS.Business.User user = new QJVRMS.Business.User(new Guid(this.hiUserId.Value)); RoleCollection rcUser = user.Roles; DataTable dt = new DataTable(); dt.Columns.Add("roleId", typeof(Guid)); dt.Columns.Add("roleName", typeof(string)); dt.Columns.Add("chked", typeof(bool)); foreach (Role role in rc) { DataRow newRow = dt.NewRow(); bool chk = false; if (rcUser[role.RoleId] != null) { chk = true; } newRow["roleId"] = role.RoleId; newRow["roleName"] = role.RoleName; newRow["chked"] = chk; dt.Rows.Add(newRow); } this.roleList.DataSource = dt; this.roleList.DataBind(); }
public Guid CreateUser(string password, string loginName, string userName, Guid groupId, string email, string tel, bool islocked, string isdownload, bool isIPValidate) { QJVRMS.Business.User user = null; Guid userId; DateTime nowTime = DateTime.Now; SqlParameter[] Parameters = new SqlParameter[12]; Parameters[0] = new SqlParameter("@loginName", SqlDbType.NVarChar); Parameters[1] = new SqlParameter("@userName", SqlDbType.NVarChar); Parameters[2] = new SqlParameter("@groupId", SqlDbType.UniqueIdentifier); Parameters[3] = new SqlParameter("@password", SqlDbType.VarChar); Parameters[4] = new SqlParameter("@tel", SqlDbType.VarChar); Parameters[5] = new SqlParameter("@email", SqlDbType.VarChar); Parameters[6] = new SqlParameter("@createDate", SqlDbType.DateTime); Parameters[7] = new SqlParameter("@islocked", SqlDbType.Bit); Parameters[8] = new SqlParameter("@isdownload", SqlDbType.Bit); Parameters[9] = new SqlParameter("@isIPValidate", SqlDbType.Bit); Parameters[10] = new SqlParameter("@NewUserId", SqlDbType.UniqueIdentifier); Parameters[11] = new SqlParameter("@ReturnValue", SqlDbType.Int); Parameters[0].Value = loginName; Parameters[1].Value = userName; Parameters[2].Value = groupId; Parameters[3].Value = Encryption.Encrypt(password); Parameters[4].Value = tel; Parameters[5].Value = email; Parameters[6].Value = nowTime; Parameters[7].Value = islocked; Parameters[8].Value = isdownload; Parameters[9].Value = isIPValidate; Parameters[10].Direction = ParameterDirection.Output; Parameters[11].Direction = ParameterDirection.ReturnValue; try { SqlHelper.ExecuteNonQuery(CommonInfo.ConQJVRMS, CommandType.StoredProcedure, "Users_createUser", Parameters); userId = new Guid(Parameters[10].Value.ToString()); if ((Parameters[11].Value != null ? (int)Parameters[11].Value : -1) == 0) { // user = new User(loginName, userName, userId, groupId, false, email, tel, nowTime, isdownload, isIPValidate); return(userId); } return(Guid.Empty); } catch (Exception ex) { LogWriter.WriteExceptionLog(ex); return(Guid.Empty); } }
public string GetUserById(Guid userId) { //string sql = "select * from Users where loginName=@loginName and IsLocked=0"; SqlParameter[] Parameters = new SqlParameter[1]; Parameters[0] = new SqlParameter("@userId", SqlDbType.UniqueIdentifier); Parameters[0].Value = userId; QJVRMS.Business.User user = null; Guid groupId; bool isLocked; bool isIPValidate; string loginName, UserName, Email, Telphone, isdownload, groupName; DateTime createDate; using (IDataReader reader = SqlHelper.ExecuteReader(CommonInfo.ConQJVRMS, CommandType.StoredProcedure, "dbo.Users_GetUserByUserId", Parameters)) { if (!reader.Read()) { throw new Exception("用户ID不存在!"); } groupId = new Guid(reader["groupId"].ToString()); isLocked = bool.Parse(reader["IsLocked"].ToString()); isIPValidate = bool.Parse(reader["IsIPValidate"].ToString()); isdownload = reader["IsDownLoad"].ToString(); loginName = reader["logInName"].ToString(); UserName = reader["Username"].ToString(); groupName = reader["groupName"].ToString(); Email = reader["email"].ToString(); Telphone = reader["Tel"].ToString(); createDate = DateTime.Parse(reader["CreateDate"].ToString()); } user = new User(loginName, UserName, userId, groupId, isLocked, Email, Telphone, createDate, isdownload, isIPValidate); user.GroupName = groupName; SerializeObjectFactory sof = new SerializeObjectFactory(); return(sof.SerializeToBase64(user)); }
public string GetUserByLoginName(string loginName) { string sql = " select u.*,g.GroupName from Users u,[Group] g where u.loginName=@loginName and u.groupId=g.groupId"; SqlParameter[] Parameters = new SqlParameter[1]; Parameters[0] = new SqlParameter("@loginName", SqlDbType.NVarChar); Parameters[0].Value = loginName; QJVRMS.Business.User user = null; Guid groupId, UserId; bool isLocked, isIPValidate; string UserName, Email, Telphone, isdownload, groupName; DateTime createDate; using (IDataReader reader = SqlHelper.ExecuteReader(CommonInfo.ConQJVRMS, CommandType.Text, sql, Parameters)) { if (!reader.Read()) { throw new Exception("用户登录ID不存在!"); } groupId = new Guid(reader["groupId"].ToString()); isLocked = bool.Parse(reader["IsLocked"].ToString()); isIPValidate = bool.Parse(reader["IsIPValidate"].ToString()); isdownload = reader["IsDownLoad"].ToString(); UserId = new Guid(reader["UserId"].ToString()); UserName = reader["Username"].ToString(); groupName = reader["groupName"].ToString(); Email = reader["email"].ToString(); Telphone = reader["Tel"].ToString(); createDate = DateTime.Parse(reader["CreateDate"].ToString()); } user = new User(loginName, UserName, UserId, groupId, isLocked, Email, Telphone, createDate, isdownload, isIPValidate); user.GroupName = groupName; SerializeObjectFactory sof = new SerializeObjectFactory(); return(sof.SerializeToBase64(user)); }
public bool AddADUsersToDB(string userListStr, Guid groupid) { DataTable userTable = new DataTable(); userTable.Columns.Add("UserId", typeof(Guid)); userTable.Columns.Add("GroupId", typeof(Guid)); userTable.Columns.Add("loginName", typeof(string)); userTable.Columns.Add("UserName", typeof(string)); userTable.Columns.Add("Tel", typeof(string)); userTable.Columns.Add("Email", typeof(string)); userTable.Columns.Add("uType", typeof(string)); userTable.Columns.Add("password", typeof(string)); userTable.Columns.Add("isLocked", typeof(string)); userTable.Columns.Add("isDownload", typeof(string)); userTable.Columns.Add("isIpValidate", typeof(string)); userTable.Columns.Add("IpAddress", typeof(string)); userTable.Columns.Add("CreateDate", typeof(DateTime)); SerializeObjectFactory sof = new SerializeObjectFactory(); ArrayList userList = (ArrayList)sof.DesializeFromBase64(userListStr); foreach (object ouser in userList) { QJVRMS.Business.User user = ouser as QJVRMS.Business.User; DataRow userRow = userTable.NewRow(); userRow["UserId"] = user.UserId; userRow["GroupId"] = groupid; userRow["loginName"] = user.UserLoginName; userRow["UserName"] = user.UserName; userRow["Tel"] = user.Telphone; userRow["Email"] = user.Email; userRow["uType"] = "1"; userRow["password"] = "******"; userTable.Rows.Add(userRow); } SqlConnection con = null; SqlTransaction trans = null; try { con = new SqlConnection(CommonInfo.ConQJVRMS); con.Open(); trans = con.BeginTransaction(); SqlHelperExtend.Update("Users", userTable, trans); trans.Commit(); return(true); } catch (Exception ex) { trans.Rollback(); LogWriter.WriteExceptionLog(ex); return(false); } finally { if (con != null) { con.Close(); } } }
/// <summary> /// 输出值 0 用户名密码为空 1 成功 2 密码错误 /// </summary> /// <param name="context"></param> public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/html"; HttpRequest Request = context.Request; HttpResponse Response = context.Response; Response.CacheControl = "no-cache"; Response.AddHeader("Pragma", "no-cache"); Response.Expires = -1441; string _userName = Request["userName"]; string _password = Request["password"]; string _ret = "0"; if (string.IsNullOrEmpty(_userName) || string.IsNullOrEmpty(_password)) { Response.Write(_ret); return; } #region 登陆使用方法 MemberShipManager msm = new MemberShipManager(); object temp = null; bool isValidate = false; //Form 验证 if (!CommonInfo.AuthByAD) { isValidate = msm.AuthUserByForm(_userName, _password, Request.UserHostAddress, ref temp); }//AD 验证 else { isValidate = msm.AuthUserByAD(CommonInfo.DomainName, CommonInfo.DomainNamePrefix + @"\" + _userName, _userName, _password, ref temp); } if (isValidate) { //转换为业务对象 QJVRMS.Business.User user = temp as QJVRMS.Business.User; //AD验证 获取用户在系统中的特有信息 if (CommonInfo.AuthByAD) { User userInfo = msm.GetUser(_userName); user.GroupName = userInfo.GroupName; user.IsDownLoad = userInfo.IsDownLoad; user.UserId = userInfo.UserId;//用户表中的ID替换AD中的ID。 user.GroupId = userInfo.GroupId; } //用户Session信息 string userData = string.Empty; userData = user.UserId + "," + user.GroupId + "," + _userName + "," + user.UserName + "," + user.GroupName + "," + user.IsDownLoad; FormsAuthenticationTicket Ticket = new FormsAuthenticationTicket(1, _userName, DateTime.Now, DateTime.Now.AddMinutes(WebUI.UIBiz.CommonInfo.CookieTimeout), false, userData, "/"); //建立身份验证票对象 string HashTicket = FormsAuthentication.Encrypt(Ticket); //加密序列化验证票为字符串 HttpCookie UserCookie = new HttpCookie(FormsAuthentication.FormsCookieName, HashTicket); UserCookie.Expires = DateTime.Now.AddMonths(1); //生成Cookie Response.Cookies.Add(UserCookie); //输出Cookie //Response.Redirect(FormsAuthentication.DefaultUrl); //这里为该用户创立一个默认的收藏夹,用户必须要有一个收藏夹,即使都删除了,下次登录还是会有一个 Resource r = new Resource(); r.CreateDefaultLightbox(user.UserId); _ret = "1"; LogEntity model = new LogEntity(); model.id = Guid.NewGuid(); model.userId = user.UserId; model.userName = _userName; model.EventType = ((int)LogType.Login).ToString(); model.EventResult = "成功"; model.EventContent = ""; model.IP = HttpContext.Current.Request.UserHostAddress; model.AddDate = DateTime.Now; new Logs().Add(model); } else { _ret = "2"; //用户名密码不正确,或者没有权限 LogEntity model = new LogEntity(); model.id = Guid.NewGuid(); model.userId = new Guid(); model.userName = _userName; model.EventType = ((int)LogType.Login).ToString(); model.EventResult = "失败"; model.EventContent = "错误的密码:" + _password; model.IP = HttpContext.Current.Request.UserHostAddress; model.AddDate = DateTime.Now; new Logs().Add(model); } #endregion //Response.Write(_ret+":"+context.Session.SessionID); Response.Write(_ret); Response.End(); }
public void Add(User item) { base.InnerList.Add(item); }
protected void btnSetUserFun_Click(object sender, EventArgs e) { List<ObjectRule> rules = new List<ObjectRule>(100); User user = null; SecurityObject secObj = null; Guid objId = new Guid(this.hiCurrentCataId.Value); secObj = new SecurityObject(objId, SecurityObjectType.Items); ArrayList opers = new ArrayList(100); foreach (GridViewRow row in userList.Rows) { Guid userId = new Guid(userList.DataKeys[row.RowIndex].Value.ToString()); user = new User(userId); opers.Add(user); ObjectRule newRule; CheckBox chk = row.FindControl("funUpChk") as CheckBox; newRule = new ObjectRule(secObj, user, OperatorMethod.Write); rules.Add(newRule); if (chk.Checked) { newRule.IsValidate = true; } else { newRule.IsValidate = false; } CheckBox echk = row.FindControl("funEditChk") as CheckBox; newRule = new ObjectRule(secObj, user, OperatorMethod.Modify); rules.Add(newRule); if (echk.Checked) { newRule.IsValidate = true; } else { newRule.IsValidate = false; } CheckBox dchk = row.FindControl("funReadChk") as CheckBox; newRule = new ObjectRule(secObj, user, OperatorMethod.Deny); rules.Add(newRule); if (dchk.Checked) { newRule.IsValidate = true; } else { newRule.IsValidate = false; } CheckBox downChk = row.FindControl("funDownChk") as CheckBox; newRule = new ObjectRule(secObj, user, OperatorMethod.Download); rules.Add(newRule); newRule.IsValidate = downChk.Checked; //针对当前类的子类设置权限(子类应自动继承父类权限) DataTable childCatalog = Catalog.GetCatalogTableByParentId(objId); foreach (DataRow cata in childCatalog.Rows) { SecurityObject cSecObj = new SecurityObject(new Guid(cata["catalogId"].ToString()), SecurityObjectType.Items); ObjectRule cOrUp = new ObjectRule(cSecObj, user, OperatorMethod.Write); cOrUp.IsValidate = chk.Checked; rules.Add(cOrUp); ObjectRule cOrEdit = new ObjectRule(cSecObj, user, OperatorMethod.Modify); cOrEdit.IsValidate = echk.Checked; rules.Add(cOrEdit); ObjectRule cOrDeny = new ObjectRule(cSecObj, user, OperatorMethod.Deny); cOrDeny.IsValidate = dchk.Checked; rules.Add(cOrDeny); ObjectRule cOrDown = new ObjectRule(cSecObj, user, OperatorMethod.Download); cOrDown.IsValidate = downChk.Checked; rules.Add(cOrDown); } } if (ObjectRule.SetRules(rules, secObj, opers)) { ShowMessage("用户权限设置成功"); } else { ShowMessage("用户权限设置失败"); } }
protected void btnSearchUser_Click(object sender, EventArgs e) { QJVRMS.Business.Group userGroup = new QJVRMS.Business.Group(CurrentGroupId); DataTable dt = userGroup.SelectUsers(this.txtloginName.Text.Trim(), this.txtUserName.Text.Trim()); Hashtable userRules = new Hashtable(); Dictionary<int, string> methodDict = WebUI.UIBiz.CommonInfo.GetMethodDict(); foreach (DataRow row in dt.Rows) { ISecurityObject securityObj = new SecurityObject(new Guid(this.hiCurrentCataId.Value), SecurityObjectType.Items); List<ObjectRule> rules = new List<ObjectRule>(); User user = new User(new Guid(row["userId"].ToString())); foreach (KeyValuePair<int, string> methodEntry in methodDict) { OperatorMethod method = (OperatorMethod)((int)methodEntry.Key); ObjectRule rule = new ObjectRule(securityObj, user, method); rules.Add(rule); } userRules.Add(user, rules); ObjectRule.CheckRules(rules); } foreach (KeyValuePair<int, string> methodEntry in methodDict) { string mIndex = methodEntry.Key.ToString(); dt.Columns.Add(mIndex, typeof(bool)); } foreach (DictionaryEntry entry in userRules) { User user = entry.Key as User; List<ObjectRule> rules = entry.Value as List<ObjectRule>; DataRow[] users = dt.Select("userId='" + user.UserId.ToString() + "'"); foreach (IRule rule in rules) { string methodKey = ((int)rule.Method).ToString(); users[0][methodKey] = rule.IsValidate; } } this.userList.DataSource = dt; this.userList.DataBind(); }
public IUser CreateUser(string password, string loginName, string userName, Guid groupId, string email, string tel, bool islocked, string isdownload, bool isIPValidate) { IUser user = null; Guid userId; DateTime nowTime = DateTime.Now; //SqlParameter[] Parameters = new SqlParameter[12]; //Parameters[0] = new SqlParameter("@loginName", SqlDbType.NVarChar); //Parameters[1] = new SqlParameter("@userName", SqlDbType.NVarChar); //Parameters[2] = new SqlParameter("@groupId", SqlDbType.UniqueIdentifier); //Parameters[3] = new SqlParameter("@password", SqlDbType.VarChar); //Parameters[4] = new SqlParameter("@tel", SqlDbType.VarChar); //Parameters[5] = new SqlParameter("@email", SqlDbType.VarChar); //Parameters[6] = new SqlParameter("@createDate", SqlDbType.DateTime); //Parameters[7] = new SqlParameter("@islocked", SqlDbType.Bit); //Parameters[8] = new SqlParameter("@isdownload", SqlDbType.Bit); //Parameters[9] = new SqlParameter("@isIPValidate", SqlDbType.Bit); //Parameters[10] = new SqlParameter("@NewUserId", SqlDbType.UniqueIdentifier); //Parameters[11] = new SqlParameter("@ReturnValue", SqlDbType.Int); //Parameters[0].Value = loginName; //Parameters[1].Value = userName; //Parameters[2].Value = groupId; //Parameters[3].Value = Encryption.Encrypt(password); //Parameters[4].Value = tel; //Parameters[5].Value = email; //Parameters[6].Value = nowTime; //Parameters[7].Value = islocked; //Parameters[8].Value = isdownload; //Parameters[9].Value = isIPValidate; //Parameters[10].Direction = ParameterDirection.Output; //Parameters[11].Direction = ParameterDirection.ReturnValue; //try //{ // SqlHelper.ExecuteNonQuery(SqlHelper.SqlCon_QJVRMS, CommandType.StoredProcedure, "Users_createUser", Parameters); // userId = new Guid(Parameters[10].Value.ToString()); // if ((Parameters[11].Value != null ? (int)Parameters[11].Value : -1) == 0) // { // user = new User(loginName, userName, userId, groupId, false, email, tel, nowTime, isdownload, isIPValidate); // } //} //catch //{ // return null; //} QJVRMS.Business.MemWS.MemberShipService mss = new QJVRMS.Business.MemWS.MemberShipService(); userId = mss.CreateUser(password, loginName, userName, groupId, email, tel, islocked, isdownload, isIPValidate); user = new User(loginName, userName, userId, groupId, false, email, tel, nowTime, isdownload, isIPValidate); return user; }