Exemple #1
0
        public ActionResult Register(RegisterModel model, CaptchaViewModel captchaViewModel)
        {
            if (model.CaptchaInput.Trim().ToLower() != captchaViewModel.CaptchaText.Trim().ToLower())
            {
                ModelState.AddModelError("Wrong captcha, please try again", new MissingFieldException());
            }
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                try
                {
                    WebSecurity.CreateUserAndAccount(
                        model.UserName,
                        model.Password,
                        new
                    {
                        FullName     = model.FullName,
                        EmailAddress = model.EmailAddress,
                        Phone        = model.Phone,
                        Activated    = false
                    },
                        false);
                    string activationCode = _encryptionEngine.DESEncrypt(
                        model.UserName + separator.ToString() + model.EmailAddress);
                    _smtpEmail.SendActivationEmail(
                        activationCode,
                        model.FullName,
                        model.EmailAddress);
                    ViewBag.Message = "An activation email sent to your email address";
                    return(View("Message"));
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }