From 285f740e2a2aa3754445141fa2e974fa4b1d9cd4 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 16 Nov 2023 16:53:37 +0900 Subject: [PATCH] Update various components to handle new state --- osu.Game/Overlays/Login/LoginPanel.cs | 2 +- ...icationForm.cs => SecondFactorAuthForm.cs} | 32 +++++++++++++++---- .../Overlays/Toolbar/ToolbarUserButton.cs | 1 + 3 files changed, 28 insertions(+), 7 deletions(-) rename osu.Game/Overlays/Login/{AccountVerificationForm.cs => SecondFactorAuthForm.cs} (78%) diff --git a/osu.Game/Overlays/Login/LoginPanel.cs b/osu.Game/Overlays/Login/LoginPanel.cs index f896d03231..ce0b0a5a48 100644 --- a/osu.Game/Overlays/Login/LoginPanel.cs +++ b/osu.Game/Overlays/Login/LoginPanel.cs @@ -82,7 +82,7 @@ namespace osu.Game.Overlays.Login break; case APIState.RequiresSecondFactorAuth: - Child = form = new AccountVerificationForm(); + Child = form = new SecondFactorAuthForm(); break; case APIState.Failing: diff --git a/osu.Game/Overlays/Login/AccountVerificationForm.cs b/osu.Game/Overlays/Login/SecondFactorAuthForm.cs similarity index 78% rename from osu.Game/Overlays/Login/AccountVerificationForm.cs rename to osu.Game/Overlays/Login/SecondFactorAuthForm.cs index a27cc01ed2..cfec46c599 100644 --- a/osu.Game/Overlays/Login/AccountVerificationForm.cs +++ b/osu.Game/Overlays/Login/SecondFactorAuthForm.cs @@ -8,15 +8,20 @@ using osu.Framework.Input.Events; using osu.Game.Graphics; using osu.Game.Graphics.Containers; using osu.Game.Graphics.UserInterface; +using osu.Game.Online.API; using osu.Game.Overlays.Settings; using osuTK; namespace osu.Game.Overlays.Login { - public partial class AccountVerificationForm : FillFlowContainer + public partial class SecondFactorAuthForm : FillFlowContainer { - private OsuTextBox code = null!; + private OsuTextBox codeTextBox = null!; private LinkFlowContainer explainText = null!; + private ErrorTextFlowContainer errorText = null!; + + [Resolved] + private IAPIProvider api { get; set; } = null!; [BackgroundDependencyLoader] private void load() @@ -43,18 +48,18 @@ namespace osu.Game.Overlays.Login AutoSizeAxes = Axes.Y, Text = "An email has been sent to you with a verification code. Enter the code.", }, - code = new OsuTextBox + codeTextBox = new OsuTextBox { PlaceholderText = "Enter code", RelativeSizeAxes = Axes.X, - TabbableContentContainer = this + TabbableContentContainer = this, }, explainText = new LinkFlowContainer(s => s.Font = OsuFont.GetFont(weight: FontWeight.Regular)) { RelativeSizeAxes = Axes.X, AutoSizeAxes = Axes.Y, }, - new ErrorTextFlowContainer + errorText = new ErrorTextFlowContainer { RelativeSizeAxes = Axes.X, AutoSizeAxes = Axes.Y, @@ -78,6 +83,21 @@ namespace osu.Game.Overlays.Login explainText.AddText(" or "); explainText.AddLink("sign out", () => { }); explainText.AddText("."); + + codeTextBox.Current.BindValueChanged(code => + { + if (code.NewValue.Length == 8) + { + api.AuthenticateSecondFactor(code.NewValue); + codeTextBox.Current.Disabled = true; + } + }); + + if (api.LastLoginError?.Message is string error) + { + errorText.Alpha = 1; + errorText.AddErrors(new[] { error }); + } } public override bool AcceptsFocus => true; @@ -86,7 +106,7 @@ namespace osu.Game.Overlays.Login protected override void OnFocus(FocusEvent e) { - Schedule(() => { GetContainingInputManager().ChangeFocus(code); }); + Schedule(() => { GetContainingInputManager().ChangeFocus(codeTextBox); }); } } } diff --git a/osu.Game/Overlays/Toolbar/ToolbarUserButton.cs b/osu.Game/Overlays/Toolbar/ToolbarUserButton.cs index 028decea1e..f0b5aed3cf 100644 --- a/osu.Game/Overlays/Toolbar/ToolbarUserButton.cs +++ b/osu.Game/Overlays/Toolbar/ToolbarUserButton.cs @@ -101,6 +101,7 @@ namespace osu.Game.Overlays.Toolbar switch (state.NewValue) { + case APIState.RequiresSecondFactorAuth: case APIState.Connecting: TooltipText = ToolbarStrings.Connecting; spinner.Show();