mirror of
https://github.com/morbalint/kemkas.git
synced 2026-07-18 03:13:46 +00:00
add Google login
This commit is contained in:
@@ -123,20 +123,42 @@ namespace Kemkas.Web.Areas.Identity.Pages.Account
|
||||
{
|
||||
return RedirectToPage("./Lockout");
|
||||
}
|
||||
else
|
||||
|
||||
// If the user does not have an account, and no email claim, then ask the user to create an account.
|
||||
ReturnUrl = returnUrl;
|
||||
ProviderDisplayName = info.ProviderDisplayName;
|
||||
if (!info.Principal.HasClaim(c => c.Type == ClaimTypes.Email))
|
||||
{
|
||||
// If the user does not have an account, then ask the user to create an account.
|
||||
ReturnUrl = returnUrl;
|
||||
ProviderDisplayName = info.ProviderDisplayName;
|
||||
if (info.Principal.HasClaim(c => c.Type == ClaimTypes.Email))
|
||||
{
|
||||
Input = new InputModel
|
||||
{
|
||||
Email = info.Principal.FindFirstValue(ClaimTypes.Email)
|
||||
};
|
||||
}
|
||||
return Page();
|
||||
}
|
||||
|
||||
// User doesn't have account but external provider has email claim. => Register with claimed email.
|
||||
Input = new InputModel
|
||||
{
|
||||
Email = info.Principal.FindFirstValue(ClaimTypes.Email)
|
||||
};
|
||||
var user = CreateUser();
|
||||
await _userStore.SetUserNameAsync(user, Input.Email, CancellationToken.None);
|
||||
await _emailStore.SetEmailAsync(user, Input.Email, CancellationToken.None);
|
||||
var registrationResult = await _userManager.CreateAsync(user);
|
||||
if (registrationResult.Succeeded)
|
||||
{
|
||||
registrationResult = await _userManager.AddLoginAsync(user, info);
|
||||
if (registrationResult.Succeeded)
|
||||
{
|
||||
_logger.LogInformation("User created an account using {Name} provider.", info.LoginProvider);
|
||||
var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
|
||||
await _userManager.ConfirmEmailAsync(user, code);
|
||||
await _signInManager.SignInAsync(user, isPersistent: false, info.LoginProvider);
|
||||
return LocalRedirect(returnUrl);
|
||||
}
|
||||
}
|
||||
foreach (var error in registrationResult.Errors)
|
||||
{
|
||||
ModelState.AddModelError(string.Empty, error.Description);
|
||||
}
|
||||
|
||||
return Page();
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostConfirmationAsync(string returnUrl = null)
|
||||
|
||||
Reference in New Issue
Block a user