| | 1 | | @using Syki.Front.Components.Passwords |
| | 2 | |
|
| | 3 | | @namespace Syki.Front.Pages.Cross |
| | 4 | |
|
| | 5 | | @page "/reset-password" |
| | 6 | |
|
| | 7 | | <SykiPageTitle Title="Redefinir senha" /> |
| | 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> |
| | 13 | | <MudForm> |
| | 14 | | <MudCard Class="px-4 pt-0 pb-4"> |
| | 15 | | <MudImage Src="logo_512x512.png" Alt="Syki" Elevation="25" Class="rounded-lg mx-20 mt-10 mb-10"/> |
| 0 | 16 | | @if (_saved) |
| | 17 | | { |
| | 18 | | <MudStack AlignItems="AlignItems.Center"> |
| | 19 | | <MudAlert NoIcon="true" Class="mt-6" Severity="Severity.Success" Variant="Variant.Text" ContentAlign |
| | 20 | | <MudText>Pronto, agora é só logar!</MudText> |
| | 21 | | </MudAlert> |
| | 22 | | <MudButton |
| | 23 | | Size="Size.Large" |
| | 24 | | OnClick="@GoToLogin" |
| | 25 | | Variant="Variant.Filled" |
| | 26 | | Color="Color.Primary" |
| | 27 | | Class="mx-auto mb-4 px-12"> |
| | 28 | | Ir pro login |
| | 29 | | </MudButton> |
| | 30 | | </MudStack> |
| | 31 | | } |
| | 32 | | else |
| | 33 | | { |
| | 34 | | <MudCardContent Class="pt-0 pb-2 px-0"> |
| | 35 | | <PasswordTextField Value="@_setup.Password" ValueChanged="@HandlePasswordChange" Class="pb-2 px-4" R |
| | 36 | | <PasswordRequerimentsCard @bind-Validation="@_setup.Validation"/> |
| | 37 | | </MudCardContent> |
| | 38 | | <MudCardActions> |
| | 39 | | <MudButton |
| | 40 | | Size="Size.Large" |
| | 41 | | OnClick="@Submit" |
| | 42 | | Disabled="@(!_setup.IsValid())" |
| | 43 | | Variant="Variant.Filled" |
| | 44 | | Color="Color.Primary" |
| | 45 | | Class="mx-auto mb-4 px-12"> |
| | 46 | | SALVAR |
| | 47 | | </MudButton> |
| | 48 | | </MudCardActions> |
| | 49 | | } |
| | 50 | | </MudCard> |
| | 51 | | </MudForm> |
| | 52 | | </MudContainer> |
| | 53 | |
|
| | 54 | | @inject ISnackbar Snackbar |
| | 55 | | @inject NavigationManager Nav |
| | 56 | | @inject ResetPasswordClient Client |
| | 57 | |
|
| | 58 | | @code |
| | 59 | | { |
| | 60 | | [Parameter] |
| | 61 | | [SupplyParameterFromQuery] |
| 0 | 62 | | public string? Token { get; set; } |
| | 63 | |
|
| | 64 | | private bool _saved; |
| | 65 | | private bool _loading; |
| 0 | 66 | | private SetupPassword _setup = new(); |
| | 67 | |
|
| | 68 | | private void HandlePasswordChange(string newValue) |
| | 69 | | { |
| 0 | 70 | | _setup.Password = newValue; |
| 0 | 71 | | _setup.Validate(); |
| 0 | 72 | | } |
| | 73 | |
|
| | 74 | | private void GoToLogin() |
| | 75 | | { |
| 0 | 76 | | Nav.NavigateTo("/login"); |
| 0 | 77 | | } |
| | 78 | |
|
| | 79 | | private async Task Submit() |
| | 80 | | { |
| 0 | 81 | | _loading = true; |
| 0 | 82 | | var response = await Client.Reset(Token, _setup.Password ); |
| 0 | 83 | | if (response.IsSuccessStatusCode) |
| | 84 | | { |
| 0 | 85 | | _saved = true; |
| | 86 | | } |
| | 87 | | else |
| | 88 | | { |
| 0 | 89 | | var error = await response.ToError(); |
| 0 | 90 | | Snackbar.Add(error.Message, Severity.Error); |
| | 91 | | } |
| 0 | 92 | | _loading = false; |
| 0 | 93 | | } |
| | 94 | | } |