public async Task <IActionResult> OnPostAsync(string returnUrl = null) { returnUrl = returnUrl ?? Url.Content("~/"); if (ModelState.IsValid) { // This doesn't count login failures towards account lockout // To enable password failures to trigger account lockout, set lockoutOnFailure: true var result = await _signInManager.PasswordSignInAsync(Input.Email, Input.Password, Input.RememberMe, lockoutOnFailure : true); if (result.Succeeded) { _logger.LogInformation("User logged in."); return(LocalRedirect(returnUrl)); } else { // Login failed attempt - create an audit record var auditrecord = new AuditRecord(); auditrecord.AuditActionType = "Failed Login"; auditrecord.DateTimeStamp = DateTime.Now; auditrecord.KeyMovieFieldID = 999; // 999 – dummy record auditrecord.Username = Input.Email; // save the email used for the failed login _context.AuditRecords.Add(auditrecord); await _context.SaveChangesAsync(); } if (result.RequiresTwoFactor) { return(RedirectToPage("./LoginWith2fa", new { ReturnUrl = returnUrl, RememberMe = Input.RememberMe })); } if (result.IsLockedOut) { _logger.LogWarning("User account locked out."); return(RedirectToPage("./Lockout")); } else { ModelState.AddModelError(string.Empty, "Invalid login attempt."); return(Page()); } } // If we got this far, something failed, redisplay form return(Page()); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Movie = await _context.Movie.FindAsync(id); if (Movie != null) { _context.Movie.Remove(Movie); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }