2021-09-20 03:09:03 +08:00
|
|
|
// 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.
|
|
|
|
|
2021-09-17 17:30:38 +08:00
|
|
|
using System;
|
|
|
|
using osu.Framework.Allocation;
|
2022-04-24 16:11:25 +08:00
|
|
|
using osu.Framework.Extensions.LocalisationExtensions;
|
2021-09-17 17:30:38 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
|
|
|
using osu.Framework.Input.Events;
|
|
|
|
using osu.Game.Configuration;
|
2021-10-04 14:40:24 +08:00
|
|
|
using osu.Game.Graphics;
|
2021-09-17 17:30:38 +08:00
|
|
|
using osu.Game.Graphics.Containers;
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
|
|
|
using osu.Game.Online.API;
|
|
|
|
using osu.Game.Overlays.Settings;
|
2022-01-28 12:53:48 +08:00
|
|
|
using osu.Game.Resources.Localisation.Web;
|
2021-09-17 17:30:38 +08:00
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Login
|
|
|
|
{
|
|
|
|
public partial class LoginForm : FillFlowContainer
|
|
|
|
{
|
2022-07-06 00:29:00 +08:00
|
|
|
private TextBox username = null!;
|
|
|
|
private TextBox password = null!;
|
|
|
|
private ShakeContainer shakeSignIn = null!;
|
2021-09-17 17:30:38 +08:00
|
|
|
|
2022-07-06 00:29:00 +08:00
|
|
|
[Resolved]
|
|
|
|
private IAPIProvider api { get; set; } = null!;
|
2021-09-17 17:30:38 +08:00
|
|
|
|
2022-07-06 00:29:00 +08:00
|
|
|
public Action? RequestHide;
|
2021-09-17 17:30:38 +08:00
|
|
|
|
|
|
|
private void performLogin()
|
|
|
|
{
|
|
|
|
if (!string.IsNullOrEmpty(username.Text) && !string.IsNullOrEmpty(password.Text))
|
2022-07-06 00:29:00 +08:00
|
|
|
api.Login(username.Text, password.Text);
|
2021-09-17 17:30:38 +08:00
|
|
|
else
|
|
|
|
shakeSignIn.Shake();
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader(permitNulls: true)]
|
|
|
|
private void load(OsuConfigManager config, AccountCreationOverlay accountCreation)
|
|
|
|
{
|
|
|
|
Direction = FillDirection.Vertical;
|
|
|
|
Spacing = new Vector2(0, 5);
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
RelativeSizeAxes = Axes.X;
|
2021-10-04 14:40:24 +08:00
|
|
|
|
|
|
|
ErrorTextFlowContainer errorText;
|
2022-07-06 00:25:04 +08:00
|
|
|
LinkFlowContainer forgottenPaswordLink;
|
2021-10-04 14:40:24 +08:00
|
|
|
|
2021-09-17 17:30:38 +08:00
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
username = new OsuTextBox
|
|
|
|
{
|
2022-04-24 16:11:25 +08:00
|
|
|
PlaceholderText = UsersStrings.LoginUsername.ToLower(),
|
2021-09-17 17:30:38 +08:00
|
|
|
RelativeSizeAxes = Axes.X,
|
2022-07-06 00:29:00 +08:00
|
|
|
Text = api.ProvidedUsername,
|
2021-09-17 17:30:38 +08:00
|
|
|
TabbableContentContainer = this
|
|
|
|
},
|
|
|
|
password = new OsuPasswordTextBox
|
|
|
|
{
|
2022-04-24 16:11:25 +08:00
|
|
|
PlaceholderText = UsersStrings.LoginPassword.ToLower(),
|
2021-09-17 17:30:38 +08:00
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
TabbableContentContainer = this,
|
|
|
|
},
|
2021-10-04 14:40:24 +08:00
|
|
|
errorText = new ErrorTextFlowContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
},
|
2021-09-17 17:30:38 +08:00
|
|
|
new SettingsCheckbox
|
|
|
|
{
|
|
|
|
LabelText = "Remember username",
|
|
|
|
Current = config.GetBindable<bool>(OsuSetting.SaveUsername),
|
|
|
|
},
|
|
|
|
new SettingsCheckbox
|
|
|
|
{
|
|
|
|
LabelText = "Stay signed in",
|
|
|
|
Current = config.GetBindable<bool>(OsuSetting.SavePassword),
|
|
|
|
},
|
2022-07-06 00:25:04 +08:00
|
|
|
forgottenPaswordLink = new LinkFlowContainer
|
|
|
|
{
|
|
|
|
Padding = new MarginPadding { Left = SettingsPanel.CONTENT_MARGINS },
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
},
|
2021-09-17 17:30:38 +08:00
|
|
|
new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
shakeSignIn = new ShakeContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
Child = new SettingsButton
|
|
|
|
{
|
2022-01-28 12:53:48 +08:00
|
|
|
Text = UsersStrings.LoginButton,
|
2021-09-17 17:30:38 +08:00
|
|
|
Action = performLogin
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
new SettingsButton
|
|
|
|
{
|
|
|
|
Text = "Register",
|
|
|
|
Action = () =>
|
|
|
|
{
|
2022-07-06 00:29:00 +08:00
|
|
|
RequestHide?.Invoke();
|
2021-09-17 17:30:38 +08:00
|
|
|
accountCreation.Show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-07-06 00:29:00 +08:00
|
|
|
forgottenPaswordLink.AddLink(LayoutStrings.PopupLoginLoginForgot, $"{api.WebsiteRootUrl}/home/password-reset");
|
2022-07-06 00:25:04 +08:00
|
|
|
|
2022-06-24 20:25:23 +08:00
|
|
|
password.OnCommit += (_, _) => performLogin();
|
2021-10-04 14:40:24 +08:00
|
|
|
|
2022-07-06 00:29:00 +08:00
|
|
|
if (api.LastLoginError?.Message is string error)
|
2021-10-04 14:40:24 +08:00
|
|
|
errorText.AddErrors(new[] { error });
|
2021-09-17 17:30:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public override bool AcceptsFocus => true;
|
|
|
|
|
|
|
|
protected override bool OnClick(ClickEvent e) => true;
|
|
|
|
|
|
|
|
protected override void OnFocus(FocusEvent e)
|
|
|
|
{
|
|
|
|
Schedule(() => { GetContainingInputManager().ChangeFocus(string.IsNullOrEmpty(username.Text) ? username : password); });
|
|
|
|
}
|
|
|
|
}
|
2021-10-04 14:40:24 +08:00
|
|
|
}
|