Exemple #1
0
        public ActionResult Register(int?id, Model.RegisterModel model)
        {
            if (Regex.IsMatch(model.UserName, "test\\d\\d"))
            {
                msg("抱歉,本系统内测,系统暂时不提供注册功能!有问题请QQ联系吴总。");
                return(View());
            }

            if (ModelState.IsValid)
            {
                if (!BLL.Login.CheckUserName(model.UserName))
                {
                    ModelState.AddModelError("UserName", "用户名必须是数字,字母或者下划线组成!");
                }
            }
            if (ModelState.IsValid)
            {
                if (model.UserName.Length < 5)
                {
                    ModelState.AddModelError("UserName", "用户名长度必须不小于六位数!");
                }
            }
            if (ModelState.IsValid)
            {
                try
                {
                    if (model.UserName.Length < 2)
                    {
                        ModelState.AddModelError("UserName", "用户名最小长度为2!");
                    }

                    if (ModelState.IsValid && !Regex.IsMatch(model.UserName, "^\\w+$"))
                    {
                        ModelState.AddModelError("UserName", "用户名必须由:\"数字,字母,下划线,或汉子,\"组合成!");
                    }

                    if (ModelState.IsValid && model.Password.Length < 6)
                    {
                        ModelState.AddModelError("Password", "密码不能小于六位!");
                    }

                    if (ModelState.IsValid)
                    {
                        Entity.advt_users advt_usersInfo = Data.advt_users.Get_advt_users(new { username = model.UserName });
                        if (advt_usersInfo != null)
                        {
                            ModelState.AddModelError("UserName", string.Format("用户名\"{0}\"已经存在!", model.UserName));
                        }
                    }

                    if (ModelState.IsValid)
                    {
                        Entity.advt_users advt_users = new Entity.advt_users();
                        advt_users.username = model.UserName;
                        advt_users.password = model.Password;
                        advt_users.email    = model.email;
                        advt_users.sex      = model.sex;
                        //if (id.GetValueOrDefault(0) > 0)
                        //{
                        //    Entity.advt_users _wbusers = Data.advt_users.Get_advt_users(id ?? 0);
                        //}
                        //int rst = MyWebSecurity.CreateUserAndAccount(advt_users);
                        //if (rst > 0)
                        //{
                        //    MyWebSecurity.Login(model.UserName, model.Password);
                        //}
                        //else
                        //{
                        //    ModelState.AddModelError("UserName", string.Format("用户名\"{0}\"创建失败!请联系管理员。", model.UserName));
                        //}
                    }

                    if (ModelState.IsValid)
                    {
                        #region 发送欢迎信息
                        //TODO:发送站点消息。
                        #endregion

                        return(RedirectToAction("Login", "Account"));
                    }
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
            }

            return(View("Login", model));
        }
Exemple #2
0
        public ActionResult Userinfo(Entity.advt_users info, string returnurl)
        {
            List <Entity.advt_user_group> ladvt_user_group = BLL.Login.GetAllUserGroup();

            ViewBag.ladvt_user_group = ladvt_user_group;

            Entity.advt_users tp_info = new advt_users();

            if (ModelState.IsValid)
            {
                if (UserContext.roles == (int)Entity.Status.RoleStatus.Admin)
                {
                }
                else
                {
                    if (info.id != UserContext.id)
                    {
                        alert("非法操作!", Url.Action("Userinfo", "Account", new { Area = "" }));
                        ModelState.AddModelError("", "非法操作!");
                    }
                }

                if (ModelState.IsValid && !string.IsNullOrWhiteSpace(info.nickname) && !BLL.Login.CheckUserName(info.nickname))
                {
                    ModelState.AddModelError("nickname", "昵称 格式不正确!");
                }

                if (ModelState.IsValid && string.IsNullOrWhiteSpace(info.firstname))
                {
                    ModelState.AddModelError("firstname", "姓 不能为空!");
                }

                if (ModelState.IsValid && !BLL.Login.CheckUserName(info.firstname))
                {
                    ModelState.AddModelError("firstname", "姓 格式不正确!");
                }

                if (ModelState.IsValid && string.IsNullOrWhiteSpace(info.lastname))
                {
                    ModelState.AddModelError("lastname", "名字 不能为空!");
                }

                if (ModelState.IsValid && !BLL.Login.CheckUserName(info.lastname))
                {
                    ModelState.AddModelError("lastname", "名字 格式不正确!");
                }

                if (ModelState.IsValid && Utils.IsInt(((Entity.Status.Sex)info.sex).ToString()))
                {
                    ModelState.AddModelError("sex", "性别填写有误!");
                }

                if (ModelState.IsValid && !string.IsNullOrWhiteSpace(info.phone) && !BLL.Login.CheckPhone(info.phone))
                {
                    ModelState.AddModelError("phone", "电话 格式不正确!");
                }

                if (ModelState.IsValid && !string.IsNullOrWhiteSpace(info.email) && !Common.Utils.IsValidEmail(info.email))
                {
                    ModelState.AddModelError("email", "e-Mail 格式不正确!");
                }

                tp_info = Data.advt_users.Get_advt_users(info.id);

                if (ModelState.IsValid && tp_info == null)
                {
                    ModelState.AddModelError("", "系统错误,请重试!");
                }

                if (ModelState.IsValid)
                {
                    int rst = 0;
                    try
                    {
                        tp_info.nickname    = info.nickname;
                        tp_info.phone       = info.phone;
                        tp_info.qq          = info.qq;
                        tp_info.msn         = info.msn;
                        tp_info.email       = info.email;
                        tp_info.description = info.description;
                        tp_info.firstname   = info.firstname;
                        tp_info.lastname    = info.lastname;
                        tp_info.sex         = info.sex;

                        if (UserContext.roles == (int)Entity.Status.RoleStatus.Admin)
                        {
                            tp_info.status      = info.status;
                            tp_info.usergroupid = info.usergroupid;
                        }

                        rst = Data.advt_users.Update_advt_users(tp_info, null, new string[] { "id" });
                        if (rst == 1)
                        {
                            if (info.id == UserContext.id)
                            {
                                Manager.Login.UserContext = null;
                            }
                            right("修改成功!");
                            if (!string.IsNullOrEmpty(returnurl))
                            {
                                return(Redirect(returnurl));
                            }
                        }
                        else
                        {
                            alert("插入失败!");
                        }
                    }
                    catch
                    {
                        alert("系统错误,请联系管理员!");
                    }
                }
            }

            return(View(tp_info));
        }
Exemple #3
0
 public static int GetChatRoles(Entity.advt_users advt_users)
 {
     return(1);//advt_users.usergroupid != null && (advt_users.usergroupid == 3 || advt_users.usergroupid == 1) ? 1 : 0;
 }