2025-08-22 11:30:09 +02:00
|
|
|
|
2025-10-11 11:33:46 +02:00
|
|
|
@using BimAI.UI.Shared.Services
|
2025-07-19 22:50:38 +02:00
|
|
|
@using Microsoft.Extensions.Configuration
|
|
|
|
|
@inject IJSRuntime JS
|
|
|
|
|
@inject IConfiguration Configuration
|
|
|
|
|
@inject AuthService AuthService
|
|
|
|
|
@inject NavigationManager NavigationManager
|
|
|
|
|
|
|
|
|
|
<MudCard Class="login-card" Elevation="8">
|
|
|
|
|
<MudCardContent Class="pa-8 d-flex flex-column align-center">
|
2025-10-11 11:33:46 +02:00
|
|
|
<MudText Typo="Typo.h4" Class="mb-4">Witaj w BimAI</MudText>
|
2025-07-19 22:50:38 +02:00
|
|
|
<MudText Typo="Typo.body1" Class="mb-6 text-center">
|
|
|
|
|
Zaloguj się używając konta Google
|
|
|
|
|
</MudText>
|
|
|
|
|
|
|
|
|
|
<MudButton
|
|
|
|
|
Variant="Variant.Filled"
|
|
|
|
|
StartIcon="@Icons.Custom.Brands.Google"
|
|
|
|
|
Size="Size.Large"
|
|
|
|
|
OnClick="HandleGoogleSignIn"
|
|
|
|
|
Disabled="@_isLoading">
|
|
|
|
|
@if (_isLoading)
|
|
|
|
|
{
|
|
|
|
|
<MudProgressCircular Class="mr-3" Size="Size.Small" Indeterminate="true"></MudProgressCircular>
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
<span>Zaloguj z Google</span>
|
|
|
|
|
}
|
|
|
|
|
</MudButton>
|
|
|
|
|
|
|
|
|
|
@if (!string.IsNullOrEmpty(_errorMessage))
|
|
|
|
|
{
|
|
|
|
|
<MudAlert Severity="Severity.Error" Class="mt-4">
|
|
|
|
|
@_errorMessage
|
|
|
|
|
</MudAlert>
|
|
|
|
|
}
|
|
|
|
|
</MudCardContent>
|
|
|
|
|
</MudCard>
|
|
|
|
|
|
|
|
|
|
@code {
|
|
|
|
|
private bool _isLoading = false;
|
|
|
|
|
private string _errorMessage = string.Empty;
|
|
|
|
|
private static LoginCard? _instance;
|
2025-08-22 11:30:09 +02:00
|
|
|
private bool _isInitialized = false;
|
2025-07-19 22:50:38 +02:00
|
|
|
|
2025-08-22 11:30:09 +02:00
|
|
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
2025-07-19 22:50:38 +02:00
|
|
|
{
|
2025-08-22 11:30:09 +02:00
|
|
|
if (firstRender)
|
|
|
|
|
{
|
|
|
|
|
_instance = this;
|
|
|
|
|
await InitializeGoogleSignIn();
|
|
|
|
|
}
|
2025-07-19 22:50:38 +02:00
|
|
|
}
|
|
|
|
|
|
2025-08-22 11:30:09 +02:00
|
|
|
private async Task InitializeGoogleSignIn()
|
2025-07-19 22:50:38 +02:00
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2025-08-22 11:30:09 +02:00
|
|
|
if (_isInitialized) return;
|
2025-07-19 22:50:38 +02:00
|
|
|
|
|
|
|
|
var clientId = Configuration["GoogleAuth:ClientId"];
|
|
|
|
|
if (string.IsNullOrEmpty(clientId))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Google ClientId is not configured.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await JS.InvokeVoidAsync("initGoogleSignIn", clientId);
|
2025-08-22 11:30:09 +02:00
|
|
|
_isInitialized = true;
|
2025-07-19 22:50:38 +02:00
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2025-08-22 11:30:09 +02:00
|
|
|
_errorMessage = "Błąd inicjalizacji Google Sign-In.";
|
|
|
|
|
Console.Error.WriteLine($"Google Sign-In initialization error: {ex.Message}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task HandleGoogleSignIn()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_isLoading = true;
|
|
|
|
|
_errorMessage = string.Empty;
|
|
|
|
|
StateHasChanged();
|
|
|
|
|
|
|
|
|
|
await JS.InvokeVoidAsync("requestGoogleSignIn");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_errorMessage = "Błąd podczas logowania. Spróbuj ponownie";
|
2025-07-19 22:50:38 +02:00
|
|
|
_isLoading = false;
|
|
|
|
|
StateHasChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[JSInvokable]
|
2025-08-22 11:30:09 +02:00
|
|
|
public static async Task OnGoogleSignInSuccess(string accessToken, string fullName, string email, string avatarUrl)
|
2025-07-19 22:50:38 +02:00
|
|
|
{
|
2025-08-22 11:30:09 +02:00
|
|
|
Console.WriteLine($"Google Sign-In Success: {email}");
|
2025-07-19 22:50:38 +02:00
|
|
|
|
|
|
|
|
if (_instance != null)
|
|
|
|
|
{
|
2025-08-22 11:30:09 +02:00
|
|
|
var userInfo = new UserInfo
|
|
|
|
|
{
|
|
|
|
|
FullName = fullName,
|
|
|
|
|
Email = email,
|
|
|
|
|
AvatarUrl = avatarUrl
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
await _instance.AuthService.SetAuthenticationAsync(accessToken, userInfo);
|
2025-07-19 22:50:38 +02:00
|
|
|
|
|
|
|
|
_instance._isLoading = false;
|
|
|
|
|
_instance._errorMessage = string.Empty;
|
|
|
|
|
|
2025-08-22 11:30:09 +02:00
|
|
|
_instance.NavigationManager.NavigateTo("/dashboard", replace: true);
|
2025-07-19 22:50:38 +02:00
|
|
|
|
|
|
|
|
await _instance.InvokeAsync(() => _instance.StateHasChanged());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[JSInvokable]
|
2025-08-22 11:30:09 +02:00
|
|
|
public static async Task OnGoogleSignInError(string error)
|
2025-07-19 22:50:38 +02:00
|
|
|
{
|
|
|
|
|
Console.WriteLine($"Google SignIn Error: {error}");
|
|
|
|
|
|
|
|
|
|
if (_instance != null)
|
|
|
|
|
{
|
|
|
|
|
_instance._isLoading = false;
|
2025-08-22 11:30:09 +02:00
|
|
|
_instance._errorMessage = "Błąd logowania Google. Spróbuj ponownie";
|
2025-07-19 22:50:38 +02:00
|
|
|
await _instance.InvokeAsync(() => _instance.StateHasChanged());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<style>
|
|
|
|
|
.login-card {
|
|
|
|
|
max-width: 400px;
|
|
|
|
|
width: 100%;
|
|
|
|
|
background: rgba(255, 255, 255, 0.95);
|
|
|
|
|
backdrop-filter: blur(10px);
|
|
|
|
|
}
|
|
|
|
|
</style>
|