Skip to content

Commit 1acfacf

Browse files
committed
complete the register-login-verify flow
1 parent 6007d68 commit 1acfacf

14 files changed

+485
-113
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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+
}

src/client/Launcher/Controllers/LoginState.cs src/client/Launcher/Controllers/ActionStatus.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace Arise.Client.Launcher.Controllers;
22

3-
public enum LoginState
3+
public enum ActionStatus
44
{
55
None,
66
Pending,

src/client/Launcher/Controllers/DefaultController.cs

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ private void Play()
2121
{
2222
MainController.ShowLoginForm();
2323
}
24+
else if (!_session.IsVerified)
25+
{
26+
MainController.ShowAccountVerificationForm();
27+
}
2428
else
2529
{
2630
MainController.LaunchGame();

src/client/Launcher/Controllers/LoginModalController.cs

+9-6
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ internal sealed partial class LoginModalController : ModalController
1616
private bool _rememberMe;
1717

1818
[ObservableProperty]
19-
private LoginState _loginState;
19+
private ActionStatus _actionStatus;
2020

2121
private bool CanExecuteLogin => !string.IsNullOrEmpty(Email)
22-
&& !string.IsNullOrEmpty(Password);
22+
&& !string.IsNullOrEmpty(Password)
23+
&& ActionStatus is not ActionStatus.Pending;
2324

2425
public LoginModalController(IServiceProvider services, MainController mainController)
2526
: base(services, mainController)
@@ -36,7 +37,7 @@ private async Task LoginAsync()
3637
{
3738
try
3839
{
39-
LoginState = LoginState.Pending;
40+
ActionStatus = ActionStatus.Pending;
4041

4142
var resp = await MainController.Gateway.Rest
4243
.AuthenticateAccountAsync(Email, Password).ConfigureAwait(true);
@@ -45,19 +46,21 @@ private async Task LoginAsync()
4546
{
4647
_session.Login(Email, resp);
4748

48-
LoginState = LoginState.Successful;
49+
ActionStatus = ActionStatus.Successful;
50+
51+
await Task.Delay(1000).ConfigureAwait(true);
4952

5053
MainController.CurrentModalController = null;
5154
}
5255
else
5356
{
54-
LoginState = LoginState.Failed;
57+
ActionStatus = ActionStatus.Failed;
5558
}
5659
}
5760
catch (GatewayHttpException)
5861
{
5962
// todo
60-
LoginState = LoginState.Failed;
63+
ActionStatus = ActionStatus.Failed;
6164
}
6265
finally
6366
{

src/client/Launcher/Controllers/MainController.cs

+7-2
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ internal sealed partial class MainController : LauncherController
1717
private bool _isLoggedIn;
1818

1919
[ObservableProperty]
20-
private bool _isVerified = true;
20+
private bool _isVerified;
2121

2222
[ObservableProperty]
23-
private string _currentAccountName = "LOGIN";
23+
private string _currentAccountName = string.Empty;
2424

2525
[ObservableProperty]
2626
private ViewController _currentContent;
@@ -111,6 +111,11 @@ public void ShowLoginForm()
111111
CurrentModalController = new LoginModalController(Services, this);
112112
}
113113

114+
public void ShowAccountVerificationForm()
115+
{
116+
CurrentModalController = new AccountVerificationModalController(Services, this);
117+
}
118+
114119
[SuppressMessage("", "CA1822")]
115120
public void LaunchGame()
116121
{

src/client/Launcher/Controllers/ModalController.cs

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ namespace Arise.Client.Launcher.Controllers;
22

33
internal partial class ModalController : LauncherController
44
{
5+
[ObservableProperty]
6+
private ActionStatus _actionStatus;
7+
58
protected MainController MainController { get; }
69

710
public ModalController(IServiceProvider services, MainController mainController)

src/client/Launcher/Controllers/RegistrationModalController.cs

+19-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ namespace Arise.Client.Launcher.Controllers;
22

33
internal sealed partial class RegistrationModalController : ModalController
44
{
5+
private readonly UserSession _session;
6+
57
[ObservableProperty]
68
private string _email = string.Empty;
79

@@ -11,15 +13,15 @@ internal sealed partial class RegistrationModalController : ModalController
1113
public RegistrationModalController(IServiceProvider services, MainController mainController)
1214
: base(services, mainController)
1315
{
16+
_session = services.GetService<UserSession>()!;
1417
}
1518

1619
[RelayCommand]
1720
private async Task ConfirmAsync()
1821
{
19-
MainController.CurrentModalController = null;
20-
2122
try
2223
{
24+
ActionStatus = ActionStatus.Pending;
2325
var request = new AccountsCreateRequest
2426
{
2527
Email = Email,
@@ -34,23 +36,35 @@ await MainController.Gateway.Rest
3436
{
3537
// todo
3638
Password = string.Empty;
39+
ActionStatus = ActionStatus.Failed;
3740
return;
3841
}
3942

4043
try
4144
{
42-
var loginResult = await MainController.Gateway.Rest
45+
var resp = await MainController.Gateway.Rest
4346
.AuthenticateAccountAsync(Email, Password)
4447
.ConfigureAwait(true);
4548

46-
if (!string.IsNullOrEmpty(loginResult.SessionTicket))
49+
if (resp.SessionTicket != null)
50+
{
51+
_session.Login(Email, resp);
52+
53+
ActionStatus = ActionStatus.Successful;
54+
55+
await Task.Delay(1000).ConfigureAwait(true); // wait a bit to show feedback before closing modal
56+
57+
MainController.CurrentModalController = null;
58+
}
59+
else
4760
{
48-
MainController.IsLoggedIn = true;
61+
ActionStatus = ActionStatus.Failed;
4962
}
5063
}
5164
catch (GatewayHttpException)
5265
{
5366
// todo
67+
ActionStatus = ActionStatus.Failed;
5468
}
5569
finally
5670
{

src/client/Launcher/LauncherApplication.axaml

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<Application xmlns="https://github.com/avaloniaui"
22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
33
xmlns:icons="using:Material.Icons.Avalonia"
4+
xmlns:controls="clr-namespace:Arise.Client.Launcher.Controls"
45
x:Class="Arise.Client.Launcher.LauncherApplication">
56
<Application.Styles>
67
<FluentTheme />
@@ -58,5 +59,7 @@
5859
Color="{StaticResource MainColor}" />
5960
<!-- not working; figure it out later -->
6061
<!-- <FontFamily x:Key="Quicksand">avares://Fonts#Quicksand Light</FontFamily> -->
62+
<controls:EqualityConverter x:Key="equals" />
63+
6164
</Application.Resources>
6265
</Application>

src/client/Launcher/UserSession.cs

+7
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,11 @@ public void Logout()
2929

3030
StatusChanged?.Invoke();
3131
}
32+
33+
public void Verify()
34+
{
35+
IsVerified = true;
36+
37+
StatusChanged?.Invoke();
38+
}
3239
}

0 commit comments

Comments
 (0)