1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-13 03:13:21 +08:00

Merge pull request #26950 from bdach/2fa-in-registration

Add 2FA verification screen to registration flow
This commit is contained in:
Dan Balasescu 2024-02-02 17:30:20 +09:00 committed by GitHub
commit 8c107b4925
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 90 additions and 31 deletions

View File

@ -10,6 +10,7 @@ using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Testing; using osu.Framework.Testing;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.API; using osu.Game.Online.API;
using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.API.Requests.Responses;
using osu.Game.Overlays; using osu.Game.Overlays;
@ -67,5 +68,34 @@ namespace osu.Game.Tests.Visual.Online
}); });
AddUntilStep("overlay is hidden", () => accountCreation.State.Value == Visibility.Hidden); AddUntilStep("overlay is hidden", () => accountCreation.State.Value == Visibility.Hidden);
} }
[Test]
public void TestFullFlow()
{
AddStep("log out", () => API.Logout());
AddStep("show manually", () => accountCreation.Show());
AddUntilStep("overlay is visible", () => accountCreation.State.Value == Visibility.Visible);
AddStep("click button", () => accountCreation.ChildrenOfType<SettingsButton>().Single().TriggerClick());
AddUntilStep("warning screen is present", () => accountCreation.ChildrenOfType<ScreenWarning>().SingleOrDefault()?.IsPresent == true);
AddStep("proceed", () => accountCreation.ChildrenOfType<DangerousSettingsButton>().Single().TriggerClick());
AddUntilStep("entry screen is present", () => accountCreation.ChildrenOfType<ScreenEntry>().SingleOrDefault()?.IsPresent == true);
AddStep("input details", () =>
{
var entryScreen = accountCreation.ChildrenOfType<ScreenEntry>().Single();
entryScreen.ChildrenOfType<OsuTextBox>().ElementAt(0).Text = "new_user";
entryScreen.ChildrenOfType<OsuTextBox>().ElementAt(1).Text = "new.user@fake.mail";
entryScreen.ChildrenOfType<OsuTextBox>().ElementAt(2).Text = "password";
});
AddStep("click button", () => accountCreation.ChildrenOfType<ScreenEntry>().Single()
.ChildrenOfType<SettingsButton>().Single().TriggerClick());
AddUntilStep("verification screen is present", () => accountCreation.ChildrenOfType<ScreenEmailVerification>().SingleOrDefault()?.IsPresent == true);
AddStep("verify", () => ((DummyAPIAccess)API).AuthenticateSecondFactor("abcdefgh"));
AddUntilStep("overlay is hidden", () => accountCreation.State.Value == Visibility.Hidden);
}
} }
} }

View File

@ -0,0 +1,24 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Game.Overlays.Login;
namespace osu.Game.Overlays.AccountCreation
{
public partial class ScreenEmailVerification : AccountCreationScreen
{
[BackgroundDependencyLoader]
private void load()
{
InternalChild = new SecondFactorAuthForm
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding(20),
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
};
}
}
}

View File

@ -1,12 +1,11 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
#nullable disable
using System; using System;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.LocalisationExtensions; using osu.Framework.Extensions.LocalisationExtensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
@ -28,28 +27,30 @@ namespace osu.Game.Overlays.AccountCreation
{ {
public partial class ScreenEntry : AccountCreationScreen public partial class ScreenEntry : AccountCreationScreen
{ {
private ErrorTextFlowContainer usernameDescription; private ErrorTextFlowContainer usernameDescription = null!;
private ErrorTextFlowContainer emailAddressDescription; private ErrorTextFlowContainer emailAddressDescription = null!;
private ErrorTextFlowContainer passwordDescription; private ErrorTextFlowContainer passwordDescription = null!;
private OsuTextBox usernameTextBox; private OsuTextBox usernameTextBox = null!;
private OsuTextBox emailTextBox; private OsuTextBox emailTextBox = null!;
private OsuPasswordTextBox passwordTextBox; private OsuPasswordTextBox passwordTextBox = null!;
[Resolved] [Resolved]
private IAPIProvider api { get; set; } private IAPIProvider api { get; set; } = null!;
private ShakeContainer registerShake; private IBindable<APIState> apiState = null!;
private ITextPart characterCheckText;
private OsuTextBox[] textboxes; private ShakeContainer registerShake = null!;
private LoadingLayer loadingLayer; private ITextPart characterCheckText = null!;
private OsuTextBox[] textboxes = null!;
private LoadingLayer loadingLayer = null!;
[Resolved] [Resolved]
private GameHost host { get; set; } private GameHost? host { get; set; }
[Resolved] [Resolved]
private OsuGame game { get; set; } private OsuGame? game { get; set; }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load()
@ -144,6 +145,8 @@ namespace osu.Game.Overlays.AccountCreation
passwordTextBox.Current.BindValueChanged(_ => updateCharacterCheckTextColour(), true); passwordTextBox.Current.BindValueChanged(_ => updateCharacterCheckTextColour(), true);
characterCheckText.DrawablePartsRecreated += _ => updateCharacterCheckTextColour(); characterCheckText.DrawablePartsRecreated += _ => updateCharacterCheckTextColour();
apiState = api.State.GetBoundCopy();
} }
private void updateCharacterCheckTextColour() private void updateCharacterCheckTextColour()
@ -180,7 +183,7 @@ namespace osu.Game.Overlays.AccountCreation
Task.Run(() => Task.Run(() =>
{ {
bool success; bool success;
RegistrationRequest.RegistrationRequestErrors errors = null; RegistrationRequest.RegistrationRequestErrors? errors = null;
try try
{ {
@ -210,7 +213,7 @@ namespace osu.Game.Overlays.AccountCreation
if (!string.IsNullOrEmpty(errors.Message)) if (!string.IsNullOrEmpty(errors.Message))
passwordDescription.AddErrors(new[] { errors.Message }); passwordDescription.AddErrors(new[] { errors.Message });
game.OpenUrlExternally($"{errors.Redirect}?username={usernameTextBox.Text}&email={emailTextBox.Text}", true); game?.OpenUrlExternally($"{errors.Redirect}?username={usernameTextBox.Text}&email={emailTextBox.Text}", true);
} }
} }
else else
@ -223,6 +226,12 @@ namespace osu.Game.Overlays.AccountCreation
return; return;
} }
apiState.BindValueChanged(state =>
{
if (state.NewValue == APIState.RequiresSecondFactorAuth)
this.Push(new ScreenEmailVerification());
});
api.Login(usernameTextBox.Text, passwordTextBox.Text); api.Login(usernameTextBox.Text, passwordTextBox.Text);
}); });
}); });
@ -241,6 +250,6 @@ namespace osu.Game.Overlays.AccountCreation
return false; return false;
} }
private OsuTextBox nextUnfilledTextBox() => textboxes.FirstOrDefault(t => string.IsNullOrEmpty(t.Text)); private OsuTextBox? nextUnfilledTextBox() => textboxes.FirstOrDefault(t => string.IsNullOrEmpty(t.Text));
} }
} }

View File

@ -1,8 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
#nullable disable
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
@ -23,14 +21,14 @@ namespace osu.Game.Overlays.AccountCreation
{ {
public partial class ScreenWarning : AccountCreationScreen public partial class ScreenWarning : AccountCreationScreen
{ {
private OsuTextFlowContainer multiAccountExplanationText; private OsuTextFlowContainer multiAccountExplanationText = null!;
private LinkFlowContainer furtherAssistance; private LinkFlowContainer furtherAssistance = null!;
[Resolved(canBeNull: true)] [Resolved]
private IAPIProvider api { get; set; } private IAPIProvider? api { get; set; }
[Resolved(canBeNull: true)] [Resolved]
private OsuGame game { get; set; } private OsuGame? game { get; set; }
private const string help_centre_url = "/help/wiki/Help_Centre#login"; private const string help_centre_url = "/help/wiki/Help_Centre#login";

View File

@ -1,8 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
#nullable disable
using System; using System;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
@ -25,7 +23,9 @@ namespace osu.Game.Overlays
{ {
private const float transition_time = 400; private const float transition_time = 400;
private ScreenWelcome welcomeScreen; private ScreenWelcome welcomeScreen = null!;
private ScheduledDelegate? scheduledHide;
public AccountCreationOverlay() public AccountCreationOverlay()
{ {
@ -108,8 +108,6 @@ namespace osu.Game.Overlays
this.FadeOut(100); this.FadeOut(100);
} }
private ScheduledDelegate scheduledHide;
private void apiStateChanged(ValueChangedEvent<APIState> state) private void apiStateChanged(ValueChangedEvent<APIState> state)
{ {
switch (state.NewValue) switch (state.NewValue)