2026-07-16 21:19:16 +00:00
|
|
|
@page "/register"
|
|
|
|
|
@layout MudBlazorLayout
|
|
|
|
|
@inject HeimdallApiClient Api
|
|
|
|
|
@inject AuthState Auth
|
|
|
|
|
@inject NavigationManager Navigation
|
|
|
|
|
@inject ISnackbar Snackbar
|
2026-07-17 07:05:07 +00:00
|
|
|
@inject HeimdallAuthStateProvider AuthStateProvider
|
2026-07-18 20:59:38 +00:00
|
|
|
@inject IJSRuntime JsRuntime
|
2026-07-16 21:19:16 +00:00
|
|
|
|
|
|
|
|
<MudContainer MaxWidth="MaxWidth.ExtraSmall" Class="mt-16">
|
|
|
|
|
<MudPaper Elevation="5" Class="pa-8" Style="border-radius: 16px;">
|
|
|
|
|
<MudText Typo="Typo.h5" Align="Align.Center" Class="mb-6">Créer un compte</MudText>
|
|
|
|
|
|
2026-07-19 06:28:13 +00:00
|
|
|
<form @onsubmit="RegisterAsync" method="post">
|
|
|
|
|
<MudTextField @bind-Value="_displayName" Label="Nom d'affichage" Variant="Variant.Outlined"
|
|
|
|
|
Class="mb-4" Required="true" Immediate="true"
|
|
|
|
|
Autocomplete="name" />
|
|
|
|
|
<MudTextField @bind-Value="_email" Label="Email" Variant="Variant.Outlined"
|
|
|
|
|
Class="mb-4" Required="true" Immediate="true"
|
|
|
|
|
Autocomplete="email" />
|
|
|
|
|
<MudTextField @bind-Value="_password" Label="Mot de passe" Variant="Variant.Outlined"
|
|
|
|
|
InputType="InputType.Password" Class="mb-6" Required="true" Immediate="true"
|
|
|
|
|
HelperText="Minimum 12 caractères"
|
|
|
|
|
Autocomplete="new-password" />
|
2026-07-16 21:19:16 +00:00
|
|
|
|
2026-07-19 06:28:13 +00:00
|
|
|
@if (!string.IsNullOrEmpty(_errorMessage))
|
|
|
|
|
{
|
|
|
|
|
<MudAlert Severity="Severity.Error" Class="mb-4">@_errorMessage</MudAlert>
|
|
|
|
|
}
|
2026-07-16 21:19:16 +00:00
|
|
|
|
2026-07-19 06:28:13 +00:00
|
|
|
<MudButton Variant="Variant.Filled" Color="Color.Primary" FullWidth="true"
|
|
|
|
|
ButtonType="ButtonType.Submit" Disabled="@_loading" Class="mb-4">
|
|
|
|
|
@if (_loading) { <MudProgressCircular Size="Size.Small" Class="mr-2" /> }
|
|
|
|
|
S'inscrire
|
|
|
|
|
</MudButton>
|
|
|
|
|
</form>
|
2026-07-16 21:19:16 +00:00
|
|
|
|
|
|
|
|
<MudText Typo="Typo.body2" Align="Align.Center">
|
|
|
|
|
Déjà un compte ?
|
|
|
|
|
<MudLink Href="/login">Se connecter</MudLink>
|
|
|
|
|
</MudText>
|
|
|
|
|
</MudPaper>
|
|
|
|
|
</MudContainer>
|
|
|
|
|
|
|
|
|
|
@code {
|
|
|
|
|
private string _email = "";
|
|
|
|
|
private string _password = "";
|
|
|
|
|
private string _displayName = "";
|
|
|
|
|
private bool _loading;
|
|
|
|
|
private string _errorMessage = "";
|
|
|
|
|
|
|
|
|
|
private async Task RegisterAsync()
|
|
|
|
|
{
|
|
|
|
|
_loading = true;
|
|
|
|
|
_errorMessage = "";
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var result = await Api.RegisterAsync(_email, _password, _displayName);
|
|
|
|
|
if (result is null)
|
|
|
|
|
{
|
|
|
|
|
_errorMessage = "Erreur lors de l'inscription";
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-07-18 20:59:38 +00:00
|
|
|
|
|
|
|
|
// Update Blazor-level auth state
|
2026-07-18 18:58:20 +00:00
|
|
|
await AuthStateProvider.NotifyLoginAsync(result);
|
2026-07-18 20:59:38 +00:00
|
|
|
|
|
|
|
|
// Create middleware-level auth cookie
|
|
|
|
|
if (result.User is not null)
|
|
|
|
|
{
|
|
|
|
|
await JsRuntime.InvokeVoidAsync("heimdallAuth.signIn", new
|
|
|
|
|
{
|
|
|
|
|
id = result.User.Id.ToString(),
|
|
|
|
|
email = result.User.Email,
|
|
|
|
|
displayName = result.User.DisplayName,
|
|
|
|
|
roles = result.User.Roles
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-16 21:19:16 +00:00
|
|
|
Snackbar.Add("Compte créé avec succès", Severity.Success);
|
|
|
|
|
Navigation.NavigateTo("/dashboard");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_errorMessage = $"Erreur : {ex.Message}";
|
|
|
|
|
}
|
|
|
|
|
finally { _loading = false; }
|
|
|
|
|
}
|
|
|
|
|
}
|