From dda6071bbc427bb335322e8c1f02a777dff78697 Mon Sep 17 00:00:00 2001 From: sbwalker Date: Mon, 23 Oct 2023 12:16:52 -0400 Subject: [PATCH] complete fix for #3427 in User Profile component --- .../Modules/Admin/UserProfile/Index.razor | 106 +++++++++--------- 1 file changed, 51 insertions(+), 55 deletions(-) diff --git a/Oqtane.Client/Modules/Admin/UserProfile/Index.razor b/Oqtane.Client/Modules/Admin/UserProfile/Index.razor index dd1b4065..42d7da8f 100644 --- a/Oqtane.Client/Modules/Admin/UserProfile/Index.razor +++ b/Oqtane.Client/Modules/Admin/UserProfile/Index.razor @@ -11,18 +11,18 @@ @inject IStringLocalizer Localizer @inject IStringLocalizer SharedLocalizer -@if (PageState.User != null && photo != null) +@if (_initialized) { - @displayname -} -else -{ -
-} - - - @if (profiles != null && settings != null) - { + @if (PageState.User != null && photo != null) + { + @displayname + } + else + { +
+ } + +
@@ -33,34 +33,34 @@ else
-
+
- + -
+
- + -
+
- @if (allowtwofactor) - { -
- -
- -
-
- } + @if (allowtwofactor) + { +
+ +
+ +
+
+ }
@@ -83,11 +83,8 @@ else
- } - - - @if (profiles != null && settings != null) - { + +
@foreach (Profile profile in profiles) @@ -104,8 +101,8 @@ else }
-
- @if (!string.IsNullOrEmpty(p.Options)) +
+ @if (!string.IsNullOrEmpty(p.Options)) {
- -
-
@if (filter == "to") { @if (notifications.Any()) @@ -294,12 +288,14 @@ else
} } - } - - -

+ + +
+
+} @code { + private bool _initialized = false; private string _passwordrequirements; private string username = string.Empty; private string _password = string.Empty; @@ -325,15 +321,14 @@ else public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.View; - protected override async Task OnParametersSetAsync() + protected override async Task OnInitializedAsync() { try { _passwordrequirements = await UserService.GetPasswordRequirementsAsync(PageState.Site.SiteId); - _togglepassword = SharedLocalizer["ShowPassword"]; - allowtwofactor = (SettingService.GetSetting(PageState.Site.Settings, "LoginOptions:TwoFactor", "false") == "true"); + profiles = await ProfileService.GetProfilesAsync(ModuleState.SiteId); if (PageState.User != null) { @@ -360,10 +355,11 @@ else photo = null; } - profiles = await ProfileService.GetProfilesAsync(ModuleState.SiteId); settings = await SettingService.GetUserSettingsAsync(PageState.User.UserId); await LoadNotificationsAsync(); + + _initialized = true; } else { @@ -463,13 +459,14 @@ else { foreach (Profile profile in profiles) { - if (string.IsNullOrEmpty(SettingService.GetSetting(settings, profile.Name, string.Empty)) && !string.IsNullOrEmpty(profile.DefaultValue)) + var value = GetProfileValue(profile.Name, string.Empty); + if (string.IsNullOrEmpty(value) && !string.IsNullOrEmpty(profile.DefaultValue)) { settings = SettingService.SetSetting(settings, profile.Name, profile.DefaultValue); } if (!profile.IsPrivate || UserSecurity.IsAuthorized(PageState.User, RoleNames.Admin)) { - if (profile.IsRequired && string.IsNullOrEmpty(SettingService.GetSetting(settings, profile.Name, string.Empty))) + if (profile.IsRequired && string.IsNullOrEmpty(value)) { AddModuleMessage(string.Format(SharedLocalizer["ProfileRequired"], profile.Title), MessageType.Warning); return false; @@ -477,7 +474,7 @@ else if (!string.IsNullOrEmpty(profile.Validation)) { Regex regex = new Regex(profile.Validation); - bool valid = regex.Match(SettingService.GetSetting(settings, profile.Name, string.Empty)).Success; + bool valid = regex.Match(value).Success; if (!valid) { AddModuleMessage(string.Format(SharedLocalizer["ProfileInvalid"], profile.Title), MessageType.Warning); @@ -528,7 +525,6 @@ else private async void FilterChanged(ChangeEventArgs e) { filter = (string)e.Value; - await LoadNotificationsAsync(); StateHasChanged(); }