| | 1 | | @using Syki.Front.Components.Passwords |
| | 2 | |
|
| | 3 | | @namespace Syki.Front.Pages.Cross |
| | 4 | |
|
| | 5 | | @page "/login" |
| | 6 | |
|
| | 7 | | <SykiPageTitle Title="Login" /> |
| | 8 | |
|
| | 9 | | <MudContainer Class="mt-4 mb-8" MaxWidth="MaxWidth.ExtraSmall"> |
| | 10 | | <MudOverlay @bind-Visible="@_loading" LightBackground="true" Absolute="false"> |
| | 11 | | <MudProgressCircular Color="Color.Info" Indeterminate="true" Size="Size.Large" /> |
| | 12 | | </MudOverlay> |
| 0 | 13 | | <MudForm @ref="@_form"> |
| 0 | 14 | | <MudCard Class="px-4 pt-0 pb-4"> |
| 0 | 15 | | <MudImage Src="logo_512x512.png" Alt="Syki" Elevation="25" Class="rounded-lg mx-20 mt-10 mb-5"/> |
| 0 | 16 | | <MudCardContent> |
| 0 | 17 | | <MudTextField |
| 0 | 18 | | InputType="InputType.Email" |
| | 19 | | Margin="Margin.Dense" |
| | 20 | | AutoFocus="true" |
| | 21 | | Label="Email" |
| | 22 | | Class="mt-0 pb-3" |
| | 23 | | OnlyValidateIfDirty="true" |
| | 24 | | @bind-Value="@_email" |
| | 25 | | Variant="Variant.Outlined" |
| | 26 | | Required="true" |
| | 27 | | RequiredError="Informe!"/> |
| | 28 | | <PasswordTextField @bind-Value="@_password"/> |
| | 29 | | </MudCardContent> |
| | 30 | | <MudCardActions Class="justify-center"> |
| | 31 | | <MudStack Spacing="1"> |
| | 32 | | <MudButton |
| | 33 | | Size="Size.Large" |
| | 34 | | OnClick="@OnClick" |
| | 35 | | Variant="Variant.Filled" |
| | 36 | | Color="Color.Primary" |
| | 37 | | Class="mx-auto mb-4 px-12"> |
| | 38 | | Login |
| | 39 | | </MudButton> |
| | 40 | | <MudLink Href="/reset-password-token">Esqueci minha senha</MudLink> |
| | 41 | | </MudStack> |
| | 42 | | </MudCardActions> |
| | 43 | | </MudCard> |
| | 44 | | </MudForm> |
| | 45 | | </MudContainer> |
| | 46 | |
|
| | 47 | | @inject ISnackbar Snackbar |
| | 48 | | @inject LoginClient Client |
| | 49 | | @inject NavigationManager Nav |
| | 50 | |
|
| | 51 | | @code |
| | 52 | | { |
| | 53 | | private bool _loading; |
| | 54 | | private MudForm _form; |
| | 55 | | private string _email; |
| | 56 | | private string _password; |
| | 57 | |
|
| | 58 | | private async Task OnClick() |
| | 59 | | { |
| 0 | 60 | | await _form.Validate(); |
| 0 | 61 | | if (!_form.IsValid) return; |
| | 62 | |
|
| 0 | 63 | | _loading = true; |
| 0 | 64 | | var result = await Client.Login(_email, _password); |
| 0 | 65 | | if (result.AccessToken != null) |
| | 66 | | { |
| 0 | 67 | | Nav.NavigateTo("/"); |
| | 68 | | } |
| 0 | 69 | | if (result.RequiresTwoFactor) |
| | 70 | | { |
| 0 | 71 | | Nav.NavigateTo("/login-mfa"); |
| | 72 | | } |
| 0 | 73 | | if (result.WrongEmailOrPassword) |
| | 74 | | { |
| 0 | 75 | | Snackbar.Add("Email ou senha inválidos!", Severity.Error); |
| | 76 | | } |
| 0 | 77 | | _loading = false; |
| 0 | 78 | | } |
| | 79 | | } |