Fix #676 - fix creation of new profile fields, add support for required and private profile fields, integrate field level help for consistency
This commit is contained in:
		| @ -145,6 +145,7 @@ | ||||
|                 profile = new Profile(); | ||||
|             } | ||||
|  | ||||
|             profile.SiteId = PageState.Site.SiteId; | ||||
|             profile.Name = _name; | ||||
|             profile.Title = _title; | ||||
|             profile.Description = _description; | ||||
|  | ||||
| @ -75,10 +75,12 @@ else | ||||
|     <TabPanel Name="Profile"> | ||||
|         @if (profiles != null && settings != null) | ||||
|         { | ||||
|             <table class="table table-borderless"> | ||||
|                 @foreach (Profile profile in profiles) | ||||
|         <table class="table table-borderless"> | ||||
|             @foreach (Profile profile in profiles) | ||||
|             { | ||||
|                 var p = profile; | ||||
|                 if (!p.IsPrivate || UserSecurity.IsAuthorized(PageState.User, Constants.AdminRole)) | ||||
|                 { | ||||
|                     var p = profile; | ||||
|                     if (p.Category != category) | ||||
|                     { | ||||
|                         <tr> | ||||
| @ -90,14 +92,22 @@ else | ||||
|                     } | ||||
|                     <tr> | ||||
|                         <td> | ||||
|                             <label for="@p.Name" class="control-label">@p.Title: </label> | ||||
|                             <Label For="@p.Name" HelpText="@p.Description">@p.Title</Label> | ||||
|                         </td> | ||||
|                         <td> | ||||
|                             <input class="form-control" maxlength="@p.MaxLength" value="@GetProfileValue(p.Name, p.DefaultValue)" placeholder="@p.Description" @onchange="@(e => ProfileChanged(e, p.Name))" /> | ||||
|                             @if (p.IsRequired) | ||||
|                             { | ||||
|                                 <input id="@p.Name" class="form-control" maxlength="@p.MaxLength" value="@GetProfileValue(p.Name, p.DefaultValue)" required @onchange="@(e => ProfileChanged(e, p.Name))" /> | ||||
|                             } | ||||
|                             else | ||||
|                             { | ||||
|                                 <input id="@p.Name" class="form-control" maxlength="@p.MaxLength" value="@GetProfileValue(p.Name, p.DefaultValue)" @onchange="@(e => ProfileChanged(e, p.Name))" /> | ||||
|                             } | ||||
|                         </td> | ||||
|                     </tr> | ||||
|                 } | ||||
|             </table> | ||||
|             } | ||||
|         </table> | ||||
|             <button type="button" class="btn btn-primary" @onclick="Save">Save</button> | ||||
|             <button type="button" class="btn btn-secondary" @onclick="Cancel">Cancel</button> | ||||
|         } | ||||
| @ -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)); | ||||
|  | ||||
| @ -71,10 +71,17 @@ | ||||
|                 } | ||||
|                 <tr> | ||||
|                     <td> | ||||
|                         <label for="@p.Name" class="control-label">@p.Title: </label> | ||||
|                         <Label For="@p.Name" HelpText="@p.Description">@p.Title</Label> | ||||
|                     </td> | ||||
|                     <td> | ||||
|                         <input class="form-control" maxlength="@p.MaxLength" placeholder="@p.Description" @onchange="@(e => ProfileChanged(e, p.Name))" /> | ||||
|                         @if (p.IsRequired) | ||||
|                         { | ||||
|                             <input id="@p.Name" class="form-control" maxlength="@p.MaxLength" value="@GetProfileValue(p.Name, p.DefaultValue)" required @onchange="@(e => ProfileChanged(e, p.Name))" /> | ||||
|                         } | ||||
|                         else | ||||
|                         { | ||||
|                             <input id="@p.Name" class="form-control" maxlength="@p.MaxLength" value="@GetProfileValue(p.Name, p.DefaultValue)" @onchange="@(e => ProfileChanged(e, p.Name))" /> | ||||
|                         } | ||||
|                     </td> | ||||
|                 </tr> | ||||
|             } | ||||
| @ -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; | ||||
|  | ||||
| @ -98,10 +98,17 @@ else | ||||
|                 } | ||||
|                 <tr> | ||||
|                     <td> | ||||
|                         <label for="@p.Name" class="control-label">@p.Title: </label> | ||||
|                         <Label For="@p.Name" HelpText="@p.Description">@p.Title</Label> | ||||
|                     </td> | ||||
|                     <td> | ||||
|                         <input class="form-control" maxlength="@p.MaxLength" value="@GetProfileValue(p.Name, p.DefaultValue)" placeholder="@p.Description" @onchange="@(e => ProfileChanged(e, p.Name))" /> | ||||
|                         @if (p.IsRequired) | ||||
|                         { | ||||
|                             <input id="@p.Name" class="form-control" maxlength="@p.MaxLength" value="@GetProfileValue(p.Name, p.DefaultValue)" required @onchange="@(e => ProfileChanged(e, p.Name))" /> | ||||
|                         } | ||||
|                         else | ||||
|                         { | ||||
|                             <input id="@p.Name" class="form-control" maxlength="@p.MaxLength" value="@GetProfileValue(p.Name, p.DefaultValue)" @onchange="@(e => ProfileChanged(e, p.Name))" /> | ||||
|                         } | ||||
|                     </td> | ||||
|                 </tr> | ||||
|             } | ||||
| @ -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; | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Shaun Walker
					Shaun Walker