Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
neozhu committed Aug 31, 2021
1 parent 9bdc3a1 commit 414c911
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
<input type="hidden" asp-for="Input.UserName" />
<input type="hidden" asp-for="Input.Email" />
<input type="hidden" asp-for="ReturnUrl" />

<div class="py-3">
<img src="@Model.Input.ProfilePictureDataUrl" class="img-responsive rounded-circle img-thumbnail" alt="thumbnail">
</div>

<div class="form-group">
<h3>
@Model.Input.UserName
Expand All @@ -33,6 +35,7 @@
<div class="text-center">
<a asp-page="Login" class="text-white opacity-90">Not <span class="text-secondary">@ViewBag.User</span>?</a>
</div>
<div asp-validation-summary="All" class="alert alert-primary text-dark"></div>
</form>
</div>

Expand Down
41 changes: 26 additions & 15 deletions src/SmartAdmin.WebUI/Areas/Identity/Pages/Account/Lockout.cshtml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;
using CleanArchitecture.Razor.Application.Common.Interfaces;
using CleanArchitecture.Razor.Infrastructure.Identity;
Expand Down Expand Up @@ -80,25 +81,35 @@ public async Task<IActionResult> OnPostAsync(string returnUrl = null)
// This doesn't count login failures towards account lockout
// To enable password failures to trigger account lockout, set lockoutOnFailure: true
var userName = Input.UserName;
var result = await _signInManager.PasswordSignInAsync(userName, Input.Password, true, lockoutOnFailure: true);

if (result.Succeeded)
{
_logger.LogInformation("User logged in.");
return LocalRedirect(returnUrl);
}
if (result.RequiresTwoFactor)
{
return RedirectToPage("./LoginWith2fa", new { ReturnUrl = returnUrl, RememberMe = true });
}
if (result.IsLockedOut)
var user = await _userManager.FindByNameAsync(userName);
var lockoutresult = await _userManager.SetLockoutEndDateAsync(user, System.DateTimeOffset.Now.AddMinutes(-1));
if (lockoutresult.Succeeded)
{
_logger.LogWarning("User account locked out.");
return RedirectToPage("./Lockout", new { userName = Input.UserName, ReturnUrl = returnUrl });
var result = await _signInManager.PasswordSignInAsync(userName, Input.Password, true, lockoutOnFailure: true);

if (result.Succeeded)
{
_logger.LogInformation("User logged in.");
return LocalRedirect(returnUrl);
}
if (result.RequiresTwoFactor)
{
return RedirectToPage("./LoginWith2fa", new { ReturnUrl = returnUrl, RememberMe = true });
}
if (result.IsLockedOut)
{
_logger.LogWarning("User account locked out.");
return RedirectToPage("./Lockout", new { userName = Input.UserName, ReturnUrl = returnUrl });
}
else
{
ModelState.AddModelError(string.Empty, "Invalid login attempt.");
return Page();
}
}
else
{
ModelState.AddModelError(string.Empty, "Invalid login attempt.");
ModelState.AddModelError(string.Empty, lockoutresult.Errors.First().Description);
return Page();
}
}
Expand Down

0 comments on commit 414c911

Please sign in to comment.