2023-09-18 00:58:40 -05:00
|
|
|
@page "/Profile"
|
2023-11-03 23:33:27 -05:00
|
|
|
@page "/Profile/General"
|
2024-12-31 13:05:06 -06:00
|
|
|
@using Microsoft.AspNetCore.Components.Authorization
|
2025-02-01 02:21:34 -06:00
|
|
|
@inject UserService UserService
|
2023-09-18 00:58:40 -05:00
|
|
|
@inject IMessageService MessageService
|
|
|
|
|
@inject AuthenticationStateProvider AuthenticationStateProvider
|
|
|
|
|
@inject NavigationManager NavigationManager
|
2024-07-07 16:33:46 -05:00
|
|
|
@inject ILogger<Index> Logger
|
2023-10-16 20:17:59 -05:00
|
|
|
@attribute [Authorize]
|
2023-09-18 00:58:40 -05:00
|
|
|
|
2024-08-21 19:40:27 -05:00
|
|
|
<PageHeader Title="Profile">
|
|
|
|
|
<PageHeaderExtra>
|
|
|
|
|
<Button Type="@ButtonType.Primary" Disabled="!Form.IsModified" OnClick="Save">Save</Button>
|
|
|
|
|
</PageHeaderExtra>
|
|
|
|
|
</PageHeader>
|
2023-09-18 00:58:40 -05:00
|
|
|
|
|
|
|
|
<div style="padding: 0 24px;">
|
2024-08-21 19:40:27 -05:00
|
|
|
<Form @ref="Form" Model="User" Layout="@FormLayout.Vertical" ValidateOnChange="true">
|
2024-01-15 02:20:35 -06:00
|
|
|
<FormItem Label="Avatar">
|
2024-08-21 19:40:27 -05:00
|
|
|
<AvatarUploader UserId="User.Id" />
|
2024-01-15 02:20:35 -06:00
|
|
|
</FormItem>
|
|
|
|
|
|
|
|
|
|
<FormItem Label="Username" Help="Username changes require a relog">
|
2023-09-18 00:58:40 -05:00
|
|
|
<Input @bind-Value="context.UserName" />
|
|
|
|
|
</FormItem>
|
|
|
|
|
|
2023-10-16 20:48:12 -05:00
|
|
|
<FormItem Label="Alias">
|
|
|
|
|
<Input @bind-Value="context.Alias" />
|
|
|
|
|
</FormItem>
|
|
|
|
|
|
2024-01-15 02:20:35 -06:00
|
|
|
<FormItem Label="Email Address" Help="Email changes require a relog">
|
2023-09-18 00:58:40 -05:00
|
|
|
<Input @bind-Value="context.Email" />
|
|
|
|
|
</FormItem>
|
|
|
|
|
</Form>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
@code {
|
2025-02-01 02:21:34 -06:00
|
|
|
User User = new();
|
2023-09-18 00:58:40 -05:00
|
|
|
Form<User> Form;
|
|
|
|
|
|
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
|
|
|
{
|
2024-10-21 20:14:55 -05:00
|
|
|
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
|
2025-02-01 02:21:34 -06:00
|
|
|
|
|
|
|
|
if (authState.User.Identity.IsAuthenticated)
|
|
|
|
|
User = await UserService.GetAsync(authState.User.Identity.Name);
|
2023-09-18 00:58:40 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task Save()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (Form.IsModified)
|
|
|
|
|
{
|
2025-02-01 02:21:34 -06:00
|
|
|
await UserService.UpdateAsync(User);
|
2023-09-18 00:58:40 -05:00
|
|
|
|
|
|
|
|
MessageService.Success("Profile updated!");
|
|
|
|
|
|
2025-01-06 02:59:32 -06:00
|
|
|
NavigationManager.NavigateTo("/Logout?force=true", true);
|
2023-09-18 00:58:40 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2024-07-07 16:33:46 -05:00
|
|
|
MessageService.Error("An unknown error occurred.");
|
|
|
|
|
Logger.LogError(ex, "An unknown error occurred.");
|
2023-09-18 00:58:40 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|