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
|
|
|
|
2026-07-19 15:28:38 +00:00
|
|
|
<div class="auth-page">
|
|
|
|
|
<div class="auth-card">
|
|
|
|
|
<div class="auth-header">
|
|
|
|
|
<div class="auth-icon">
|
|
|
|
|
<MudIcon Icon="@Icons.Material.Filled.Shield" Size="Size.Large" />
|
|
|
|
|
</div>
|
|
|
|
|
<h1>Créer un compte</h1>
|
|
|
|
|
<p>Rejoignez la plateforme Heimdall</p>
|
|
|
|
|
</div>
|
2026-07-16 21:19:16 +00:00
|
|
|
|
2026-07-19 15:28:38 +00:00
|
|
|
<div class="auth-form">
|
|
|
|
|
<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-4"
|
|
|
|
|
Required="true"
|
|
|
|
|
Immediate="true"
|
|
|
|
|
HelperText="Minimum 12 caractères"
|
|
|
|
|
Autocomplete="new-password" />
|
2026-07-16 21:19:16 +00:00
|
|
|
|
2026-07-19 15:28:38 +00:00
|
|
|
<div class="auth-error">
|
|
|
|
|
@if (!string.IsNullOrEmpty(_errorMessage))
|
|
|
|
|
{
|
|
|
|
|
<MudAlert Severity="Severity.Error">@_errorMessage</MudAlert>
|
|
|
|
|
}
|
|
|
|
|
</div>
|
2026-07-16 21:19:16 +00:00
|
|
|
|
2026-07-19 15:28:38 +00:00
|
|
|
<MudButton Variant="Variant.Filled"
|
|
|
|
|
Color="Color.Primary"
|
|
|
|
|
FullWidth="true"
|
|
|
|
|
ButtonType="ButtonType.Submit"
|
|
|
|
|
Disabled="@_loading"
|
|
|
|
|
Class="mud-button-submit">
|
|
|
|
|
@if (_loading)
|
|
|
|
|
{
|
|
|
|
|
<MudProgressCircular Size="Size.Small" Class="mr-2" Color="Color.Inherit" />
|
|
|
|
|
}
|
|
|
|
|
@(_loading ? "Création en cours…" : "S'inscrire")
|
|
|
|
|
</MudButton>
|
|
|
|
|
</form>
|
|
|
|
|
</div>
|
2026-07-16 21:19:16 +00:00
|
|
|
|
2026-07-19 15:28:38 +00:00
|
|
|
<div class="auth-footer">
|
|
|
|
|
<p>
|
|
|
|
|
Déjà un compte ?
|
|
|
|
|
<a href="/login">Se connecter</a>
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-07-16 21:19:16 +00:00
|
|
|
|
|
|
|
|
@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; }
|
|
|
|
|
}
|
|
|
|
|
}
|