Merge pull request #19010 from peppy/forgotten-password-link

Add forgotten password link to login form
This commit is contained in:
Dan Balasescu 2022-07-06 13:55:18 +09:00 committed by GitHub
commit 73a5f9e911
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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.Extensions.LocalisationExtensions; using osu.Framework.Extensions.LocalisationExtensions;
@ -23,19 +21,19 @@ namespace osu.Game.Overlays.Login
{ {
public class LoginForm : FillFlowContainer public class LoginForm : FillFlowContainer
{ {
private TextBox username; private TextBox username = null!;
private TextBox password; private TextBox password = null!;
private ShakeContainer shakeSignIn; private ShakeContainer shakeSignIn = null!;
[Resolved(CanBeNull = true)] [Resolved]
private IAPIProvider api { get; set; } private IAPIProvider api { get; set; } = null!;
public Action RequestHide; public Action? RequestHide;
private void performLogin() private void performLogin()
{ {
if (!string.IsNullOrEmpty(username.Text) && !string.IsNullOrEmpty(password.Text)) if (!string.IsNullOrEmpty(username.Text) && !string.IsNullOrEmpty(password.Text))
api?.Login(username.Text, password.Text); api.Login(username.Text, password.Text);
else else
shakeSignIn.Shake(); shakeSignIn.Shake();
} }
@ -49,6 +47,7 @@ namespace osu.Game.Overlays.Login
RelativeSizeAxes = Axes.X; RelativeSizeAxes = Axes.X;
ErrorTextFlowContainer errorText; ErrorTextFlowContainer errorText;
LinkFlowContainer forgottenPaswordLink;
Children = new Drawable[] Children = new Drawable[]
{ {
@ -56,7 +55,7 @@ namespace osu.Game.Overlays.Login
{ {
PlaceholderText = UsersStrings.LoginUsername.ToLower(), PlaceholderText = UsersStrings.LoginUsername.ToLower(),
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
Text = api?.ProvidedUsername ?? string.Empty, Text = api.ProvidedUsername,
TabbableContentContainer = this TabbableContentContainer = this
}, },
password = new OsuPasswordTextBox password = new OsuPasswordTextBox
@ -80,6 +79,12 @@ namespace osu.Game.Overlays.Login
LabelText = "Stay signed in", LabelText = "Stay signed in",
Current = config.GetBindable<bool>(OsuSetting.SavePassword), Current = config.GetBindable<bool>(OsuSetting.SavePassword),
}, },
forgottenPaswordLink = new LinkFlowContainer
{
Padding = new MarginPadding { Left = SettingsPanel.CONTENT_MARGINS },
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
},
new Container new Container
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
@ -103,15 +108,17 @@ namespace osu.Game.Overlays.Login
Text = "Register", Text = "Register",
Action = () => Action = () =>
{ {
RequestHide(); RequestHide?.Invoke();
accountCreation.Show(); accountCreation.Show();
} }
} }
}; };
forgottenPaswordLink.AddLink(LayoutStrings.PopupLoginLoginForgot, $"{api.WebsiteRootUrl}/home/password-reset");
password.OnCommit += (_, _) => performLogin(); password.OnCommit += (_, _) => performLogin();
if (api?.LastLoginError?.Message is string error) if (api.LastLoginError?.Message is string error)
errorText.AddErrors(new[] { error }); errorText.AddErrors(new[] { error });
} }