diff --git a/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Register.cshtml b/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Register.cshtml
index aa5ecba592..137715804a 100644
--- a/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Register.cshtml
+++ b/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Register.cshtml
@@ -12,20 +12,28 @@
@L["Login"]
@if (!Model.IsExternalLogin && Model.VisibleExternalProviders.Any())
diff --git a/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Register.cshtml.cs b/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Register.cshtml.cs
index 5836ec2123..7bc536ba9d 100644
--- a/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Register.cshtml.cs
+++ b/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Register.cshtml.cs
@@ -38,6 +38,9 @@ public class RegisterModel : AccountPageModel
public IEnumerable ExternalProviders { get; set; }
public IEnumerable 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 OnGetAsync()
{
- if (!IsExternalLogin)
+ ExternalProviders = await GetExternalProviders();
+
+ if (!await CheckSelfRegistrationAsync())
{
- await CheckSelfRegistrationAsync();
+ if (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 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> GetExternalProviders()
{
+
var schemes = await SchemeProvider.GetAllSchemesAsync();
return schemes
@@ -194,6 +214,15 @@ public class RegisterModel : AccountPageModel
})
.ToList();
}
+
+ protected virtual async Task 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
{