Set LoginProvider when ExternalLoginConfirmation fails (#187)

Addresses #98
This commit is contained in:
Jass Bagga 2017-12-12 11:27:11 -08:00 committed by GitHub
parent 4d2e642b94
commit 26ea920fa6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 13 deletions

View File

@ -99,8 +99,6 @@ namespace Company.WebApplication1.Pages.Account
} }
public async Task<IActionResult> OnPostConfirmationAsync(string returnUrl = null) public async Task<IActionResult> OnPostConfirmationAsync(string returnUrl = null)
{
if (ModelState.IsValid)
{ {
// Get the information about the user from the external login provider // Get the information about the user from the external login provider
var info = await _signInManager.GetExternalLoginInfoAsync(); var info = await _signInManager.GetExternalLoginInfoAsync();
@ -108,6 +106,9 @@ namespace Company.WebApplication1.Pages.Account
{ {
throw new ApplicationException("Error loading external login information during confirmation."); throw new ApplicationException("Error loading external login information during confirmation.");
} }
if (ModelState.IsValid)
{
var user = new ApplicationUser { UserName = Input.Email, Email = Input.Email }; var user = new ApplicationUser { UserName = Input.Email, Email = Input.Email };
var result = await _userManager.CreateAsync(user); var result = await _userManager.CreateAsync(user);
if (result.Succeeded) if (result.Succeeded)
@ -126,6 +127,7 @@ namespace Company.WebApplication1.Pages.Account
} }
} }
LoginProvider = info.LoginProvider;
ReturnUrl = returnUrl; ReturnUrl = returnUrl;
return Page(); return Page();
} }

View File

@ -306,8 +306,6 @@ namespace Company.WebApplication1.Identity.Controllers
[AllowAnonymous] [AllowAnonymous]
[ValidateAntiForgeryToken] [ValidateAntiForgeryToken]
public async Task<IActionResult> ExternalLoginConfirmation(ExternalLoginViewModel model, string returnUrl = null) public async Task<IActionResult> ExternalLoginConfirmation(ExternalLoginViewModel model, string returnUrl = null)
{
if (ModelState.IsValid)
{ {
// Get the information about the user from the external login provider // Get the information about the user from the external login provider
var info = await _signInManager.GetExternalLoginInfoAsync(); var info = await _signInManager.GetExternalLoginInfoAsync();
@ -315,6 +313,9 @@ namespace Company.WebApplication1.Identity.Controllers
{ {
throw new ApplicationException("Error loading external login information during confirmation."); throw new ApplicationException("Error loading external login information during confirmation.");
} }
if (ModelState.IsValid)
{
var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
var result = await _userManager.CreateAsync(user); var result = await _userManager.CreateAsync(user);
if (result.Succeeded) if (result.Succeeded)
@ -327,9 +328,11 @@ namespace Company.WebApplication1.Identity.Controllers
return RedirectToLocal(returnUrl); return RedirectToLocal(returnUrl);
} }
} }
AddErrors(result); AddErrors(result);
} }
ViewData["LoginProvider"] = info.LoginProvider;
ViewData["ReturnUrl"] = returnUrl; ViewData["ReturnUrl"] = returnUrl;
return View(nameof(ExternalLogin), model); return View(nameof(ExternalLogin), model);
} }