diff --git a/Oqtane.Client/Modules/Admin/Profiles/Edit.razor b/Oqtane.Client/Modules/Admin/Profiles/Edit.razor index 96a65b18..73847560 100644 --- a/Oqtane.Client/Modules/Admin/Profiles/Edit.razor +++ b/Oqtane.Client/Modules/Admin/Profiles/Edit.razor @@ -145,6 +145,7 @@ profile = new Profile(); } + profile.SiteId = PageState.Site.SiteId; profile.Name = _name; profile.Title = _title; profile.Description = _description; diff --git a/Oqtane.Client/Modules/Admin/UserProfile/Index.razor b/Oqtane.Client/Modules/Admin/UserProfile/Index.razor index 0c40987a..9c718ef1 100644 --- a/Oqtane.Client/Modules/Admin/UserProfile/Index.razor +++ b/Oqtane.Client/Modules/Admin/UserProfile/Index.razor @@ -75,10 +75,12 @@ else @if (profiles != null && settings != null) { - - @foreach (Profile profile in profiles) +
+ @foreach (Profile profile in profiles) + { + var p = profile; + if (!p.IsPrivate || UserSecurity.IsAuthorized(PageState.User, Constants.AdminRole)) { - var p = profile; if (p.Category != category) { @@ -90,14 +92,22 @@ else } } -
- + - + @if (p.IsRequired) + { + + } + else + { + + }
+ } + } @@ -241,7 +251,7 @@ else { try { - if (username != string.Empty && email != string.Empty) + if (username != string.Empty && email != string.Empty && ValidateProfiles()) { if (password == confirm) { @@ -261,6 +271,7 @@ else await UserService.UpdateUserAsync(user); await SettingService.UpdateUserSettingsAsync(settings, PageState.User.UserId); await logger.LogInformation("User Profile Saved"); + AddModuleMessage("User Profile Updated Successfully", MessageType.Success); } else { @@ -269,7 +280,7 @@ else } else { - AddModuleMessage("You Must Provide A Username and Email Address", MessageType.Warning); + AddModuleMessage("You Must Provide A Username and Email Address As Well As All Required Profile Information", MessageType.Warning); } } catch (Exception ex) @@ -279,6 +290,26 @@ else } } + private bool ValidateProfiles() + { + bool valid = true; + foreach (Profile profile in profiles) + { + if (string.IsNullOrEmpty(SettingService.GetSetting(settings, profile.Name, string.Empty)) && !string.IsNullOrEmpty(profile.DefaultValue)) + { + settings = SettingService.SetSetting(settings, profile.Name, profile.DefaultValue); + } + if (!profile.IsPrivate || UserSecurity.IsAuthorized(PageState.User, Constants.AdminRole)) + { + if (profile.IsRequired && string.IsNullOrEmpty(SettingService.GetSetting(settings, profile.Name, string.Empty))) + { + valid = false; + } + } + } + return valid; + } + private void Cancel() { NavigationManager.NavigateTo(NavigateUrl(string.Empty)); diff --git a/Oqtane.Client/Modules/Admin/Users/Add.razor b/Oqtane.Client/Modules/Admin/Users/Add.razor index b6aa116a..4b15ce82 100644 --- a/Oqtane.Client/Modules/Admin/Users/Add.razor +++ b/Oqtane.Client/Modules/Admin/Users/Add.razor @@ -71,10 +71,17 @@ } - + - + @if (p.IsRequired) + { + + } + else + { + + } } @@ -112,11 +119,14 @@ } } + private string GetProfileValue(string SettingName, string DefaultValue) + => SettingService.GetSetting(settings, SettingName, DefaultValue); + private async Task SaveUser() { try { - if (username != string.Empty && password != string.Empty && confirm != string.Empty && email != string.Empty) + if (username != string.Empty && password != string.Empty && confirm != string.Empty && email != string.Empty && ValidateProfiles()) { if (password == confirm) { @@ -149,7 +159,7 @@ } else { - AddModuleMessage("You Must Provide A Username, Password, and Email Address", MessageType.Warning); + AddModuleMessage("You Must Provide A Username, Password, Email Address And All Required Profile Information", MessageType.Warning); } } catch (Exception ex) @@ -159,6 +169,23 @@ } } + private bool ValidateProfiles() + { + bool valid = true; + foreach (Profile profile in profiles) + { + if (string.IsNullOrEmpty(SettingService.GetSetting(settings, profile.Name, string.Empty)) && !string.IsNullOrEmpty(profile.DefaultValue)) + { + settings = SettingService.SetSetting(settings, profile.Name, profile.DefaultValue); + } + if (profile.IsRequired && string.IsNullOrEmpty(SettingService.GetSetting(settings, profile.Name, string.Empty))) + { + valid = false; + } + } + return valid; + } + private void ProfileChanged(ChangeEventArgs e, string SettingName) { var value = (string)e.Value; diff --git a/Oqtane.Client/Modules/Admin/Users/Edit.razor b/Oqtane.Client/Modules/Admin/Users/Edit.razor index 95449f2d..87a6a387 100644 --- a/Oqtane.Client/Modules/Admin/Users/Edit.razor +++ b/Oqtane.Client/Modules/Admin/Users/Edit.razor @@ -98,10 +98,17 @@ else } - + - + @if (p.IsRequired) + { + + } + else + { + + } } @@ -180,7 +187,7 @@ else { try { - if (username != string.Empty && email != string.Empty) + if (username != string.Empty && email != string.Empty && ValidateProfiles()) { if (password == confirm) { @@ -213,7 +220,7 @@ else } else { - AddModuleMessage("You Must Provide A Username, Password, and Email Address", MessageType.Warning); + AddModuleMessage("You Must Provide A Username, Password, Email Address, And All Required Profile Information", MessageType.Warning); } } catch (Exception ex) @@ -223,6 +230,23 @@ else } } + private bool ValidateProfiles() + { + bool valid = true; + foreach (Profile profile in profiles) + { + if (string.IsNullOrEmpty(SettingService.GetSetting(settings, profile.Name, string.Empty)) && !string.IsNullOrEmpty(profile.DefaultValue)) + { + settings = SettingService.SetSetting(settings, profile.Name, profile.DefaultValue); + } + if (profile.IsRequired && string.IsNullOrEmpty(SettingService.GetSetting(settings, profile.Name, string.Empty))) + { + valid = false; + } + } + return valid; + } + private void ProfileChanged(ChangeEventArgs e, string SettingName) { var value = (string)e.Value;