Refactoring, database structure changed

This commit is contained in:
2025-03-03 00:56:32 +01:00
Unverified
parent d3805ef3db
commit c603c41c0b
913 changed files with 21764 additions and 32775 deletions

View File

@@ -0,0 +1,34 @@
@inherits Component
<EditForm Model="@(_model)">
<AntiforgeryToken/>
<div class="container-grid">
<div class="row form-group mb-1">
<label for="username" class="col-5 col-form-label">Username or email:</label>
<div class="col">
<InputText id="username" class="form-control" @bind-Value="_model.UsernameOrEmail"/>
</div>
</div>
<div class="row form-group my-1">
<label for="password" class="col-5 col-form-label">Password:</label>
<div class="col">
<InputText id="password" type="password" class="form-control" @bind-Value="_model.Password"/>
</div>
</div>
<div class="row form-group">
<div class="col align-self-center">
<div class="form-check">
<InputCheckbox class="form-check-input" @bind-Value="_model.RememberMe"/>
<label class="form-check-label">Remember me</label>
</div>
</div>
<div class="col-auto">
<div class="d-flex justify-content-stretch">
<button type="submit" class="btn btn-secondary" @onclick="@(Login)">Sign in</button>
</div>
</div>
</div>
</div>
</EditForm>

View File

@@ -0,0 +1,71 @@
using System.Net;
using Blazorise.Snackbar;
using Microsoft.AspNetCore.Components;
using Refit;
using WatchIt.DTO.Models.Controllers.Authentication;
using WatchIt.Website.Components.Layout;
using WatchIt.Website.Services.Authentication;
namespace WatchIt.Website.Components.Subcomponents.Pages.AuthPage;
public partial class LoginForm : Component
{
#region SERVICES
[Inject] public NavigationManager NavigationManager { get; set; } = null!;
[Inject] public IAuthenticationService AuthenticationService { get; set; } = null!;
#endregion
#region PARAMETERS
[Parameter] public required string RedirectTo { get; set; }
#endregion
#region FIELDS
private AuthenticationRequest _model = new AuthenticationRequest();
#endregion
#region PRIVATE METHODS
private async Task Login()
{
IApiResponse response = await AuthenticationService.Login(_model);
if (response.IsSuccessful)
{
NavigationManager.NavigateTo(RedirectTo, true);
}
else
{
string content = "Unknown error";
switch (response.StatusCode)
{
case HttpStatusCode.Unauthorized:
content = "Wrong username or password";
break;
case HttpStatusCode.BadRequest:
if (response.Error is ValidationApiException ex)
{
string? exContent = ex.Content?.Errors.SelectMany(x => x.Value).FirstOrDefault();
if (exContent is not null)
{
content = exContent;
}
}
break;
}
await Base.SnackbarStack.PushAsync(content, SnackbarColor.Danger);
}
}
#endregion
}

View File

@@ -0,0 +1,40 @@
@inherits Component
<EditForm Model="@(_model)">
<AntiforgeryToken/>
<div class="container-grid">
<div class="row form-group mb-1">
<label for="username" class="col-5 col-form-label">Username:</label>
<div class="col">
<InputText id="username" class="form-control" @bind-Value="_model.Username"/>
</div>
</div>
<div class="row form-group my-1">
<label for="email" class="col-5 col-form-label">Email:</label>
<div class="col">
<InputText id="email" class="form-control" @bind-Value="_model.Email"/>
</div>
</div>
<div class="row form-group my-1">
<label for="password" class="col-5 col-form-label">Password:</label>
<div class="col">
<InputText id="password" class="form-control" type="password" @bind-Value="_model.Password"/>
</div>
</div>
<div class="row form-group my-1">
<label for="confpassword" class="col-5 col-form-label">Confirm password:</label>
<div class="col">
<InputText id="confpassword" class="form-control" type="password" @bind-Value="_model.PasswordConfirmation"/>
</div>
</div>
<div class="row">
<div class="col">
<div class="d-flex justify-content-end">
<button type="submit" class="btn btn-secondary" @onclick="@(Register)">Sign up</button>
</div>
</div>
</div>
</div>
</EditForm>

View File

@@ -0,0 +1,63 @@
using System.Net;
using Blazorise.Snackbar;
using Microsoft.AspNetCore.Components;
using Refit;
using WatchIt.DTO.Models.Controllers.Accounts.Account;
using WatchIt.Website.Clients;
using WatchIt.Website.Components.Layout;
namespace WatchIt.Website.Components.Subcomponents.Pages.AuthPage;
public partial class RegisterForm : Component
{
#region SERVICES
[Inject] public IAccountsClient AccountsClient { get; set; } = null!;
#endregion
#region PARAMETERS
[Parameter] public Action? RegisteredSuccessfully { get; set; }
#endregion
#region FIELDS
private AccountRequest _model = new AccountRequest();
#endregion
#region PRIVATE METHODS
private async Task Register()
{
IApiResponse<AccountResponse> response = await AccountsClient.PostAccount(_model);
if (response.IsSuccessful)
{
RegisteredSuccessfully?.Invoke();
await Base.SnackbarStack.PushAsync("You have been registered successfully. You can log in now.", SnackbarColor.Success);
}
else
{
string content = "Unknown error";
if (response.Error is ValidationApiException ex)
{
string? exContent = ex.Content?.Errors.SelectMany(x => x.Value).FirstOrDefault();
if (exContent is not null)
{
content = exContent;
}
}
await Base.SnackbarStack.PushAsync(content, SnackbarColor.Danger);
}
}
#endregion
}