|
|
|
@ -1,6 +1,4 @@ |
|
|
|
using Microsoft.eShopWeb.Services; |
|
|
|
using Microsoft.eShopWeb.ViewModels; |
|
|
|
using Microsoft.AspNetCore.Hosting; |
|
|
|
using Microsoft.eShopWeb.ViewModels; |
|
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Microsoft.AspNetCore.Authorization; |
|
|
|
@ -16,7 +14,6 @@ namespace Microsoft.eShopWeb.Controllers |
|
|
|
private readonly SignInManager<ApplicationUser> _signInManager; |
|
|
|
private readonly string _externalCookieScheme; |
|
|
|
|
|
|
|
|
|
|
|
public AccountController( |
|
|
|
UserManager<ApplicationUser> userManager, |
|
|
|
SignInManager<ApplicationUser> signInManager, |
|
|
|
@ -27,59 +24,39 @@ namespace Microsoft.eShopWeb.Controllers |
|
|
|
_userManager = userManager; |
|
|
|
_signInManager = signInManager; |
|
|
|
_externalCookieScheme = identityCookieOptions.Value.ExternalCookieAuthenticationScheme; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//
|
|
|
|
// GET: /Account/SignIn
|
|
|
|
[HttpGet] |
|
|
|
[AllowAnonymous] |
|
|
|
public async Task<IActionResult> SignIn(string returnUrl = null) |
|
|
|
{ |
|
|
|
// Clear the existing external cookie to ensure a clean login process
|
|
|
|
await HttpContext.Authentication.SignOutAsync(_externalCookieScheme); |
|
|
|
|
|
|
|
ViewData["ReturnUrl"] = returnUrl; |
|
|
|
return View(); |
|
|
|
} |
|
|
|
|
|
|
|
//
|
|
|
|
// POST: /Account/SignIn
|
|
|
|
[HttpPost] |
|
|
|
[AllowAnonymous] |
|
|
|
[ValidateAntiForgeryToken] |
|
|
|
public async Task<IActionResult> SignIn(LoginViewModel model, string returnUrl = null) |
|
|
|
{ |
|
|
|
ViewData["ReturnUrl"] = returnUrl; |
|
|
|
if (ModelState.IsValid) |
|
|
|
if (!ModelState.IsValid) |
|
|
|
{ |
|
|
|
// This doesn't count login failures towards account lockout
|
|
|
|
// To enable password failures to trigger account lockout, set lockoutOnFailure: true
|
|
|
|
return View(model); |
|
|
|
} |
|
|
|
ViewData["ReturnUrl"] = returnUrl; |
|
|
|
|
|
|
|
var result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, lockoutOnFailure: false); |
|
|
|
if (result.Succeeded) |
|
|
|
{ |
|
|
|
//_logger.LogInformation(1, "User logged in.");
|
|
|
|
return RedirectToLocal(returnUrl); |
|
|
|
} |
|
|
|
//if (result.RequiresTwoFactor)
|
|
|
|
//{
|
|
|
|
// return RedirectToAction(nameof(SendCode), new { ReturnUrl = returnUrl, RememberMe = model.RememberMe });
|
|
|
|
//}
|
|
|
|
if (result.IsLockedOut) |
|
|
|
{ |
|
|
|
//_logger.LogWarning(2, "User account locked out.");
|
|
|
|
return View("Lockout"); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
ModelState.AddModelError(string.Empty, "Invalid login attempt."); |
|
|
|
return View(model); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// If we got this far, something failed, redisplay form
|
|
|
|
return View(model); |
|
|
|
} |
|
|
|
|
|
|
|
private IActionResult RedirectToLocal(string returnUrl) |
|
|
|
{ |
|
|
|
@ -92,7 +69,5 @@ namespace Microsoft.eShopWeb.Controllers |
|
|
|
return RedirectToAction(nameof(CatalogController.Index), "Catalog"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|