feat: implement core domain models, authentication service, and UI components for the attendance system
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using Asistencia.Services;
|
||||
|
||||
namespace Asistencia.ViewModels;
|
||||
|
||||
public partial class LoginViewModel : ObservableObject
|
||||
{
|
||||
private readonly AuthService _authService;
|
||||
private readonly MainWindowViewModel _mainVm;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _rut = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _password = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _errorMessage = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _hasError;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _isLoading;
|
||||
|
||||
public LoginViewModel(AuthService authService, MainWindowViewModel mainVm)
|
||||
{
|
||||
_authService = authService;
|
||||
_mainVm = mainVm;
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private async Task LoginAsync()
|
||||
{
|
||||
IsLoading = true;
|
||||
HasError = false;
|
||||
|
||||
var (success, message) = await _authService.LoginAsync(Rut, Password);
|
||||
|
||||
if (success)
|
||||
{
|
||||
_mainVm.NavigateToDashboard();
|
||||
}
|
||||
else
|
||||
{
|
||||
ErrorMessage = message;
|
||||
HasError = true;
|
||||
}
|
||||
|
||||
IsLoading = false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user