Exemplo n.º 1
0
        public ActionResult Index(LogOnModel input)
        {
            var user = RavenSession.GetUserByEmail(input.Login);

            if (user == null || user.ValidatePassword(input.Password) == false)
            {
                ModelState.AddModelError("UserNotExistOrPasswordNotMatch",
                                         "The email or password do not match to any known user.");
            }
            else if (user.Enabled == false)
            {
                ModelState.AddModelError("NotEnabled", "The user is not enabled");
            }

            if (ModelState.IsValid)
            {
                FormsAuthentication.SetAuthCookie(input.Login, true);
                return RedirectFromLoginPage(input.ReturnUrl);
            }

            return View(new LogOnModel {Login = input.Login, ReturnUrl = input.ReturnUrl});
        }
Exemplo n.º 2
0
		public void SignIn(LogOnModel logOn, bool isPersistent)
		{
			authenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie, DefaultAuthenticationTypes.TwoFactorCookie);

			var identity = new ClaimsIdentity(DefaultAuthenticationTypes.ApplicationCookie);
			identity.AddClaim(new Claim(ClaimTypes.Email, logOn.Login));

			if (logOn.RememberMe)
			{
				var rememberBrowserIdentity =
					authenticationManager.CreateTwoFactorRememberBrowserIdentity(logOn.Login);

				authenticationManager.SignIn(
					new AuthenticationProperties { IsPersistent = isPersistent },
					identity,
					rememberBrowserIdentity);
			}
			else
			{
				authenticationManager.SignIn(
					new AuthenticationProperties { IsPersistent = isPersistent },
					identity);
			}
		}