From e2f8eb014a02e0da0b624de4c44e943b80837c72 Mon Sep 17 00:00:00 2001 From: Carl Sixsmith Date: Tue, 20 Aug 2024 08:05:13 +0100 Subject: [PATCH] Addresses issues with user registration - The phone number now saves on create - Two factor auth is enabled by default - Set all users to 'false' for export and import --- .../Features/Identity/DTOs/ApplicationUserDto.cs | 1 + src/Server.UI/Pages/Identity/Users/Users.razor | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Application/Features/Identity/DTOs/ApplicationUserDto.cs b/src/Application/Features/Identity/DTOs/ApplicationUserDto.cs index 44d86597..b8d009cd 100644 --- a/src/Application/Features/Identity/DTOs/ApplicationUserDto.cs +++ b/src/Application/Features/Identity/DTOs/ApplicationUserDto.cs @@ -78,6 +78,7 @@ public Mapping() .ForMember(x => x.SuperiorName, s => s.MapFrom(y => y.Superior!.UserName)) .ForMember(x => x.TenantName, s => s.MapFrom(y => y.Tenant!.Name)) .ForMember(x => x.AssignedRoles, s => s.MapFrom(y => y.UserRoles.Select(r => r.Role.Name))) + .ForMember(x => x.PhoneNumber, s => s.MapFrom(x => x.PhoneNumber)) .ReverseMap() .ForMember(x => x.UserName, s => s.MapFrom(y => y.Email)) .ForMember(x => x.Notes, s => s.Ignore()) diff --git a/src/Server.UI/Pages/Identity/Users/Users.razor b/src/Server.UI/Pages/Identity/Users/Users.razor index 2b4a8c14..edc0d51a 100644 --- a/src/Server.UI/Pages/Identity/Users/Users.razor +++ b/src/Server.UI/Pages/Identity/Users/Users.razor @@ -389,8 +389,8 @@ policies ??= new() { { SecurityPolicies.SystemFunctionsWrite, (await AuthService.AuthorizeAsync(state.User, SecurityPolicies.SystemFunctionsWrite)).Succeeded }, - { SecurityPolicies.Import, (await AuthService.AuthorizeAsync(state.User, SecurityPolicies.Import)).Succeeded }, - { SecurityPolicies.Export, (await AuthService.AuthorizeAsync(state.User, SecurityPolicies.Export)).Succeeded } + { SecurityPolicies.Import, false /*(await AuthService.AuthorizeAsync(state.User, SecurityPolicies.Import)).Succeeded */ }, + { SecurityPolicies.Export, false /* (await AuthService.AuthorizeAsync(state.User, SecurityPolicies.Export)).Succeeded */ } }; _canCreate = policies.GetValueOrDefault(SecurityPolicies.SystemFunctionsWrite); @@ -533,6 +533,8 @@ var applicationUser = Mapper.Map(model); applicationUser.EmailConfirmed = true; applicationUser.IsActive = true; + applicationUser.TwoFactorEnabled = true; + applicationUser.PhoneNumberConfirmed = string.IsNullOrWhiteSpace(applicationUser.PhoneNumber) == false; var identityResult = await UserManager.CreateAsync(applicationUser); if (!identityResult.Succeeded) @@ -556,6 +558,8 @@ Mapper.Map(model, user); + user.PhoneNumberConfirmed = string.IsNullOrWhiteSpace(user.PhoneNumber) == false; + var identityResult = await UserManager.UpdateAsync(user); if (identityResult.Succeeded) {