119 lines
4.4 KiB
Plaintext
119 lines
4.4 KiB
Plaintext
@page "/account/login"
|
|
@layout AuthLayout
|
|
@attribute [AllowAnonymous]
|
|
@using Microsoft.AspNetCore.Components.Forms
|
|
@using NexusReader.UI.Shared.Services
|
|
@using NexusReader.UI.Shared.Components.Atoms
|
|
@inject IIdentityService IdentityService
|
|
@inject NavigationManager NavigationManager
|
|
|
|
<div class="login-page-container">
|
|
<div class="mesh-bg"></div>
|
|
|
|
<div class="auth-card">
|
|
<div class="auth-header">
|
|
<div class="logo-box">
|
|
<NexusIcon Name="robot" Size="48" />
|
|
</div>
|
|
<h1 class="app-name">E-Czytnik <span>AI</span></h1>
|
|
<p class="auth-subtitle">Zaloguj się do E-Czytnika AI</p>
|
|
</div>
|
|
|
|
<div class="social-auth">
|
|
<button type="button" class="btn-google-auth" @onclick="HandleGoogleLogin">
|
|
<img src="https://www.gstatic.com/images/branding/product/1x/gsa_512dp.png"
|
|
alt="Google"
|
|
style="width: 20px !important; height: 20px !important; flex-shrink: 0;" />
|
|
<span>Zaloguj się przez Google</span>
|
|
</button>
|
|
</div>
|
|
|
|
<div class="auth-divider">
|
|
<span>lub</span>
|
|
</div>
|
|
|
|
<EditForm Model="@_loginModel" OnValidSubmit="HandleLogin" class="auth-form">
|
|
<DataAnnotationsValidator />
|
|
|
|
<div class="field-group">
|
|
<div class="field-icon">
|
|
<NexusIcon Name="mail" Size="18" />
|
|
</div>
|
|
<InputText id="email" @bind-Value="_loginModel.Email" placeholder="E-mail" class="field-input" />
|
|
</div>
|
|
<ValidationMessage For="@(() => _loginModel.Email)" class="auth-validation" />
|
|
|
|
<div class="field-group">
|
|
<div class="field-icon">
|
|
<NexusIcon Name="lock" Size="18" />
|
|
</div>
|
|
<InputText id="password" type="@(_showPassword ? "text" : "password")" @bind-Value="_loginModel.Password" placeholder="Hasło" class="field-input" />
|
|
<button type="button" class="toggle-visibility" @onclick="TogglePassword">
|
|
<NexusIcon Name="@(_showPassword ? "eye-off" : "eye")" Size="18" />
|
|
</button>
|
|
</div>
|
|
<ValidationMessage For="@(() => _loginModel.Password)" class="auth-validation" />
|
|
|
|
@if (!string.IsNullOrEmpty(_errorMessage))
|
|
{
|
|
<div class="auth-error">@_errorMessage</div>
|
|
}
|
|
|
|
<button type="submit" class="btn-submit-auth" disabled="@_isSubmitting">
|
|
@if (_isSubmitting)
|
|
{
|
|
<div class="auth-loader"></div>
|
|
}
|
|
else
|
|
{
|
|
<span>Zaloguj się</span>
|
|
}
|
|
</button>
|
|
</EditForm>
|
|
|
|
<div class="auth-footer">
|
|
<a href="/account/forgot-password" class="auth-link">Zapomniałem hasła?</a>
|
|
<p class="auth-switch">Nie masz konta? <a href="/account/register">Zarejestruj się</a></p>
|
|
</div>
|
|
|
|
<div class="auth-legal">
|
|
Korzystając z usługi, akceptujesz <a href="/terms">Regulamin</a> i <a href="/privacy">Politykę Prywatności</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
@code {
|
|
private LoginModel _loginModel = new();
|
|
private string? _errorMessage;
|
|
private bool _isSubmitting;
|
|
private bool _showPassword;
|
|
|
|
private async Task HandleLogin()
|
|
{
|
|
_isSubmitting = true;
|
|
_errorMessage = null;
|
|
|
|
try
|
|
{
|
|
var success = await IdentityService.LoginAsync(_loginModel.Email, _loginModel.Password);
|
|
if (success) NavigationManager.NavigateTo("/");
|
|
else _errorMessage = "Nieprawidłowy e-mail lub hasło.";
|
|
}
|
|
catch (Exception) { _errorMessage = "Wystąpił błąd logowania."; }
|
|
finally { _isSubmitting = false; }
|
|
}
|
|
|
|
private void HandleGoogleLogin() => NavigationManager.NavigateTo("identity/login/google", forceLoad: true);
|
|
private void TogglePassword() => _showPassword = !_showPassword;
|
|
|
|
public class LoginModel
|
|
{
|
|
[System.ComponentModel.DataAnnotations.Required]
|
|
[System.ComponentModel.DataAnnotations.EmailAddress]
|
|
public string Email { get; set; } = string.Empty;
|
|
|
|
[System.ComponentModel.DataAnnotations.Required]
|
|
public string Password { get; set; } = string.Empty;
|
|
}
|
|
}
|