From 22c72c51e5280b40e8975188955d20c3054ba47b Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Fri, 18 Aug 2023 19:55:54 +0800 Subject: [PATCH 1/7] Improve --- .../Pages/Account/Register.cshtml | 22 +++++--- .../Pages/Account/Register.cshtml.cs | 51 +++++++++++++++---- 2 files changed, 55 insertions(+), 18 deletions(-) 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) + @if (!Model.IsExternalLogin && Model.EnableLocalRegister) { } + + @if(Model.EnableLocalRegister || Model.IsExternalLogin) + { + + } - - - @if (!Model.IsExternalLogin) + @if (!Model.IsExternalLogin && Model.EnableLocalRegister) { } -
- @L["Register"] -
+ + @if(Model.EnableLocalRegister || Model.IsExternalLogin) + { +
+ @L["Register"] +
+ } + @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..1b1a02d201 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 (!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 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 { From 019144e746d7fe72c8a5ca26f64242bb2107c426 Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Fri, 18 Aug 2023 20:20:39 +0800 Subject: [PATCH 2/7] Update Register.cshtml.cs --- .../src/Volo.Abp.Account.Web/Pages/Account/Register.cshtml.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 1b1a02d201..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 @@ -62,7 +62,7 @@ public class RegisterModel : AccountPageModel if (!await CheckSelfRegistrationAsync()) { - if (!IsExternalLogin && IsExternalLoginOnly) + if (IsExternalLoginOnly) { return await OnPostExternalLogin(ExternalLoginScheme); } From 736b072d09749aa9e3c9f35414ea33a58e14be17 Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Sun, 20 Aug 2023 22:05:52 +0800 Subject: [PATCH 3/7] Fix AbpDashboardOptionsProvider --- docs/en/Background-Jobs-Hangfire.md | 14 ++++++-------- .../Hangfire/AbpDashboardOptionsProvider.cs | 13 +++++++++++-- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/docs/en/Background-Jobs-Hangfire.md b/docs/en/Background-Jobs-Hangfire.md index 77f2da8bd0..6f13d32e05 100644 --- a/docs/en/Background-Jobs-Hangfire.md +++ b/docs/en/Background-Jobs-Hangfire.md @@ -128,10 +128,9 @@ You can integrate the Hangfire dashboard to [ABP authorization system](Authoriza class. This class is defined in the `Volo.Abp.Hangfire` package. The following example, checks if the current user is logged in to the application: ```csharp -app.UseHangfireDashboard("/hangfire", new DashboardOptions -{ - AsyncAuthorization = new[] { new AbpHangfireAuthorizationFilter() } -}); +var dashboardOptions = app.ApplicationServices.GetRequiredService(); +dashboardOptions.AsyncAuthorization = new[] { new AbpHangfireAuthorizationFilter() }; +app.UseHangfireDashboard("/hangfire", dashboardOptions); ``` * `AbpHangfireAuthorizationFilter` is an implementation of an authorization filter. @@ -146,10 +145,9 @@ app.UseHangfireDashboard("/hangfire", new DashboardOptions If you want to require an additional permission, you can pass it into the constructor as below: ```csharp -app.UseHangfireDashboard("/hangfire", new DashboardOptions -{ - AsyncAuthorization = new[] { new AbpHangfireAuthorizationFilter(requiredPermissionName: "MyHangFireDashboardPermissionName") } -}); +var dashboardOptions = app.ApplicationServices.GetRequiredService(); +dashboardOptions.AsyncAuthorization = new[] { new AbpHangfireAuthorizationFilter(requiredPermissionName: "MyHangFireDashboardPermissionName") }; +app.UseHangfireDashboard("/hangfire", dashboardOptions); ``` **Important**: `UseHangfireDashboard` should be called after the authentication and authorization middlewares in your `Startup` class (probably at the last line). Otherwise, diff --git a/framework/src/Volo.Abp.BackgroundJobs.HangFire/Volo/Abp/BackgroundJobs/Hangfire/AbpDashboardOptionsProvider.cs b/framework/src/Volo.Abp.BackgroundJobs.HangFire/Volo/Abp/BackgroundJobs/Hangfire/AbpDashboardOptionsProvider.cs index bc41b21ce8..e68489290a 100644 --- a/framework/src/Volo.Abp.BackgroundJobs.HangFire/Volo/Abp/BackgroundJobs/Hangfire/AbpDashboardOptionsProvider.cs +++ b/framework/src/Volo.Abp.BackgroundJobs.HangFire/Volo/Abp/BackgroundJobs/Hangfire/AbpDashboardOptionsProvider.cs @@ -1,4 +1,5 @@ using System.Linq; +using System.Threading; using Hangfire; using Microsoft.Extensions.Options; using Volo.Abp.DependencyInjection; @@ -18,8 +19,16 @@ public class AbpDashboardOptionsProvider : ITransientDependency { return new DashboardOptions { - DisplayNameFunc = (dashboardContext, job) => - AbpBackgroundJobOptions.GetJob(job.Args.First().GetType()).JobName + DisplayNameFunc = (_, job) => + { + var jobName = job.ToString(); + if (job.Args.Count == 3 && job.Args.Last() is CancellationToken) + { + jobName = AbpBackgroundJobOptions.GetJob(job.Args[1].GetType()).JobName; + } + + return jobName; + } }; } } From fa10f3a82d846d04c4572c371dfd172f671452b9 Mon Sep 17 00:00:00 2001 From: Ahmad Nidal <79116096+Ahmad-Nidal@users.noreply.github.com> Date: Sun, 20 Aug 2023 17:40:40 +0300 Subject: [PATCH 4/7] Fix Spelling in a word Auto-API-Controllers.md Contoller = > Controller --- docs/en/API/Auto-API-Controllers.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/API/Auto-API-Controllers.md b/docs/en/API/Auto-API-Controllers.md index 1644e2d28a..0ffbc644a8 100644 --- a/docs/en/API/Auto-API-Controllers.md +++ b/docs/en/API/Auto-API-Controllers.md @@ -204,7 +204,7 @@ public class MyApplicationConfigurationDto : ApplicationConfigurationDto } ```` -### Remove contoller +### Remove controller Configure `ControllersToRemove` of `AbpAspNetCoreMvcOptions` to remove the controllers. From 3e1953d9c954f4cf487027736a7e410216e98644 Mon Sep 17 00:00:00 2001 From: maliming Date: Mon, 21 Aug 2023 08:29:32 +0800 Subject: [PATCH 5/7] Add `localization` section in OpenIddict Explain why we didn't use localization error messages. --- docs/en/Modules/OpenIddict.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/docs/en/Modules/OpenIddict.md b/docs/en/Modules/OpenIddict.md index cb9d36a30c..20098eb975 100644 --- a/docs/en/Modules/OpenIddict.md +++ b/docs/en/Modules/OpenIddict.md @@ -471,7 +471,24 @@ In **Blazor wasm** applications, add `options.ProviderOptions.DefaultScopes.Add( In **Angular** applications, add `offline_access` to **oAuthConfig** scopes in *environment.ts* file. (Angular applications already have this configuration). +## About localization +We don't localize any error messages in the OpenIddict module, Because the OAuth 2.0 specification restricts the charset you're allowed to use for the error and error_description parameters: + +> A.7. "error" Syntax +> The "error" element is defined in Sections 4.1.2.1, 4.2.2.1, 5.2, 7.2, and 8.5: + +``` +error = 1*NQSCHAR +``` + +> A.8. "error_description" Syntax +>T he "error_description" element is defined in Sections 4.1.2.1, 4.2.2.1, 5.2, and 7.2: + +``` +error-description = 1*NQSCHAR +NQSCHAR = %x20-21 / %x23-5B / %x5D-7E +``` ## Demo projects From 7a56f78313c9a335a6b6f9e9503e32f79a0b778e Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Mon, 21 Aug 2023 11:08:22 +0800 Subject: [PATCH 6/7] Add UseAbpHangfireDashboard method --- docs/en/Background-Jobs-Hangfire.md | 20 +++++++------- docs/en/Background-Workers-Hangfire.md | 4 +-- ...AbpHangfireApplicationBuilderExtensions.cs | 26 +++++++++++++++++++ 3 files changed, 39 insertions(+), 11 deletions(-) create mode 100644 framework/src/Volo.Abp.BackgroundJobs.HangFire/Microsoft/AspNetCore/Builder/AbpHangfireApplicationBuilderExtensions.cs diff --git a/docs/en/Background-Jobs-Hangfire.md b/docs/en/Background-Jobs-Hangfire.md index 6f13d32e05..69903e1c85 100644 --- a/docs/en/Background-Jobs-Hangfire.md +++ b/docs/en/Background-Jobs-Hangfire.md @@ -70,7 +70,7 @@ After you have installed these NuGet packages, you need to configure your projec > You have to configure a storage for Hangfire. -2. If you want to use hangfire's dashboard, you can add `UseHangfireDashboard` call in the `OnApplicationInitialization` method in `Module` class: +2. If you want to use hangfire's dashboard, you can add `UseAbpHangfireDashboard` call in the `OnApplicationInitialization` method in `Module` class: ````csharp public override void OnApplicationInitialization(ApplicationInitializationContext context) @@ -79,7 +79,7 @@ After you have installed these NuGet packages, you need to configure your projec // ... others - app.UseHangfireDashboard(); //should add to the request pipeline before the app.UseConfiguredEndpoints() + app.UseAbpHangfireDashboard(); //should add to the request pipeline before the app.UseConfiguredEndpoints() app.UseConfiguredEndpoints(); } ```` @@ -128,9 +128,10 @@ You can integrate the Hangfire dashboard to [ABP authorization system](Authoriza class. This class is defined in the `Volo.Abp.Hangfire` package. The following example, checks if the current user is logged in to the application: ```csharp -var dashboardOptions = app.ApplicationServices.GetRequiredService(); -dashboardOptions.AsyncAuthorization = new[] { new AbpHangfireAuthorizationFilter() }; -app.UseHangfireDashboard("/hangfire", dashboardOptions); +app.UseAbpHangfireDashboard("/hangfire", options => +{ + options.AsyncAuthorization = new[] { new AbpHangfireAuthorizationFilter() }; +}); ``` * `AbpHangfireAuthorizationFilter` is an implementation of an authorization filter. @@ -145,10 +146,11 @@ app.UseHangfireDashboard("/hangfire", dashboardOptions); If you want to require an additional permission, you can pass it into the constructor as below: ```csharp -var dashboardOptions = app.ApplicationServices.GetRequiredService(); -dashboardOptions.AsyncAuthorization = new[] { new AbpHangfireAuthorizationFilter(requiredPermissionName: "MyHangFireDashboardPermissionName") }; -app.UseHangfireDashboard("/hangfire", dashboardOptions); +app.UseAbpHangfireDashboard("/hangfire", options => +{ + options.AsyncAuthorization = new[] { new AbpHangfireAuthorizationFilter(requiredPermissionName: "MyHangFireDashboardPermissionName") }; +}); ``` -**Important**: `UseHangfireDashboard` should be called after the authentication and authorization middlewares in your `Startup` class (probably at the last line). Otherwise, +**Important**: `UseAbpHangfireDashboard` should be called after the authentication and authorization middlewares in your `Startup` class (probably at the last line). Otherwise, authorization will always fail! diff --git a/docs/en/Background-Workers-Hangfire.md b/docs/en/Background-Workers-Hangfire.md index 9506eb97a7..70c8d0cf95 100644 --- a/docs/en/Background-Workers-Hangfire.md +++ b/docs/en/Background-Workers-Hangfire.md @@ -70,7 +70,7 @@ After you have installed these NuGet packages, you need to configure your projec > You have to configure a storage for Hangfire. -2. If you want to use hangfire's dashboard, you can add `UseHangfireDashboard` call in the `OnApplicationInitialization` method in `Module` class +2. If you want to use hangfire's dashboard, you can add `UseAbpHangfireDashboard` call in the `OnApplicationInitialization` method in `Module` class ````csharp public override void OnApplicationInitialization(ApplicationInitializationContext context) @@ -79,7 +79,7 @@ After you have installed these NuGet packages, you need to configure your projec // ... others - app.UseHangfireDashboard(); //should add to the request pipeline before the app.UseConfiguredEndpoints() + app.UseAbpHangfireDashboard(); //should add to the request pipeline before the app.UseConfiguredEndpoints() app.UseConfiguredEndpoints(); } ```` diff --git a/framework/src/Volo.Abp.BackgroundJobs.HangFire/Microsoft/AspNetCore/Builder/AbpHangfireApplicationBuilderExtensions.cs b/framework/src/Volo.Abp.BackgroundJobs.HangFire/Microsoft/AspNetCore/Builder/AbpHangfireApplicationBuilderExtensions.cs new file mode 100644 index 0000000000..2b79b37f76 --- /dev/null +++ b/framework/src/Volo.Abp.BackgroundJobs.HangFire/Microsoft/AspNetCore/Builder/AbpHangfireApplicationBuilderExtensions.cs @@ -0,0 +1,26 @@ +using System; +using Hangfire; +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.BackgroundJobs.Hangfire; + +namespace Microsoft.AspNetCore.Builder; + +public static class AbpHangfireApplicationBuilderExtensions +{ + public static IApplicationBuilder UseAbpHangfireDashboard( + this IApplicationBuilder app, + string pathMatch = "/hangfire", + Action? configure = null, + JobStorage? storage = null) + { + var options = app.ApplicationServices.GetRequiredService().Get(); + configure?.Invoke(options); + return app.UseHangfireDashboard(pathMatch, options, storage); + + + app.UseAbpHangfireDashboard("/hangfire", options => + { + options.AsyncAuthorization = new[] { new AbpHangfireAuthorizationFilter() }; + }); + } +} \ No newline at end of file From b3d494c719eed5eba28564a4ee11b796b62244bd Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Mon, 21 Aug 2023 11:09:16 +0800 Subject: [PATCH 7/7] Update AbpHangfireApplicationBuilderExtensions.cs --- .../Builder/AbpHangfireApplicationBuilderExtensions.cs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/framework/src/Volo.Abp.BackgroundJobs.HangFire/Microsoft/AspNetCore/Builder/AbpHangfireApplicationBuilderExtensions.cs b/framework/src/Volo.Abp.BackgroundJobs.HangFire/Microsoft/AspNetCore/Builder/AbpHangfireApplicationBuilderExtensions.cs index 2b79b37f76..1b49510517 100644 --- a/framework/src/Volo.Abp.BackgroundJobs.HangFire/Microsoft/AspNetCore/Builder/AbpHangfireApplicationBuilderExtensions.cs +++ b/framework/src/Volo.Abp.BackgroundJobs.HangFire/Microsoft/AspNetCore/Builder/AbpHangfireApplicationBuilderExtensions.cs @@ -16,11 +16,5 @@ public static class AbpHangfireApplicationBuilderExtensions var options = app.ApplicationServices.GetRequiredService().Get(); configure?.Invoke(options); return app.UseHangfireDashboard(pathMatch, options, storage); - - - app.UseAbpHangfireDashboard("/hangfire", options => - { - options.AsyncAuthorization = new[] { new AbpHangfireAuthorizationFilter() }; - }); } } \ No newline at end of file