Added Cookie Settings option on the account settings

This commit is contained in:
Moritz Deiaco
2024-06-08 12:02:00 +02:00
parent 0fd60b5ccb
commit 87f93b3cab
2 changed files with 38 additions and 4 deletions

View File

@@ -0,0 +1,9 @@
using System.ComponentModel;
namespace Moonlight.Core.Models.Forms;
public class ChangeCookiesForm
{
[Description("This specifies if you would like to personalize your experience with optional cookies.")]
public bool UseOptionalCookies { get; set; } = false;
}

View File

@@ -28,7 +28,7 @@
<div class="row g-5">
<div class="col-md-6 col-12">
<div class="card">
<SmartForm Model="PasswordForm" OnValidSubmit="OnValidSubmit">
<SmartForm Model="PasswordForm" OnValidSubmit="OnValidSubmitPassword">
<div class="card-body">
<div class="row">
<AutoForm Model="PasswordForm" Columns="12" />
@@ -47,6 +47,22 @@
</div>
</div>
</div>
<div class="col-md-6 col-12">
<div class="card h-100">
<SmartForm Model="CookiesForm" OnValidSubmit="OnValidSubmitCookie">
<div class="card-body">
<h3>Cookies</h3>
<div>
<AutoForm Model="CookiesForm"/>
</div>
</div>
<div class="card-footer d-flex justify-content-end">
<button class="btn btn-primary" type="submit">Save changes</button>
</div>
</SmartForm>
</div>
</div>
</div>
</LazyLoader>
@@ -54,12 +70,14 @@
{
private readonly ChangePasswordForm PasswordForm = new();
private Task Load(LazyLoader lazyLoader)
private ChangeCookiesForm CookiesForm = new();
private async Task Load(LazyLoader lazyLoader)
{
return Task.CompletedTask;
CookiesForm.UseOptionalCookies = await IdentityService.HasFlag("CookieConsent");
}
private async Task OnValidSubmit()
private async Task OnValidSubmitPassword()
{
if (PasswordForm.Password != PasswordForm.RepeatedPassword)
throw new DisplayException("The passwords do not match");
@@ -69,4 +87,11 @@
await ToastService.Success("Successfully changed password");
await IdentityService.Authenticate(true);
}
private async Task OnValidSubmitCookie()
{
await IdentityService.SetFlag("CookieConsent", CookiesForm.UseOptionalCookies);
await InvokeAsync(StateHasChanged);
}
}