@namespace Oqtane.Modules.Admin.UserProfile @inherits ModuleBase @inject NavigationManager NavigationManager @inject IUserService UserService @inject IProfileService ProfileService @inject ISettingService SettingService @inject INotificationService NotificationService @inject IFileService FileService @inject IFolderService FolderService @inject IStringLocalizer Localizer @inject IStringLocalizer SharedLocalizer @if (PageState.User != null && photo != null) { @displayname } else {
} @if (profiles != null && settings != null) {

}
@if (profiles != null && settings != null) {
@foreach (Profile profile in profiles) { var p = profile; if (!p.IsPrivate || UserSecurity.IsAuthorized(PageState.User, RoleNames.Admin)) { if (p.Category != category) {
@p.Category
category = p.Category; }
@if (!string.IsNullOrEmpty(p.Options)) { } else { @if (p.IsRequired) { } else { } }
} }
}
@if (notifications != null) {

@if (filter == "to") {
    @Localizer["From"] @Localizer["Subject"] @Localizer["Received"]
@context.FromDisplayName @context.Subject @context.CreatedOn @{ string input = "___"; if (context.Body.Contains(input)) { context.Body = context.Body.Split(input)[0]; context.Body = context.Body.Replace("\n", ""); context.Body = context.Body.Replace("\r", ""); } } @(context.Body.Length > 100 ? (context.Body.Substring(0, 97) + "...") : context.Body)
} else {
    @Localizer["To"] @Localizer["Subject"] @Localizer["Sent"]
@context.ToDisplayName @context.Subject @context.CreatedOn @{ string input = "___"; if (context.Body.Contains(input)) { context.Body = context.Body.Split(input)[0]; context.Body = context.Body.Replace("\n", ""); context.Body = context.Body.Replace("\r", ""); } } @(context.Body.Length > 100 ? (context.Body.Substring(0, 97) + "...") : context.Body)
}

}
@code { private string username = string.Empty; private string password = string.Empty; private string confirm = string.Empty; private string email = string.Empty; private string displayname = string.Empty; private FileManager filemanager; private int folderid = -1; private int photofileid = -1; private File photo = null; private List profiles; private Dictionary settings; private string category = string.Empty; private string filter = "to"; private List notifications; public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.View; protected override async Task OnParametersSetAsync() { try { if (PageState.User != null) { username = PageState.User.Username; email = PageState.User.Email; displayname = PageState.User.DisplayName; // get user folder var folder = await FolderService.GetFolderAsync(ModuleState.SiteId, PageState.User.FolderPath); if (folder != null) { folderid = folder.FolderId; } if (PageState.User.PhotoFileId != null) { photofileid = PageState.User.PhotoFileId.Value; photo = await FileService.GetFileAsync(photofileid); } else { photofileid = -1; photo = null; } profiles = await ProfileService.GetProfilesAsync(ModuleState.SiteId); settings = await SettingService.GetUserSettingsAsync(PageState.User.UserId); await LoadNotificationsAsync(); } else { AddModuleMessage(Localizer["Message.User.NoLogIn"], MessageType.Warning); } } catch (Exception ex) { await logger.LogError(ex, "Error Loading User Profile {Error}", ex.Message); AddModuleMessage(Localizer["Error.Profile.Load"], MessageType.Error); } } private async Task LoadNotificationsAsync() { notifications = await NotificationService.GetNotificationsAsync(PageState.Site.SiteId, filter, PageState.User.UserId); notifications = notifications.Where(item => item.DeletedBy != PageState.User.Username).ToList(); } private string GetProfileValue(string SettingName, string DefaultValue) => SettingService.GetSetting(settings, SettingName, DefaultValue); private async Task Save() { try { if (username != string.Empty && email != string.Empty && ValidateProfiles()) { if (password == confirm) { var user = PageState.User; user.Username = username; user.Password = password; user.Email = email; user.DisplayName = (displayname == string.Empty ? username : displayname); user.PhotoFileId = filemanager.GetFileId(); if (user.PhotoFileId == -1) { user.PhotoFileId = null; } await UserService.UpdateUserAsync(user); await SettingService.UpdateUserSettingsAsync(settings, PageState.User.UserId); await logger.LogInformation("User Profile Saved"); NavigationManager.NavigateTo(NavigateUrl()); } else { AddModuleMessage(Localizer["Message.Password.Invalid"], MessageType.Warning); } } else { AddModuleMessage(Localizer["Message.Required.ProfileInfo"], MessageType.Warning); } } catch (Exception ex) { await logger.LogError(ex, "Error Saving User Profile {Error}", ex.Message); AddModuleMessage(Localizer["Error.Profile.Save"], MessageType.Error); } } 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, RoleNames.Admin)) { if (profile.IsRequired && string.IsNullOrEmpty(SettingService.GetSetting(settings, profile.Name, string.Empty))) { valid = false; } } } return valid; } private void Cancel() { NavigationManager.NavigateTo(NavigateUrl(string.Empty)); } private void ProfileChanged(ChangeEventArgs e, string SettingName) { var value = (string)e.Value; settings = SettingService.SetSetting(settings, SettingName, value); } private async Task Delete(Notification Notification) { try { if (!Notification.IsDeleted) { Notification.IsDeleted = true; await NotificationService.UpdateNotificationAsync(Notification); } else { await NotificationService.DeleteNotificationAsync(Notification.NotificationId); } await logger.LogInformation("Notification Deleted {Notification}", Notification); await LoadNotificationsAsync(); StateHasChanged(); } catch (Exception ex) { await logger.LogError(ex, "Error Deleting Notification {Notification} {Error}", Notification, ex.Message); AddModuleMessage(ex.Message, MessageType.Error); } } private async void FilterChanged(ChangeEventArgs e) { filter = (string)e.Value; await LoadNotificationsAsync(); StateHasChanged(); } }