public ActionResult VerifySignInWith(AuthenticationProvider provider) { var result = AuthenticationService.FinalizeAuthentication(provider); if (result.IsSuccessful) { if (result.IsRegisteredDeveloper) { var authenticator = new CookieAuthenticator(); authenticator.SetCookie(result.Developer.Username, true); return(this.RedirectToDeveloperHome(result.Developer.Username)); } else { TempData["authenticationResult"] = result; return(RedirectToAction("Create", "Developer")); } } return(new HttpUnauthorizedResult("HAL: Without your space helmet, Dave? You're going to find that rather difficult.")); }
private static void CreateAuthenticationTicket(string Username, bool IsImagemakers) { IAuthenticator authenticator = new CookieAuthenticator(); authenticator.SetCookie(Username, false, (IsImagemakers) ? new string[] { "IM" } : null); }
public ActionResult Login(LoginModel user) { if (ModelState.IsValid) { string password; try { var rsaProvider = new RSACryptoServiceProvider(); rsaProvider.FromXmlString(Session["Encryption"].ToString()); password = Encoding.ASCII.GetString( rsaProvider.Decrypt(Convert.FromBase64String(user.Password), false) ); } catch (Exception ex) { ModelState.AddModelError("Invalid", "Invalid email address and/or password"); GenerateRsaInformation(); return(View()); } int?adminUserID; var response = AttemptLogin(user.Username, password, out adminUserID); if (response == AuthenticationResponse.ImagemakersSuccess || response == AuthenticationResponse.LocalSuccess) { if (response == AuthenticationResponse.ImagemakersSuccess) { IAuthenticator authenticator = new CookieAuthenticator(); var guid = authenticator.SetCookie(user.Username, false, new string[] { "IM", "Admin" }); _sessionRepo.Add(user.Username, UserIP, guid); } if (response == AuthenticationResponse.LocalSuccess) { var dbUser = _repo.FindByEmailAddress(user.Username); IAuthenticator authenticator = new CookieAuthenticator(); var guid = authenticator.SetCookie(user.Username, false, dbUser.Roles.Select(x => x.Name).ToArray()); _sessionRepo.Add(user.Username, UserIP, guid, adminUserID); } _uow.Commit(); if (!String.IsNullOrEmpty(Request.QueryString["ReturnUrl"]) && Url.IsLocalUrl(Request.QueryString["ReturnUrl"])) { return(Redirect(Request.QueryString["ReturnUrl"])); } else { return(Redirect("/")); } } ModelState.AddModelError( "Invalid", response == AuthenticationResponse.LockedOut ? "Looks like you've tried logging in too many times. Try again in a few minutes." : "Invalid username and/or password"); } GenerateRsaInformation(); return(View()); }