private void AddUserInfo_Click(object sender, EventArgs e) { #region 添加新用户信息 if (this.CheckCookie()) { if (userName.Text.Trim() == "" || password.Text.Trim() == "") { base.RegisterStartupScript("", "<script>alert('用户名或密码为空,因此无法提交!');window.location.href='global_adduser.aspx';</script>"); return; } if (!Utils.IsSafeSqlString(userName.Text)) { base.RegisterStartupScript("", "<script>alert('您输入的用户名包含不安全的字符,因此无法提交!');window.location.href='global_adduser.aspx';</script>"); return; } if (PrivateMessages.SystemUserName == userName.Text) { base.RegisterStartupScript("", "<script>alert('您不能创建该用户名,因为它是系统保留的用户名,请您输入其它的用户名!');window.location.href='global_adduser.aspx';</script>"); return; } if (!Utils.IsValidEmail(email.Text.Trim())) { base.RegisterStartupScript("", "<script>alert('E-mail为空或格式不正确,因此无法提交!');window.location='global_adduser.aspx';</script>"); return; } UserInfo userInfo = CreateUserInfo(); if (AdminUsers.GetUserId(userName.Text) > 0) { base.RegisterStartupScript("", "<script>alert('您所输入的用户名已被使用过, 请输入其他的用户名!');window.location.href='global_adduser.aspx';</script>"); return; } if (!Users.ValidateEmail(email.Text)) { base.RegisterStartupScript("", "<script>alert('您所输入的邮箱地址已被使用过, 请输入其他的邮箱!');window.location.href='global_adduser.aspx';</script>"); return; } if (config.Passwordmode > 1 && PasswordModeProvider.GetInstance() != null) { PasswordModeProvider.GetInstance().CreateUserInfo(userInfo); } else { userInfo.Password = Utils.MD5(userInfo.Password); AdminUsers.CreateUser(userInfo); } AdminVistLogs.InsertLog(this.userid, this.username, this.usergroupid, this.grouptitle, this.ip, "后台添加用户", "用户名:" + userName.Text); string emailresult = null; if (sendemail.Checked) { emailresult = SendEmail(email.Text); } base.RegisterStartupScript("PAGE", "window.location.href='global_usergrid.aspx';"); } #endregion }
public ActionResult Add(string name = "") { string form = Request.Form.ToString(); form = HttpUtility.UrlDecode(form); Dictionary <string, string> parms = CommonHelper.ParmsToDic(form); if (AdminUsers.IsExistMobile(parms["Mobile"])) { ModelState.AddModelError("Mobile", "手机号已经存在"); } UserModel us = new UserModel(); if (ModelState.IsValid) { string salt = Users.GenerateUserSalt(); UserInfo userInfo = new UserInfo() { UserName = parms["Mobile"], Email = "", Mobile = parms["Mobile"], Salt = salt, Password = Users.CreateUserPassword(parms["Password"].ToString(), salt), UserRid = int.Parse(parms["UserRid"].ToString()), AdminGid = int.Parse(parms["AdminGid"]), NickName = parms["NickName"], Avatar = "", PayCredits = 0, RankCredits = 0, VerifyEmail = 0, VerifyMobile = 0, LiftBanTime = new DateTime(1900, 1, 1), LastVisitTime = DateTime.Now, LastVisitIP = WorkContext.IP, LastVisitRgId = WorkContext.RegionId, RegisterTime = DateTime.Now, RegisterIP = WorkContext.IP, RegisterRgId = WorkContext.RegionId, Gender = 0, RealName = "", Bday = new DateTime(1970, 1, 1), IdCard = "", RegionId = -1, Address = "", Bio = "" }; userInfo.UserRid = userInfo.UserRid == 0 ? 7 : userInfo.UserRid; int uid = AdminUsers.CreateUser(userInfo); if (uid > 0) { AddAdminOperateLog("添加用户", "添加用户,用户为:" + parms["Mobile"]); return(PromptView("用户添加成功")); } else { return(PromptView("用户添加失败")); } } else { us = new UserModel { Mobile = parms["Mobile"], NickName = parms["NickName"], Password = parms["Password"], ConfirmPassword = parms["ConfirmPassword"], UserRid = int.Parse(parms["UserRid"]) }; } Load(-1); return(View(us)); }
public ActionResult Add(UserModel model) { if (string.IsNullOrWhiteSpace(model.Password)) { ModelState.AddModelError("Password", "密码不能为空"); } if (AdminUsers.IsExistUserName(model.UserName)) { ModelState.AddModelError("UserName", "名称已经存在"); } if (AdminUsers.IsExistEmail(model.Email)) { ModelState.AddModelError("Email", "email已经存在"); } if (AdminUsers.IsExistMobile(model.Mobile)) { ModelState.AddModelError("Mobile", "手机号已经存在"); } if (ModelState.IsValid) { string salt = Users.GenerateUserSalt(); string nickName; if (string.IsNullOrWhiteSpace(model.NickName)) { nickName = "bsp" + Randoms.CreateRandomValue(7); } else { nickName = model.NickName; } UserInfo userInfo = new UserInfo() { UserName = model.UserName, Email = model.Email == null ? "" : model.Email, Mobile = model.Mobile == null ? "" : model.Mobile, Salt = salt, Password = Users.CreateUserPassword(model.Password, salt), UserRid = model.UserRid, AdminGid = model.AdminGid, NickName = WebHelper.HtmlEncode(nickName), Avatar = model.Avatar == null ? "" : WebHelper.HtmlEncode(model.Avatar), PayCredits = model.PayCredits, RankCredits = AdminUserRanks.GetUserRankById(model.UserRid).CreditsLower, VerifyEmail = 1, VerifyMobile = 1, LiftBanTime = UserRanks.IsBanUserRank(model.UserRid) ? DateTime.Now.AddDays(WorkContext.UserRankInfo.LimitDays) : new DateTime(1900, 1, 1), LastVisitTime = DateTime.Now, LastVisitIP = WorkContext.IP, LastVisitRgId = WorkContext.RegionId, RegisterTime = DateTime.Now, RegisterIP = WorkContext.IP, RegisterRgId = WorkContext.RegionId, Gender = model.Gender, RealName = model.RealName == null ? "" : WebHelper.HtmlEncode(model.RealName), Bday = model.Bday ?? new DateTime(1970, 1, 1), IdCard = model.IdCard == null ? "" : model.IdCard, RegionId = model.RegionId, Address = model.Address == null ? "" : WebHelper.HtmlEncode(model.Address), Bio = model.Bio == null ? "" : WebHelper.HtmlEncode(model.Bio) }; AdminUsers.CreateUser(userInfo); AddAdminOperateLog("添加用户", "添加用户,用户为:" + model.UserName); return(PromptView("用户添加成功")); } Load(model.RegionId); return(View(model)); }
private void AddUserInfo_Click(object sender, EventArgs e) { #region 添加新用户信息 if (this.CheckCookie()) { if (userName.Text.Trim() == "" || password.Text.Trim() == "") { base.RegisterStartupScript("", "<script>alert('用户名或密码为空,因此无法提交!');window.location.href='global_adduser.aspx';</script>"); return; } if (!Utils.IsSafeSqlString(userName.Text)) { base.RegisterStartupScript("", "<script>alert('您输入的用户名包含不安全的字符,因此无法提交!');window.location.href='global_adduser.aspx';</script>"); return; } if (PrivateMessages.SystemUserName == userName.Text) { base.RegisterStartupScript("", "<script>alert('您不能创建该用户名,因为它是系统保留的用户名,请您输入其它的用户名!');window.location.href='global_adduser.aspx';</script>"); return; } if (!Utils.IsValidEmail(email.Text.Trim())) { base.RegisterStartupScript("", "<script>alert('E-mail为空或格式不正确,因此无法提交!');window.location='global_adduser.aspx';</script>"); return; } int selectgroupid = Convert.ToInt32(groupid.SelectedValue); UserInfo __userinfo = new UserInfo(); __userinfo.Username = userName.Text; __userinfo.Nickname = userName.Text; __userinfo.Password = Utils.MD5(password.Text); __userinfo.Secques = ""; __userinfo.Gender = 0; __userinfo.Adminid = AdminUserGroups.AdminGetUserGroupInfo(selectgroupid).Radminid; __userinfo.Groupid = selectgroupid; __userinfo.Groupexpiry = 0; __userinfo.Extgroupids = ""; __userinfo.Regip = ""; __userinfo.Joindate = Utils.GetDate(); //DateTime.Now.ToString(); __userinfo.Lastip = ""; __userinfo.Lastvisit = Utils.GetDate(); //DateTime.Now.ToString(); __userinfo.Lastactivity = Utils.GetDate(); //DateTime.Now.ToString(); __userinfo.Lastpost = Utils.GetDate(); //DateTime.Now.ToString(); __userinfo.Lastpostid = 0; __userinfo.Lastposttitle = ""; __userinfo.Posts = 0; __userinfo.Digestposts = 0; __userinfo.Oltime = 0; __userinfo.Pageviews = 0; __userinfo.Credits = Convert.ToInt32(credits.Text); __userinfo.Extcredits1 = 0; __userinfo.Extcredits2 = 0; __userinfo.Extcredits3 = 0; __userinfo.Extcredits4 = 0; __userinfo.Extcredits5 = 0; __userinfo.Extcredits6 = 0; __userinfo.Extcredits7 = 0; __userinfo.Extcredits8 = 0; __userinfo.Avatarshowid = 1; __userinfo.Email = email.Text; __userinfo.Bday = ""; __userinfo.Sigstatus = 0; GeneralConfigInfo __configinfo = GeneralConfigs.Deserialize(Server.MapPath("../../config/general.config")); __userinfo.Templateid = __configinfo.Templateid; __userinfo.Tpp = 16; __userinfo.Ppp = 16; __userinfo.Pmsound = 1; __userinfo.Showemail = 1; __userinfo.Newsletter = (ReceivePMSettingType)7; __userinfo.Invisible = 0; __userinfo.Newpm = 0; __userinfo.Accessmasks = 0; //扩展信息 __userinfo.Website = ""; __userinfo.Icq = ""; __userinfo.Qq = ""; __userinfo.Yahoo = ""; __userinfo.Msn = ""; __userinfo.Skype = ""; __userinfo.Location = ""; __userinfo.Customstatus = ""; __userinfo.Avatar = ""; __userinfo.Avatarwidth = 32; __userinfo.Avatarheight = 32; __userinfo.Medals = ""; __userinfo.Bio = ""; __userinfo.Signature = userName.Text; __userinfo.Sightml = ""; __userinfo.Authstr = ""; __userinfo.Realname = realname.Text; __userinfo.Idcard = idcard.Text; __userinfo.Mobile = mobile.Text; __userinfo.Phone = phone.Text; if (AdminUsers.GetUserID(userName.Text) != -1) { base.RegisterStartupScript("", "<script>alert('您所输入的用户名已被使用过, 请输入其他的用户名!');window.location.href='global_adduser.aspx';</script>"); return; } if (__configinfo.Doublee == 0) { if (AdminUsers.FindUserEmail(email.Text) != -1) { base.RegisterStartupScript("", "<script>alert('您所输入的邮箱地址已被使用过, 请输入其他的邮箱!');window.location.href='global_adduser.aspx';</script>"); return; } } AdminUsers.CreateUser(__userinfo); AdminVistLogs.InsertLog(this.userid, this.username, this.usergroupid, this.grouptitle, this.ip, "后台添加用户", "用户名:" + userName.Text); string emailresult = null; if (sendemail.Checked) { emailresult = SendEmail(email.Text); } base.RegisterStartupScript("PAGE", "window.location.href='global_usergrid.aspx';"); } #endregion }