Example #1
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                using (this._context)
                {
                    var salt = _saltGenerator.GenerateSaltValue(24);
                    var password = _passwordSalter.SaltPassword(model.Password, salt);
                    var user = new User { Email = model.Email, Password = password, Salt = salt };

                    this._context.Users.Add(user);
                    this._context.SaveChanges();

                    var loginModel = new LoginModel { Password = model.Password, UserName = model.Email };
                    return Login(loginModel, "/");
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
Example #2
0
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            using (_authenticationProvider)
            {
                var principal = _authenticationProvider.ValidateCredentials(model.UserName, model.Password);

                if (principal != null)
                {
                    _authenticationProvider.Logon(principal, Response);

                    return this.RedirectToLocal(returnUrl);
                }
            }

            ModelState.AddModelError("error", "Invalid username/password combination.  Please try again.");
            return View(model);
        }