|
| 1 | +@page "/complete-registration/{userGuid:guid}" |
| 2 | + |
| 3 | +@rendermode InteractiveAuto |
| 4 | + |
| 5 | +@inherits CancellableComponent |
| 6 | + |
| 7 | +@using RailwayResult |
| 8 | +@using System.ComponentModel.DataAnnotations |
| 9 | + |
| 10 | +@inject ApiClient ApiClient |
| 11 | +@inject IAuthService AuthService |
| 12 | +@inject AuthenticationStateProvider AuthenticationStateProvider |
| 13 | +@inject IToastService ToastService |
| 14 | + |
| 15 | +<PageTitle>Complete Registration</PageTitle> |
| 16 | + |
| 17 | +<div class="d-flex flex-dir-column h-screen"> |
| 18 | + <FluentSpacer /> |
| 19 | + <FluentCard Style="margin-bottom: 200px" Class="body-small h-auto margin-auto padding-large"> |
| 20 | + <h1 style="margin-bottom: 16px">Complete Your Registration</h1> |
| 21 | + <FluentDivider Style="margin-bottom: 16px" /> |
| 22 | + |
| 23 | + @if (completed) |
| 24 | + { |
| 25 | + <div class="padding-small d-flex"> |
| 26 | + <strong>Registration has been successfully completed. </strong> |
| 27 | + <FluentIcon Icon="Icons.Filled.Size20.CheckmarkCircle" /> |
| 28 | + </div> |
| 29 | + |
| 30 | + <FluentDivider Style="margin-top: 16px" /> |
| 31 | + |
| 32 | + <FluentStack Orientation="Orientation.Horizontal" Style="margin-top: 8px"> |
| 33 | + <FluentAnchor Href="login" Appearance="Appearance.Lightweight">Log in</FluentAnchor> |
| 34 | + <FluentAnchor Href="register" Appearance="Appearance.Lightweight">Register</FluentAnchor> |
| 35 | + </FluentStack> |
| 36 | + } |
| 37 | + else |
| 38 | + { |
| 39 | + <EditForm Model="@Input" OnValidSubmit="CompleteRegistrationAsync" FormName="CompleteRegistrationForm"> |
| 40 | + <CustomValidation /> |
| 41 | + <FluentStack Orientation="Orientation.Vertical"> |
| 42 | + <FluentTextField @bind-value="Input.Password" Immediate="true" AutoComplete="current-password" Required="true" Placeholder="password" Label="Password" type="password" Class="w-100" /> |
| 43 | + <FluentValidationMessage For="() => Input.Password" Class="text-danger" /> |
| 44 | + |
| 45 | + <FluentTextField @bind-value="Input.ConfirmPassword" Immediate="true" Required="true" Placeholder="password" Label="Confirm Password" type="password" Class="w-100" /> |
| 46 | + <FluentValidationMessage For="() => Input.ConfirmPassword" Class="text-danger" /> |
| 47 | + |
| 48 | + <FluentStack Orientation="Orientation.Horizontal" Style="margin-top: 8px"> |
| 49 | + <FluentButton Type="ButtonType.Submit" Appearance="Appearance.Accent">Complete</FluentButton> |
| 50 | + <FluentAnchor Href="login" Appearance="Appearance.Lightweight">Log in</FluentAnchor> |
| 51 | + <FluentAnchor Href="register" Appearance="Appearance.Lightweight">Register</FluentAnchor> |
| 52 | + </FluentStack> |
| 53 | + </FluentStack> |
| 54 | + </EditForm> |
| 55 | + } |
| 56 | + </FluentCard> |
| 57 | + <FluentSpacer /> |
| 58 | +</div> |
| 59 | + |
| 60 | +@code |
| 61 | +{ |
| 62 | + [Parameter] |
| 63 | + public Guid UserGuid { get; init; } = default!; |
| 64 | + |
| 65 | + [SupplyParameterFromForm] |
| 66 | + private RegisterModel Input { get; set; } = new(); |
| 67 | + |
| 68 | + private bool completed = false; |
| 69 | + |
| 70 | + public async Task CompleteRegistrationAsync() |
| 71 | + { |
| 72 | + var state = await AuthenticationStateProvider.GetAuthenticationStateAsync(); |
| 73 | + if (state.User.Identity?.IsAuthenticated == true) |
| 74 | + { |
| 75 | + await AuthService.LogoutAsync("", CTS.Token); |
| 76 | + } |
| 77 | + |
| 78 | + var userId = UserId.FromGuid(UserGuid); |
| 79 | + var result = await ApiClient.CompleteRegistrationAsync(userId, Input.Password, CTS.Token); |
| 80 | + if (result.IsFailure) |
| 81 | + { |
| 82 | + ToastService.ShowError(result.Error.Message); |
| 83 | + Input.Password = ""; |
| 84 | + Input.ConfirmPassword = ""; |
| 85 | + return; |
| 86 | + } |
| 87 | + |
| 88 | + ToastService.ShowSuccess("Registration completed"); |
| 89 | + completed = true; |
| 90 | + } |
| 91 | + |
| 92 | + private sealed class RegisterModel |
| 93 | + { |
| 94 | + [Required] |
| 95 | + [DataType(DataType.Password)] |
| 96 | + [Display(Name = "Password")] |
| 97 | + public string Password { get; set; } = ""; |
| 98 | + |
| 99 | + [DataType(DataType.Password)] |
| 100 | + [Display(Name = "Confirm password")] |
| 101 | + [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")] |
| 102 | + public string ConfirmPassword { get; set; } = ""; |
| 103 | + } |
| 104 | +} |
0 commit comments