public ActionResult SignIn(SignInViewModel model, string returnUrl) { if (!ModelState.IsValid) { return(View()); } var volunteer = volunteerDataService.SelectOne(v => v.Username == model.Username); if (volunteer != null && !volunteer.Active) { ModelState.AddModelError("Username", "You account is inactive. Please contact us to activate your account."); return(View()); } if (volunteer != null && volunteer.Password == volunteerDataService.HashPassword(model.Password, volunteer.Id)) { formsAuthenticationService.SetAuthCookie(volunteer, model.RememberMe); return(Redirect(returnUrl ?? "~/")); } ModelState.AddModelError("Username", "Invalid username or password."); return(View()); }
public bool LogOn(string userName, string password, bool rememberMe) { if (membershipService.ValidateUser(userName, password)) { formsAuthenticationService.SetAuthCookie(userName, rememberMe); return(true); } return(false); }
public virtual ActionResult Register(viewModels.RegisterViewModel model) { if (ModelState.IsValid) { // Attempt to register the user MembershipCreateStatus createStatus; membershipService.CreateUser(model.UserName, model.Password, model.Email, model.SecretQuestion, model.SecretAnswer, true, out createStatus); if (createStatus == MembershipCreateStatus.Success) { formsAuthenticationService.SetAuthCookie(model.UserName, false /* createPersistentCookie */); return(RedirectToAction("Index", "Home")); } else { ModelState.AddModelError("", ErrorCodeToString(createStatus)); } } return(RedirectToAction("Register")); }
public bool SignIn(string username, string password, bool rememberMe) { var authenticated = _agentAuthenticator.Authenticate(username, password); if (!authenticated) { return(false); } _formsAuthentication.SetAuthCookie(username, rememberMe); return(true); }
public virtual ActionResult Respond(string returnUrl) { string validatedReturnUrl = Uri.IsWellFormedUriString(returnUrl, UriKind.Relative) ? returnUrl : null; IAuthenticationResponse response = _openIdService.GetResponse(); if (response != null) { switch (response.Status) { case AuthenticationStatus.Authenticated: _formsAuthenticationService.SetAuthCookie(response.ClaimedIdentifier, false); if (!string.IsNullOrEmpty(validatedReturnUrl)) { return(Redirect(validatedReturnUrl)); } return(RedirectToAction(MVC.About.Index())); case AuthenticationStatus.Canceled: ModelState.AddModelError("Canceled", "The authentication was canceled."); break; case AuthenticationStatus.Failed: ModelState.AddModelError(response.Exception.Message, response.Exception.Message); break; case AuthenticationStatus.ExtensionsOnly: ModelState.AddModelError("ExtensionsOnly", "Google sent a message that did not contain an identity assertion, but may carry OpenID extensions."); break; case AuthenticationStatus.SetupRequired: ModelState.AddModelError("SetupRequired", "Google responded to a additional setup is required."); break; default: throw new ArgumentOutOfRangeException(); } } else { ModelState.AddModelError("NoOpenIDIdentifier", "No OpenID identifier was provided"); } return(RedirectToAction(MVC.Accounts.LogIn(validatedReturnUrl))); }
public ActionResult Index(logInModel model) { if (ModelState.IsValid) { bool match = authenticator.Authenticate(model.Username, model.Password); if (match) { formsAuthentication.SetAuthCookie(model.Username, false); return(RedirectToAction("index", "home")); } else { ModelState.AddModelError("", "Invalid username or password"); } } return(View()); }
public bool SignIn(string username, string password, bool rememberMe) { var authenticated = _agentAuthenticator.Authenticate(username, password); if (!authenticated) { return(false); } var identity = new GenericIdentity(username); _currentSdkUser.SetUser(_principalFactory.CreatePrincipal(identity)); _formsAuthentication.SetAuthCookie(username, rememberMe); return(true); }
public ActionResult Login(LoginViewModel loginViewModel) { if (loginViewModel == null) { throw new ArgumentNullException("loginViewModel"); } if (ModelState.IsValid) { var user = userService.GetUserByUserName(loginViewModel.Name); if (user != null) { if (!user.IsActive) { ModelState.AddModelError( "Name", "Please activate your account first by clicking on the link in your " + "activation email."); return(View("Login", loginViewModel)); } var hashedPassword = formsAuthenticationService.HashAndSalt( loginViewModel.Name, loginViewModel.Password); if (hashedPassword == user.Password) { formsAuthenticationService.SetAuthCookie(user.UserName, false); if (user is Child) { return(RedirectToAction("ChildView", "Account")); } else { return(RedirectToAction("Index", "Child")); } } ModelState.AddModelError("Password", "Invalid Password"); } else { ModelState.AddModelError("Name", "Invalid Name"); } } return(View("Login", loginViewModel)); }
public virtual ActionResult LogOn(SignInRequest request, string returnUrl) { // TODO: modify the Object.cshtml partial to make the first text box autofocus, or use additional metadata ViewData[Constants.ReturnUrlViewDataKey] = returnUrl; if (!ModelState.IsValid) { return(View()); } var user = userSvc.FindByUsernameOrEmailAddressAndPassword( request.UserNameOrEmail, request.Password); if (user == null) { ModelState.AddModelError( String.Empty, Strings.UserNotFound); return(View()); } if (!user.Confirmed) { ViewBag.ConfirmationRequired = true; return(View()); } IEnumerable <string> roles = null; if (user.Roles.AnySafe()) { roles = user.Roles.Select(r => r.Name); } formsAuthSvc.SetAuthCookie( user.Username, true, roles); return(SafeRedirect(returnUrl)); }
public ActionResult Authenticate(string returnUrl) { var response = openIdService.GetResponse(); // Stage 2: Make the request to the openId provider if (response == null) { try { return(openIdService.CreateRequest(Request.Form["openid_identifier"])); } catch (OpenIdException openIdException) { ViewData["Message"] = openIdException.Message; return(View("Login")); } } // Stage 3: OpenID Provider sending assertion response switch (response.Status) { case AuthenticationStatus.Authenticated: formsAuthenticationService.SetAuthCookie(response.ClaimedIdentifier, false); CreateNewParentIfTheyDontAlreadyExist(response); if (!string.IsNullOrEmpty(returnUrl)) { return(Redirect(returnUrl)); } return(RedirectToAction("Index", "Home")); case AuthenticationStatus.Canceled: ViewData["Message"] = "Canceled at provider"; return(View("Login")); case AuthenticationStatus.Failed: ViewData["Message"] = response.Exception.Message; return(View("Login")); } throw new TardisBankException("Unknown AuthenticationStatus Response"); }
public ActionResult Login(UserAccountModel user) { var login = user.Login; var passwordHash = user.HashOfPassword; var searchResults = userService.GetByLogin(login); if (searchResults != null) { if (searchResults.HashOfPassword == passwordHash) { formsAuthentication.SetAuthCookie(user.Login, true); return(RedirectToAction("Index", "Admin")); } } ModelState.AddModelError("", "Ошибка! Пожалуйста, проверьте ввееденные данные!"); return(View("Login", user)); }
public bool SignIn(string username, string password, bool rememberMe) { _logger.LogDebug("Authenticating session {0}.".ToFormat(username)); var isAuthenticated = _agentAuthenticator.Authenticate(username, password); if (!isAuthenticated) { return(false); } _impersonationService.StopImpersonating(username); _currentSdkUser.SetUser(username); _formsAuthentication.SetAuthCookie(username, rememberMe); return(true); }
public ActionResult SignUp(UserSignUpView userSignUpView) { if (User.Identity.IsAuthenticated) { return(RedirectToAction("Index", "Home")); } else if (!ModelState.IsValid) { return(View(userSignUpView)); } string error = userManagerModel.CheckIfAccountExists(userSignUpView.LoginName, userSignUpView.Email); if (error != null) { ModelState.AddModelError("", error); return(View(userSignUpView)); } else { userManagerModel.AddAccount(userSignUpView); formsAuthentication.SetAuthCookie(userSignUpView.LoginName, false); return(RedirectToAction("Welcome", "Home")); } }