Exemplo n.º 1
0
        public ActionResult Register(RegisterModel model)
        {
            var code = (this.SessionGet <string>(SessionName.验证码) ?? "").ToLower();

            this.SessionRemove(SessionName.验证码);

            if (model.Validcode.ToLower() != code)
            {
                this.ModelState.AddModelError("Validcode", "验证码不正确");
                return(View(model));
            }
            if (this.ModelState.IsValid)
            {
                if (this._userService.UserNickExist(model.NickName))
                {
                    this.ModelState.AddModelError("NickName", "昵称已经被使用");
                    return(View(model));
                }

                // 尝试注册用户
                try
                {
                    var token = WebSecurity.CreateUserAndAccount(model.UserName, model.Password,
                                                                 new
                    {
                        Email = model.UserName,
                        model.NickName,
                        model.Sex,
                        model.Province,
                        model.City,
                        model.ProvinceName,
                        model.CityName
                    }, true);

                    var userid = WebSecurity.GetUserId(model.UserName);

                    var uid = this._userService.InserOrUpdateExtUid(userid);


                    SystemMessagerManager.SendValidateMail(Dev.Comm.Web.HttpServerInfo.BaseUrl, model.UserName, model.NickName, "邮件激活",
                                                           SystemMessagerManager.ActMessage(Dev.Comm.Web.HttpServerInfo.BaseUrl, model.UserName,
                                                                                            model.NickName, token));


                    return(this.RedirectToAction("EmailActivation", new { email = model.UserName }));
                }
                catch (MembershipCreateUserException e)
                {
                    this.ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
            }

            // 如果我们进行到这一步时某个地方出错,则重新显示表单
            return(View(model));
        }
Exemplo n.º 2
0
        public ActionResult ResendToken(string email)
        {
            if (WebSecurity.IsConfirmed(email))
            {
                return(this.Json(false));
            }

            var NickName = this._userService.GetNickNameByUserName(email);

            var token = this._userService.GetTokenByUserName(email);

            SystemMessagerManager.SendValidateMail(Dev.Comm.Web.HttpServerInfo.BaseUrl, email, NickName, "邮件激活",
                                                   SystemMessagerManager.ActMessage(Dev.Comm.Web.HttpServerInfo.BaseUrl, email, NickName, token));

            return(this.Json(true));
        }
Exemplo n.º 3
0
        private BaseState GetPassWordByEmail(string baseurl, GetPwdModel model)
        {
            if (!Dev.Comm.Validate.Validate.IsEmail(model.UserName))
            {
                return(new BaseState(-1, "用户名非邮箱!"));
            }


            var nick  = this.GetNickNameByUserName(model.UserName);
            var token = WebSecurity.GeneratePasswordResetToken(model.UserName);
            var mail  = SystemMessagerManager.GetContentForGetPass(baseurl, nick, token);
            var isok  = SystemMessagerManager.SendValidateMail(baseurl, model.UserName, nick, "找回密码", mail);

            if (isok)
            {
                return(new BaseState());
            }

            return(new BaseState {
                ErrorCode = -1, ErrorMessage = "发送邮件失败"
            });
        }