refactor: consolidate project structure by migrating authentication, identity, and shared UI components while removing legacy Web Client files.
This commit is contained in:
@@ -0,0 +1,112 @@
|
||||
@page "/account/register"
|
||||
@using Microsoft.AspNetCore.Components.Forms
|
||||
@using NexusReader.UI.Shared.Services
|
||||
@inject IIdentityService IdentityService
|
||||
@inject NavigationManager NavigationManager
|
||||
|
||||
<div class="login-container">
|
||||
<div class="login-card">
|
||||
<div class="login-header">
|
||||
<h1>NEXUS<span>AI</span></h1>
|
||||
<p>Join the future of reading.</p>
|
||||
</div>
|
||||
|
||||
<EditForm Model="@_registerModel" OnValidSubmit="HandleRegister">
|
||||
<DataAnnotationsValidator />
|
||||
|
||||
<div class="form-group">
|
||||
<label for="email">Email</label>
|
||||
<InputText id="email" @bind-Value="_registerModel.Email" class="form-control" placeholder="reader@nexus.ai" />
|
||||
<ValidationMessage For="@(() => _registerModel.Email)" />
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="password">Password</label>
|
||||
<InputText id="password" type="password" @bind-Value="_registerModel.Password" class="form-control" placeholder="Min 8 chars, uppercase, digit" />
|
||||
<ValidationMessage For="@(() => _registerModel.Password)" />
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="confirm-password">Confirm Password</label>
|
||||
<InputText id="confirm-password" type="password" @bind-Value="_registerModel.ConfirmPassword" class="form-control" placeholder="••••••••" />
|
||||
<ValidationMessage For="@(() => _registerModel.ConfirmPassword)" />
|
||||
</div>
|
||||
|
||||
@if (!string.IsNullOrEmpty(_errorMessage))
|
||||
{
|
||||
<div class="error-banner">
|
||||
@_errorMessage
|
||||
</div>
|
||||
}
|
||||
|
||||
<button type="submit" class="btn-login" disabled="@_isSubmitting">
|
||||
@if (_isSubmitting)
|
||||
{
|
||||
<span class="spinner"></span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span>Register</span>
|
||||
}
|
||||
</button>
|
||||
</EditForm>
|
||||
|
||||
<div class="login-footer">
|
||||
<p>Already have an account? <a href="/account/login">Login here</a></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
private RegisterModel _registerModel = new();
|
||||
private string? _errorMessage;
|
||||
private bool _isSubmitting;
|
||||
|
||||
private async Task HandleRegister()
|
||||
{
|
||||
if (_registerModel.Password != _registerModel.ConfirmPassword)
|
||||
{
|
||||
_errorMessage = "Passwords do not match.";
|
||||
return;
|
||||
}
|
||||
|
||||
_isSubmitting = true;
|
||||
_errorMessage = null;
|
||||
|
||||
try
|
||||
{
|
||||
var success = await IdentityService.RegisterAsync(_registerModel.Email, _registerModel.Password);
|
||||
if (success)
|
||||
{
|
||||
// Registration successful, redirect to login
|
||||
NavigationManager.NavigateTo("/account/login?registered=true");
|
||||
}
|
||||
else
|
||||
{
|
||||
_errorMessage = "Registration failed. Email might already be in use.";
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
_errorMessage = "An error occurred during registration. Please try again.";
|
||||
}
|
||||
finally
|
||||
{
|
||||
_isSubmitting = false;
|
||||
}
|
||||
}
|
||||
|
||||
public class RegisterModel
|
||||
{
|
||||
[System.ComponentModel.DataAnnotations.Required]
|
||||
[System.ComponentModel.DataAnnotations.EmailAddress]
|
||||
public string Email { get; set; } = string.Empty;
|
||||
|
||||
[System.ComponentModel.DataAnnotations.Required]
|
||||
[System.ComponentModel.DataAnnotations.MinLength(8)]
|
||||
public string Password { get; set; } = string.Empty;
|
||||
|
||||
[System.ComponentModel.DataAnnotations.Required]
|
||||
public string ConfirmPassword { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user