|
|
|
@ -38,6 +38,9 @@ public class RegisterModel : AccountPageModel |
|
|
|
|
|
|
|
public IEnumerable<ExternalProviderModel> ExternalProviders { get; set; } |
|
|
|
public IEnumerable<ExternalProviderModel> VisibleExternalProviders => ExternalProviders.Where(x => !string.IsNullOrWhiteSpace(x.DisplayName)); |
|
|
|
public bool EnableLocalRegister { get; set; } |
|
|
|
public bool IsExternalLoginOnly => EnableLocalRegister == false && ExternalProviders?.Count() == 1; |
|
|
|
public string ExternalLoginScheme => IsExternalLoginOnly ? ExternalProviders?.SingleOrDefault()?.AuthenticationScheme : null; |
|
|
|
|
|
|
|
protected IAuthenticationSchemeProvider SchemeProvider { get; } |
|
|
|
|
|
|
|
@ -55,13 +58,20 @@ public class RegisterModel : AccountPageModel |
|
|
|
|
|
|
|
public virtual async Task<IActionResult> OnGetAsync() |
|
|
|
{ |
|
|
|
if (!IsExternalLogin) |
|
|
|
ExternalProviders = await GetExternalProviders(); |
|
|
|
|
|
|
|
if (!await CheckSelfRegistrationAsync()) |
|
|
|
{ |
|
|
|
await CheckSelfRegistrationAsync(); |
|
|
|
if (!IsExternalLogin && IsExternalLoginOnly) |
|
|
|
{ |
|
|
|
return await OnPostExternalLogin(ExternalLoginScheme); |
|
|
|
} |
|
|
|
|
|
|
|
Alerts.Warning(L["SelfRegistrationDisabledMessage"]); |
|
|
|
} |
|
|
|
|
|
|
|
await TrySetEmailAsync(); |
|
|
|
ExternalProviders = await GetExternalProviders(); |
|
|
|
|
|
|
|
return Page(); |
|
|
|
} |
|
|
|
|
|
|
|
@ -96,12 +106,12 @@ public class RegisterModel : AccountPageModel |
|
|
|
{ |
|
|
|
try |
|
|
|
{ |
|
|
|
if (!IsExternalLogin) |
|
|
|
ExternalProviders = await GetExternalProviders(); |
|
|
|
|
|
|
|
if (!await CheckSelfRegistrationAsync()) |
|
|
|
{ |
|
|
|
await CheckSelfRegistrationAsync(); |
|
|
|
throw new UserFriendlyException(L["SelfRegistrationDisabledMessage"]); |
|
|
|
} |
|
|
|
|
|
|
|
ExternalProviders = await GetExternalProviders(); |
|
|
|
|
|
|
|
if (IsExternalLogin) |
|
|
|
{ |
|
|
|
@ -172,17 +182,27 @@ public class RegisterModel : AccountPageModel |
|
|
|
await SignInManager.SignInAsync(user, isPersistent: true, ExternalLoginAuthSchema); |
|
|
|
} |
|
|
|
|
|
|
|
protected virtual async Task CheckSelfRegistrationAsync() |
|
|
|
protected virtual async Task<bool> CheckSelfRegistrationAsync() |
|
|
|
{ |
|
|
|
if (!await SettingProvider.IsTrueAsync(AccountSettingNames.IsSelfRegistrationEnabled) || |
|
|
|
!await SettingProvider.IsTrueAsync(AccountSettingNames.EnableLocalLogin)) |
|
|
|
EnableLocalRegister = await SettingProvider.IsTrueAsync(AccountSettingNames.EnableLocalLogin) && |
|
|
|
await SettingProvider.IsTrueAsync(AccountSettingNames.IsSelfRegistrationEnabled); |
|
|
|
|
|
|
|
if (IsExternalLogin) |
|
|
|
{ |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
if (!EnableLocalRegister) |
|
|
|
{ |
|
|
|
throw new UserFriendlyException(L["SelfRegistrationDisabledMessage"]); |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
protected virtual async Task<List<ExternalProviderModel>> GetExternalProviders() |
|
|
|
{ |
|
|
|
|
|
|
|
var schemes = await SchemeProvider.GetAllSchemesAsync(); |
|
|
|
|
|
|
|
return schemes |
|
|
|
@ -194,6 +214,15 @@ public class RegisterModel : AccountPageModel |
|
|
|
}) |
|
|
|
.ToList(); |
|
|
|
} |
|
|
|
|
|
|
|
protected virtual async Task<IActionResult> OnPostExternalLogin(string provider) |
|
|
|
{ |
|
|
|
var redirectUrl = Url.Page("./Login", pageHandler: "ExternalLoginCallback", values: new { ReturnUrl, ReturnUrlHash }); |
|
|
|
var properties = SignInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl); |
|
|
|
properties.Items["scheme"] = provider; |
|
|
|
|
|
|
|
return await Task.FromResult(Challenge(properties, provider)); |
|
|
|
} |
|
|
|
|
|
|
|
public class PostInput |
|
|
|
{ |
|
|
|
|