mirror of
https://github.com/ppy/osu.git
synced 2025-01-12 19:42:55 +08:00
Merge pull request #26950 from bdach/2fa-in-registration
Add 2FA verification screen to registration flow
This commit is contained in:
commit
8c107b4925
@ -10,6 +10,7 @@ using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
using osu.Game.Overlays;
|
||||
@ -67,5 +68,34 @@ namespace osu.Game.Tests.Visual.Online
|
||||
});
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
24
osu.Game/Overlays/AccountCreation/ScreenEmailVerification.cs
Normal file
24
osu.Game/Overlays/AccountCreation/ScreenEmailVerification.cs
Normal 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,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -1,12 +1,11 @@
|
||||
// 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.
|
||||
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Extensions.LocalisationExtensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
@ -28,28 +27,30 @@ namespace osu.Game.Overlays.AccountCreation
|
||||
{
|
||||
public partial class ScreenEntry : AccountCreationScreen
|
||||
{
|
||||
private ErrorTextFlowContainer usernameDescription;
|
||||
private ErrorTextFlowContainer emailAddressDescription;
|
||||
private ErrorTextFlowContainer passwordDescription;
|
||||
private ErrorTextFlowContainer usernameDescription = null!;
|
||||
private ErrorTextFlowContainer emailAddressDescription = null!;
|
||||
private ErrorTextFlowContainer passwordDescription = null!;
|
||||
|
||||
private OsuTextBox usernameTextBox;
|
||||
private OsuTextBox emailTextBox;
|
||||
private OsuPasswordTextBox passwordTextBox;
|
||||
private OsuTextBox usernameTextBox = null!;
|
||||
private OsuTextBox emailTextBox = null!;
|
||||
private OsuPasswordTextBox passwordTextBox = null!;
|
||||
|
||||
[Resolved]
|
||||
private IAPIProvider api { get; set; }
|
||||
private IAPIProvider api { get; set; } = null!;
|
||||
|
||||
private ShakeContainer registerShake;
|
||||
private ITextPart characterCheckText;
|
||||
private IBindable<APIState> apiState = null!;
|
||||
|
||||
private OsuTextBox[] textboxes;
|
||||
private LoadingLayer loadingLayer;
|
||||
private ShakeContainer registerShake = null!;
|
||||
private ITextPart characterCheckText = null!;
|
||||
|
||||
private OsuTextBox[] textboxes = null!;
|
||||
private LoadingLayer loadingLayer = null!;
|
||||
|
||||
[Resolved]
|
||||
private GameHost host { get; set; }
|
||||
private GameHost? host { get; set; }
|
||||
|
||||
[Resolved]
|
||||
private OsuGame game { get; set; }
|
||||
private OsuGame? game { get; set; }
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
@ -144,6 +145,8 @@ namespace osu.Game.Overlays.AccountCreation
|
||||
|
||||
passwordTextBox.Current.BindValueChanged(_ => updateCharacterCheckTextColour(), true);
|
||||
characterCheckText.DrawablePartsRecreated += _ => updateCharacterCheckTextColour();
|
||||
|
||||
apiState = api.State.GetBoundCopy();
|
||||
}
|
||||
|
||||
private void updateCharacterCheckTextColour()
|
||||
@ -180,7 +183,7 @@ namespace osu.Game.Overlays.AccountCreation
|
||||
Task.Run(() =>
|
||||
{
|
||||
bool success;
|
||||
RegistrationRequest.RegistrationRequestErrors errors = null;
|
||||
RegistrationRequest.RegistrationRequestErrors? errors = null;
|
||||
|
||||
try
|
||||
{
|
||||
@ -210,7 +213,7 @@ namespace osu.Game.Overlays.AccountCreation
|
||||
if (!string.IsNullOrEmpty(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
|
||||
@ -223,6 +226,12 @@ namespace osu.Game.Overlays.AccountCreation
|
||||
return;
|
||||
}
|
||||
|
||||
apiState.BindValueChanged(state =>
|
||||
{
|
||||
if (state.NewValue == APIState.RequiresSecondFactorAuth)
|
||||
this.Push(new ScreenEmailVerification());
|
||||
});
|
||||
|
||||
api.Login(usernameTextBox.Text, passwordTextBox.Text);
|
||||
});
|
||||
});
|
||||
@ -241,6 +250,6 @@ namespace osu.Game.Overlays.AccountCreation
|
||||
return false;
|
||||
}
|
||||
|
||||
private OsuTextBox nextUnfilledTextBox() => textboxes.FirstOrDefault(t => string.IsNullOrEmpty(t.Text));
|
||||
private OsuTextBox? nextUnfilledTextBox() => textboxes.FirstOrDefault(t => string.IsNullOrEmpty(t.Text));
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,6 @@
|
||||
// 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.
|
||||
|
||||
#nullable disable
|
||||
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
@ -23,14 +21,14 @@ namespace osu.Game.Overlays.AccountCreation
|
||||
{
|
||||
public partial class ScreenWarning : AccountCreationScreen
|
||||
{
|
||||
private OsuTextFlowContainer multiAccountExplanationText;
|
||||
private LinkFlowContainer furtherAssistance;
|
||||
private OsuTextFlowContainer multiAccountExplanationText = null!;
|
||||
private LinkFlowContainer furtherAssistance = null!;
|
||||
|
||||
[Resolved(canBeNull: true)]
|
||||
private IAPIProvider api { get; set; }
|
||||
[Resolved]
|
||||
private IAPIProvider? api { get; set; }
|
||||
|
||||
[Resolved(canBeNull: true)]
|
||||
private OsuGame game { get; set; }
|
||||
[Resolved]
|
||||
private OsuGame? game { get; set; }
|
||||
|
||||
private const string help_centre_url = "/help/wiki/Help_Centre#login";
|
||||
|
||||
|
@ -1,8 +1,6 @@
|
||||
// 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.
|
||||
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
@ -25,7 +23,9 @@ namespace osu.Game.Overlays
|
||||
{
|
||||
private const float transition_time = 400;
|
||||
|
||||
private ScreenWelcome welcomeScreen;
|
||||
private ScreenWelcome welcomeScreen = null!;
|
||||
|
||||
private ScheduledDelegate? scheduledHide;
|
||||
|
||||
public AccountCreationOverlay()
|
||||
{
|
||||
@ -108,8 +108,6 @@ namespace osu.Game.Overlays
|
||||
this.FadeOut(100);
|
||||
}
|
||||
|
||||
private ScheduledDelegate scheduledHide;
|
||||
|
||||
private void apiStateChanged(ValueChangedEvent<APIState> state)
|
||||
{
|
||||
switch (state.NewValue)
|
||||
|
Loading…
Reference in New Issue
Block a user