|
| 1 | +namespace Arise.Client.Launcher.Controllers; |
| 2 | + |
| 3 | +internal sealed partial class AccountVerificationModalController : ModalController |
| 4 | +{ |
| 5 | + private readonly UserSession _session; |
| 6 | + |
| 7 | + [ObservableProperty] |
| 8 | + [NotifyCanExecuteChangedFor(nameof(ConfirmCommand))] |
| 9 | + private string _token = string.Empty; |
| 10 | + |
| 11 | + [ObservableProperty] |
| 12 | + [NotifyCanExecuteChangedFor(nameof(ConfirmCommand))] |
| 13 | + private string _password = string.Empty; |
| 14 | + |
| 15 | + [ObservableProperty] |
| 16 | + private ActionStatus _actionStatus; |
| 17 | + |
| 18 | + public bool CanConfirm => !string.IsNullOrEmpty(Token) |
| 19 | + && !string.IsNullOrEmpty(Password) |
| 20 | + && ActionStatus is not ActionStatus.Pending; |
| 21 | + |
| 22 | + public AccountVerificationModalController(IServiceProvider services, MainController mainController) |
| 23 | + : base(services, mainController) |
| 24 | + { |
| 25 | + _session = services.GetService<UserSession>()!; |
| 26 | + } |
| 27 | + |
| 28 | + [RelayCommand(CanExecute = nameof(CanConfirm))] |
| 29 | + private async Task ConfirmAsync() |
| 30 | + { |
| 31 | + try |
| 32 | + { |
| 33 | + ActionStatus = ActionStatus.Pending; |
| 34 | + await MainController.Gateway.Rest.VerifyAccountTokenAsync(_session.AccountName!, Password, new AccountsVerifyRequest |
| 35 | + { |
| 36 | + Token = Token, |
| 37 | + }).ConfigureAwait(true); |
| 38 | + |
| 39 | + _session.Verify(); |
| 40 | + ActionStatus = ActionStatus.Successful; |
| 41 | + |
| 42 | + await Task.Delay(1000).ConfigureAwait(true); // wait a bit to show feedback before closing modal |
| 43 | + |
| 44 | + MainController.CurrentModalController = null; |
| 45 | + } |
| 46 | + catch (GatewayHttpException) |
| 47 | + { |
| 48 | + // todo: something else? |
| 49 | + ActionStatus = ActionStatus.Failed; |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + [RelayCommand] |
| 54 | + private void Cancel() |
| 55 | + { |
| 56 | + MainController.CurrentModalController = null; |
| 57 | + } |
| 58 | + |
| 59 | + [RelayCommand] |
| 60 | + private async Task ResendEmailAsync() |
| 61 | + { |
| 62 | + try |
| 63 | + { |
| 64 | + ActionStatus = ActionStatus.Pending; |
| 65 | + await MainController.Gateway.Rest.SendAccountEmailAsync(_session.AccountName!, Password) |
| 66 | + .ConfigureAwait(true); |
| 67 | + |
| 68 | + ActionStatus = ActionStatus.Successful; |
| 69 | + } |
| 70 | + catch (GatewayHttpException) |
| 71 | + { |
| 72 | + // todo: something else? |
| 73 | + ActionStatus = ActionStatus.Failed; |
| 74 | + } |
| 75 | + } |
| 76 | +} |
0 commit comments