public ActionResult Account(string returnUrl) { var model = new AuthModelView() { ReturnUrl = returnUrl }; return(View(model)); }
public async Task <ActionResult> MemberLoginSummary(AuthModelView model) { if (!ModelState.IsValid) { return(View(model)); } var user = await UserManager.FindByNameAsync(model.LoginModel.Email); if (user != null) { if (!await UserManager.IsEmailConfirmedAsync(user.Id)) { ModelState.AddModelError("", "Musisz potwierdzić swój email aby się zalogować."); return(View("Account", model)); } else if (UserManager.IsInRole(user.Id, "Admin")) { ModelState.AddModelError("", "Nieprawidłowy email lub hasło"); return(View("Account", model)); } } // This doesn't count login failures towards account lockout // To enable password failures to trigger account lockout, change to shouldLockout: true var result = await SignInManager.PasswordSignInAsync(model.LoginModel.Email, model.LoginModel.Password, model.LoginModel.RememberMe, shouldLockout : false); switch (result) { case SignInStatus.Success: if (model.ReturnUrl != null) { return(RedirectToLocal(model.ReturnUrl)); } return(RedirectToAction("List", "Event")); case SignInStatus.LockedOut: return(View("Lockout")); case SignInStatus.RequiresVerification: return(RedirectToAction("SendCode", new { ReturnUrl = model.ReturnUrl, RememberMe = model.LoginModel.RememberMe })); case SignInStatus.Failure: default: ModelState.AddModelError("", "Nieprawidłowy email lub hasło"); return(View("Account", model)); } }
public async Task <ActionResult> AdminLogin(AuthModelView model) { if (!ModelState.IsValid) { return(View(model)); } var user = await UserManager.FindByNameAsync(model.LoginModel.Email); if (user != null) { if (UserManager.IsInRole(user.Id, "Admin")) { var result = await SignInManager.PasswordSignInAsync(model.LoginModel.Email, model.LoginModel.Password, model.LoginModel.RememberMe, shouldLockout : false); switch (result) { case SignInStatus.Success: //return RedirectToLocal(model.ReturnUrl); return(Redirect(Url.Action("Index", "Admin") + "#tile")); case SignInStatus.LockedOut: return(View("Lockout")); case SignInStatus.RequiresVerification: return(RedirectToAction("SendCode", new { ReturnUrl = model.ReturnUrl, RememberMe = model.LoginModel.RememberMe })); case SignInStatus.Failure: default: ModelState.AddModelError("", "Nieprawidłowy email lub hasło"); return(View("AdminLogin", model)); } } ModelState.AddModelError("", "Nie masz uprawnień"); } else { ModelState.AddModelError("", "Nieprawidłowy login lub hasło"); } return(View("AdminLogin", model)); }
public async Task <ActionResult> MemberRegisterSummary(AuthModelView model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.RegisterModel.Email, Email = model.RegisterModel.Email }; var result = await UserManager.CreateAsync(user, model.RegisterModel.Password); if (result.Succeeded) { //await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false); // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); UserManager.AddToRole(user.Id, "User"); StringBuilder builder = new StringBuilder(); builder.Append("<h2>Potwierdź swój adres email</h2>"); builder.Append("Potwierdź swoje konto klikając na ten link:<a href=\"" + callbackUrl + "\">here</a>"); await UserManager.SendEmailAsync(user.Id, "Dziękujemy za zarejestrowanie się w serwisie TicketHunter!", builder.ToString()); return(RedirectToAction("ConfirmEmailSended", "Account")); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View("Account", model)); }