125 lines
3.4 KiB
Text
125 lines
3.4 KiB
Text
@page "/dashboard"
|
|
@using System.ComponentModel.DataAnnotations;
|
|
@using System.Net
|
|
@inject HttpClient req
|
|
@inject UserManager usr
|
|
|
|
<PageTitle>Dashboard</PageTitle>
|
|
|
|
<h1>Your profile</h1>
|
|
|
|
@if (!string.IsNullOrWhiteSpace(_err))
|
|
{
|
|
<p class="text-danger">@_err</p>
|
|
}
|
|
|
|
<div class="profile">
|
|
<h2>Profile settings</h2>
|
|
<EditForm class="form" Model="@_pdr" OnValidSubmit="@UpdateProfile">
|
|
<div class="form-group">
|
|
<label for="cc">Country</label>
|
|
<InputText @bind-Value="_pdr.CC" id="cc" />
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="city">City</label>
|
|
<InputText @bind-Value="_pdr.City" id="city" />
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="bio">Bio</label>
|
|
<InputText @bind-Value="_pdr.Bio" id="bio" />
|
|
</div>
|
|
<button type="submit">Update profile</button>
|
|
</EditForm>
|
|
</div>
|
|
|
|
<div class="security">
|
|
<h2>Security settings</h2>
|
|
|
|
<EditForm class="form" Model="@_pwc" OnValidSubmit="@ChangePassword">
|
|
<div class="form-group">
|
|
<label for="oldpw">Old password</label>
|
|
<InputText @bind-Value="_pwc.PasswordOld" id="oldpw" />
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="npw">New password</label>
|
|
<InputText @bind-Value="_pwc.PasswordNew" id="npw" />
|
|
</div>
|
|
<button type="submit">Change password</button>
|
|
</EditForm>
|
|
|
|
<EditForm class="form" Model="@_emc" OnValidSubmit="@ChangeEmail">
|
|
<div class="form-group">
|
|
<label for="oldpw">Email</label>
|
|
<InputText @bind-Value="_emc.Email" id="eml" />
|
|
</div>
|
|
<button type="submit">Change email</button>
|
|
</EditForm>
|
|
</div>
|
|
|
|
@code {
|
|
private string _err = "";
|
|
private PasswordChangeRequest _pwc = new();
|
|
private EmailChangeRequest _emc = new();
|
|
private ProfileRequest _pdr = new();
|
|
|
|
public record PasswordChangeRequest
|
|
{
|
|
[Required]
|
|
public string PasswordOld { get; set; } = default!;
|
|
[Required]
|
|
public string PasswordNew { get; set; } = default!;
|
|
};
|
|
|
|
public record EmailChangeRequest
|
|
{
|
|
[Required]
|
|
[EmailAddress]
|
|
public string Email { get; set; } = default!;
|
|
}
|
|
|
|
public record ProfileRequest
|
|
{
|
|
public string? Bio { get; set; }
|
|
public string? CC { get; set; }
|
|
public string? City { get; set; }
|
|
public ICollection<string> Interests { get; set; } = new List<string>();
|
|
}
|
|
|
|
protected async override Task OnInitializedAsync()
|
|
{
|
|
|
|
}
|
|
|
|
private async Task ChangePassword()
|
|
{
|
|
var resp = await req.PostAsJsonAsync("/api/auth/changepass", _pwc);
|
|
if (!resp.IsSuccessStatusCode)
|
|
{
|
|
_err = await resp.Content.ReadAsStringAsync();
|
|
}
|
|
this._pwc = new();
|
|
this.StateHasChanged();
|
|
}
|
|
|
|
private async Task ChangeEmail()
|
|
{
|
|
var resp = await req.PostAsJsonAsync("/api/auth/changemail", _emc);
|
|
if (!resp.IsSuccessStatusCode)
|
|
{
|
|
_err = await resp.Content.ReadAsStringAsync();
|
|
}
|
|
this._emc = new();
|
|
this.StateHasChanged();
|
|
}
|
|
|
|
private async Task UpdateProfile()
|
|
{
|
|
var resp = await req.PostAsJsonAsync("/api/auth/profile/update", _pdr);
|
|
if (!resp.IsSuccessStatusCode)
|
|
{
|
|
_err = await resp.Content.ReadAsStringAsync();
|
|
}
|
|
this._pdr = new();
|
|
this.StateHasChanged();
|
|
}
|
|
}
|