From a3b443f1470de4f66eb56f0627616ad70fa366b5 Mon Sep 17 00:00:00 2001 From: maliming Date: Fri, 1 Sep 2023 10:30:39 +0800 Subject: [PATCH 1/2] Prevent to disable account authenticated user self. --- .../Volo/Abp/Identity/IdentityUserAppService.cs | 5 ++++- .../Pages/Identity/UserManagement.razor | 9 ++++++--- .../Pages/Identity/UserManagement.razor.cs | 3 ++- .../Pages/Identity/Users/EditModal.cshtml | 6 ++++-- .../Pages/Identity/Users/EditModal.cshtml.cs | 4 +++- 5 files changed, 19 insertions(+), 8 deletions(-) diff --git a/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserAppService.cs b/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserAppService.cs index 498184b9cc..fa1beb9124 100644 --- a/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserAppService.cs +++ b/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserAppService.cs @@ -173,7 +173,10 @@ public class IdentityUserAppService : IdentityAppServiceBase, IIdentityUserAppSe (await UserManager.SetPhoneNumberAsync(user, input.PhoneNumber)).CheckErrors(); } - (await UserManager.SetLockoutEnabledAsync(user, input.LockoutEnabled)).CheckErrors(); + if (user.Id != CurrentUser.Id) + { + (await UserManager.SetLockoutEnabledAsync(user, input.LockoutEnabled)).CheckErrors(); + } user.Name = input.Name; user.Surname = input.Surname; diff --git a/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/UserManagement.razor b/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/UserManagement.razor index afa3fd3897..0f66c7131e 100644 --- a/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/UserManagement.razor +++ b/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/UserManagement.razor @@ -129,9 +129,12 @@ @L["DisplayName:IsActive"] - - @L["DisplayName:LockoutEnabled"] - + @if (!IsEditCurrentUser) + { + + @L["DisplayName:LockoutEnabled"] + + } diff --git a/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/UserManagement.razor.cs b/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/UserManagement.razor.cs index 403e46601d..b219c820a6 100644 --- a/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/UserManagement.razor.cs +++ b/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/UserManagement.razor.cs @@ -41,6 +41,7 @@ public partial class UserManagement private List UserManagementTableColumns => TableColumns.Get(); private TextRole _passwordTextRole = TextRole.Password; + public bool IsEditCurrentUser { get; set; } public UserManagement() { @@ -119,7 +120,7 @@ public partial class UserManagement try { EditModalSelectedTab = DefaultSelectedTab; - + IsEditCurrentUser = entity.Id == CurrentUser.Id; var userRoleNames = (await AppService.GetRolesAsync(entity.Id)).Items.Select(r => r.Name).ToList(); EditUserRoles = Roles.Select(x => new AssignedRoleViewModel diff --git a/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/EditModal.cshtml b/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/EditModal.cshtml index 28d0fd6da6..3e5a59fe57 100644 --- a/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/EditModal.cshtml +++ b/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/EditModal.cshtml @@ -39,8 +39,10 @@ - - + @if (!Model.IsEditCurrentUser) + { + + } @foreach (var propertyInfo in ObjectExtensionManager.Instance.GetProperties()) { if (!propertyInfo.Name.EndsWith("_Text")) diff --git a/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/EditModal.cshtml.cs b/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/EditModal.cshtml.cs index 2b15d794ac..55365498a7 100644 --- a/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/EditModal.cshtml.cs +++ b/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/EditModal.cshtml.cs @@ -22,6 +22,8 @@ public class EditModalModel : IdentityPageModel protected IIdentityUserAppService IdentityUserAppService { get; } + public bool IsEditCurrentUser { get; set; } + public EditModalModel(IIdentityUserAppService identityUserAppService) { IdentityUserAppService = identityUserAppService; @@ -30,7 +32,7 @@ public class EditModalModel : IdentityPageModel public virtual async Task OnGetAsync(Guid id) { UserInfo = ObjectMapper.Map(await IdentityUserAppService.GetAsync(id)); - + IsEditCurrentUser = CurrentUser.Id == id; Roles = ObjectMapper.Map, AssignedRoleViewModel[]>((await IdentityUserAppService.GetAssignableRolesAsync()).Items); var userRoleNames = (await IdentityUserAppService.GetRolesAsync(UserInfo.Id)).Items.Select(r => r.Name).ToList(); From 4da3cf412a6c5fc462ab0b92b6d5a2a3289fed7c Mon Sep 17 00:00:00 2001 From: Masum ULU Date: Fri, 1 Sep 2023 10:06:48 +0300 Subject: [PATCH 2/2] Refactor error handler for 401 status code --- .../src/lib/handlers/error.handler.ts | 22 ++++++------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/npm/ng-packs/packages/theme-shared/src/lib/handlers/error.handler.ts b/npm/ng-packs/packages/theme-shared/src/lib/handlers/error.handler.ts index cc7f733798..3077e22b00 100644 --- a/npm/ng-packs/packages/theme-shared/src/lib/handlers/error.handler.ts +++ b/npm/ng-packs/packages/theme-shared/src/lib/handlers/error.handler.ts @@ -1,4 +1,4 @@ - import { +import { AuthService, HttpErrorReporterService, LocalizationParam, @@ -86,7 +86,6 @@ export class ErrorHandler { protected httpErrorConfig: HttpErrorConfig; protected sessionStateService: SessionStateService; private authService: AuthService; - constructor(protected injector: Injector) { this.httpErrorReporter = injector.get(HttpErrorReporterService); @@ -146,7 +145,7 @@ export class ErrorHandler { }; if (err instanceof HttpErrorResponse && err.headers.get('Abp-Tenant-Resolve-Error')) { - this.sessionStateService.setTenant(null) + this.sessionStateService.setTenant(null); this.authService.logout().subscribe(); return; } @@ -162,18 +161,11 @@ export class ErrorHandler { } else { switch (err.status) { case 401: - this.canCreateCustomError(401) - ? this.show401Page() - : this.showError( - { - key: DEFAULT_ERROR_LOCALIZATIONS.defaultError401.title, - defaultValue: DEFAULT_ERROR_MESSAGES.defaultError401.title, - }, - { - key: DEFAULT_ERROR_LOCALIZATIONS.defaultError401.details, - defaultValue: DEFAULT_ERROR_MESSAGES.defaultError401.details, - }, - ).subscribe(() => this.navigateToLogin()); + if (this.canCreateCustomError(401)) { + this.show401Page(); + } + + this.navigateToLogin(); break; case 403: this.createErrorComponent({