Exemple #1
0
        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));
        }
Exemple #2
0
        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));
        }