2019-01-24 16:43: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.
|
2018-12-06 10:58:09 +08:00
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2018-12-06 10:58:09 +08:00
|
|
|
using System;
|
2018-12-06 13:57:00 +08:00
|
|
|
using System.Linq;
|
2018-12-06 10:58:09 +08:00
|
|
|
using System.Threading.Tasks;
|
|
|
|
using osu.Framework.Allocation;
|
2022-06-03 11:30:56 +08:00
|
|
|
using osu.Framework.Extensions.LocalisationExtensions;
|
2018-12-06 10:58:09 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2023-01-17 18:31:03 +08:00
|
|
|
using osu.Framework.Localisation;
|
2020-01-09 12:43:44 +08:00
|
|
|
using osu.Framework.Utils;
|
2019-01-29 16:01:53 +08:00
|
|
|
using osu.Framework.Platform;
|
2018-12-06 15:29:41 +08:00
|
|
|
using osu.Framework.Screens;
|
2018-12-06 10:58:09 +08:00
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Containers;
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2023-01-17 02:31:01 +08:00
|
|
|
using osu.Game.Localisation;
|
2018-12-06 10:58:09 +08:00
|
|
|
using osu.Game.Online.API;
|
|
|
|
using osu.Game.Overlays.Settings;
|
2022-01-28 12:53:48 +08:00
|
|
|
using osu.Game.Resources.Localisation.Web;
|
2018-12-06 10:58:09 +08:00
|
|
|
using osuTK;
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.AccountCreation
|
|
|
|
{
|
|
|
|
public partial class ScreenEntry : AccountCreationScreen
|
|
|
|
{
|
|
|
|
private ErrorTextFlowContainer usernameDescription;
|
|
|
|
private ErrorTextFlowContainer emailAddressDescription;
|
|
|
|
private ErrorTextFlowContainer passwordDescription;
|
|
|
|
|
|
|
|
private OsuTextBox usernameTextBox;
|
|
|
|
private OsuTextBox emailTextBox;
|
|
|
|
private OsuPasswordTextBox passwordTextBox;
|
|
|
|
|
2020-02-14 21:14:00 +08:00
|
|
|
[Resolved]
|
|
|
|
private IAPIProvider api { get; set; }
|
|
|
|
|
2018-12-06 10:58:09 +08:00
|
|
|
private ShakeContainer registerShake;
|
2021-08-01 23:12:04 +08:00
|
|
|
private ITextPart characterCheckText;
|
2018-12-06 10:58:09 +08:00
|
|
|
|
2018-12-06 13:57:00 +08:00
|
|
|
private OsuTextBox[] textboxes;
|
2020-02-21 14:31:40 +08:00
|
|
|
private LoadingLayer loadingLayer;
|
2020-02-14 21:14:00 +08:00
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private GameHost host { get; set; }
|
2018-12-06 10:58:09 +08:00
|
|
|
|
2023-01-13 14:36:45 +08:00
|
|
|
[Resolved]
|
|
|
|
private OsuGame game { get; set; }
|
|
|
|
|
2018-12-06 10:58:09 +08:00
|
|
|
[BackgroundDependencyLoader]
|
2023-01-17 18:31:03 +08:00
|
|
|
private void load(LocalisationManager localisationManager)
|
2018-12-06 10:58:09 +08:00
|
|
|
{
|
2019-01-23 19:52:00 +08:00
|
|
|
InternalChildren = new Drawable[]
|
2018-12-06 10:58:09 +08:00
|
|
|
{
|
2021-01-06 05:39:59 +08:00
|
|
|
new FillFlowContainer
|
2018-12-06 10:58:09 +08:00
|
|
|
{
|
2018-12-06 15:29:41 +08:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
Padding = new MarginPadding(20),
|
|
|
|
Spacing = new Vector2(0, 10),
|
|
|
|
Children = new Drawable[]
|
2018-12-06 10:58:09 +08:00
|
|
|
{
|
2018-12-06 15:29:41 +08:00
|
|
|
new OsuSpriteText
|
2018-12-06 10:58:09 +08:00
|
|
|
{
|
2018-12-06 15:29:41 +08:00
|
|
|
Margin = new MarginPadding { Vertical = 10 },
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre,
|
2019-02-12 12:04:46 +08:00
|
|
|
Font = OsuFont.GetFont(size: 20),
|
2023-01-17 02:31:01 +08:00
|
|
|
Text = AccountCreationStrings.LetsCreateAnAccount
|
2018-12-06 15:29:41 +08:00
|
|
|
},
|
|
|
|
usernameTextBox = new OsuTextBox
|
|
|
|
{
|
2022-06-03 11:30:56 +08:00
|
|
|
PlaceholderText = UsersStrings.LoginUsername.ToLower(),
|
2018-12-06 15:29:41 +08:00
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
TabbableContentContainer = this
|
|
|
|
},
|
|
|
|
usernameDescription = new ErrorTextFlowContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y
|
|
|
|
},
|
|
|
|
emailTextBox = new OsuTextBox
|
|
|
|
{
|
2023-01-17 03:24:03 +08:00
|
|
|
PlaceholderText = ModelValidationStrings.UserAttributesUserEmail.ToLower(),
|
2018-12-06 15:29:41 +08:00
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
TabbableContentContainer = this
|
|
|
|
},
|
|
|
|
emailAddressDescription = new ErrorTextFlowContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y
|
|
|
|
},
|
|
|
|
passwordTextBox = new OsuPasswordTextBox
|
|
|
|
{
|
2022-06-03 11:30:56 +08:00
|
|
|
PlaceholderText = UsersStrings.LoginPassword.ToLower(),
|
2018-12-06 15:29:41 +08:00
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
TabbableContentContainer = this,
|
|
|
|
},
|
|
|
|
passwordDescription = new ErrorTextFlowContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y
|
|
|
|
},
|
|
|
|
new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
Children = new Drawable[]
|
2018-12-06 10:58:09 +08:00
|
|
|
{
|
2018-12-06 15:29:41 +08:00
|
|
|
registerShake = new ShakeContainer
|
2018-12-06 10:58:09 +08:00
|
|
|
{
|
2018-12-06 15:29:41 +08:00
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
Child = new SettingsButton
|
|
|
|
{
|
2023-01-17 02:31:01 +08:00
|
|
|
Text = LoginPanelStrings.Register,
|
2018-12-06 15:29:41 +08:00
|
|
|
Margin = new MarginPadding { Vertical = 20 },
|
|
|
|
Action = performRegistration
|
|
|
|
}
|
2018-12-06 10:58:09 +08:00
|
|
|
}
|
|
|
|
}
|
2018-12-06 15:29:41 +08:00
|
|
|
},
|
2018-12-06 10:58:09 +08:00
|
|
|
},
|
2018-12-06 15:29:41 +08:00
|
|
|
},
|
2021-01-04 21:42:39 +08:00
|
|
|
loadingLayer = new LoadingLayer(true)
|
2018-12-06 10:58:09 +08:00
|
|
|
};
|
|
|
|
|
2018-12-06 13:57:00 +08:00
|
|
|
textboxes = new[] { usernameTextBox, emailTextBox, passwordTextBox };
|
|
|
|
|
2023-01-17 02:31:01 +08:00
|
|
|
usernameDescription.AddText(AccountCreationStrings.ThisWillBeYourPublic);
|
2018-12-06 10:58:09 +08:00
|
|
|
|
2023-01-17 02:31:01 +08:00
|
|
|
emailAddressDescription.AddText(AccountCreationStrings.EmailUsage);
|
|
|
|
emailAddressDescription.AddText(AccountCreationStrings.MakeSureToGetIt, cp => cp.Font = cp.Font.With(Typeface.Torus, weight: FontWeight.Bold));
|
2018-12-06 10:58:09 +08:00
|
|
|
|
2023-01-17 18:31:03 +08:00
|
|
|
string[] passwordReq = localisationManager.GetLocalisedBindableString(AccountCreationStrings.PasswordRequirements("{}")).Value.Split("{}");
|
|
|
|
if (passwordReq.Length != 2) passwordReq = AccountCreationStrings.PasswordRequirements("{}").ToString().Split("{}");
|
|
|
|
|
|
|
|
passwordDescription.AddText(passwordReq[0]);
|
2023-01-17 02:31:01 +08:00
|
|
|
characterCheckText = passwordDescription.AddText(AccountCreationStrings.CharactersLong);
|
2023-01-17 18:31:03 +08:00
|
|
|
passwordDescription.AddText(passwordReq[1]);
|
2018-12-06 10:58:09 +08:00
|
|
|
|
2021-11-01 22:44:51 +08:00
|
|
|
passwordTextBox.Current.BindValueChanged(_ => updateCharacterCheckTextColour(), true);
|
|
|
|
characterCheckText.DrawablePartsRecreated += _ => updateCharacterCheckTextColour();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateCharacterCheckTextColour()
|
|
|
|
{
|
|
|
|
string password = passwordTextBox.Text;
|
|
|
|
|
|
|
|
foreach (var d in characterCheckText.Drawables)
|
|
|
|
d.Colour = password.Length == 0 ? Color4.White : Interpolation.ValueAt(password.Length, Color4.OrangeRed, Color4.YellowGreen, 0, 8, Easing.In);
|
2018-12-06 10:58:09 +08:00
|
|
|
}
|
|
|
|
|
2022-04-21 23:52:44 +08:00
|
|
|
public override void OnEntering(ScreenTransitionEvent e)
|
2018-12-06 15:29:41 +08:00
|
|
|
{
|
2022-04-21 23:52:44 +08:00
|
|
|
base.OnEntering(e);
|
2020-02-21 14:31:40 +08:00
|
|
|
loadingLayer.Hide();
|
2019-10-23 05:40:56 +08:00
|
|
|
|
2019-10-23 10:51:29 +08:00
|
|
|
if (host?.OnScreenKeyboardOverlapsGameWindow != true)
|
2021-12-10 13:15:00 +08:00
|
|
|
focusNextTextBox();
|
2018-12-06 15:29:41 +08:00
|
|
|
}
|
|
|
|
|
2018-12-06 13:57:00 +08:00
|
|
|
private void performRegistration()
|
|
|
|
{
|
2021-12-10 13:15:00 +08:00
|
|
|
if (focusNextTextBox())
|
2018-12-06 10:58:09 +08:00
|
|
|
{
|
|
|
|
registerShake.Shake();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
usernameDescription.ClearErrors();
|
|
|
|
emailAddressDescription.ClearErrors();
|
|
|
|
passwordDescription.ClearErrors();
|
|
|
|
|
2020-02-21 14:31:40 +08:00
|
|
|
loadingLayer.Show();
|
2018-12-06 15:29:41 +08:00
|
|
|
|
2018-12-06 10:58:09 +08:00
|
|
|
Task.Run(() =>
|
|
|
|
{
|
|
|
|
bool success;
|
|
|
|
RegistrationRequest.RegistrationRequestErrors errors = null;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
errors = api.CreateAccount(emailTextBox.Text, usernameTextBox.Text, passwordTextBox.Text);
|
|
|
|
success = errors == null;
|
|
|
|
}
|
|
|
|
catch (Exception)
|
|
|
|
{
|
|
|
|
success = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Schedule(() =>
|
|
|
|
{
|
|
|
|
if (!success)
|
|
|
|
{
|
|
|
|
if (errors != null)
|
|
|
|
{
|
2023-01-13 14:36:45 +08:00
|
|
|
if (errors.User != null)
|
|
|
|
{
|
|
|
|
usernameDescription.AddErrors(errors.User.Username);
|
|
|
|
emailAddressDescription.AddErrors(errors.User.Email);
|
|
|
|
passwordDescription.AddErrors(errors.User.Password);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(errors.Redirect))
|
|
|
|
{
|
|
|
|
if (!string.IsNullOrEmpty(errors.Message))
|
|
|
|
passwordDescription.AddErrors(new[] { errors.Message });
|
|
|
|
|
2023-01-13 14:42:34 +08:00
|
|
|
game.OpenUrlExternally($"{errors.Redirect}?username={usernameTextBox.Text}&email={emailTextBox.Text}");
|
2023-01-13 14:36:45 +08:00
|
|
|
}
|
2018-12-06 10:58:09 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
passwordDescription.AddErrors(new[] { "Something happened... but we're not sure what." });
|
|
|
|
}
|
|
|
|
|
|
|
|
registerShake.Shake();
|
2020-02-21 14:31:40 +08:00
|
|
|
loadingLayer.Hide();
|
2018-12-06 10:58:09 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-01-04 13:52:07 +08:00
|
|
|
api.Login(usernameTextBox.Text, passwordTextBox.Text);
|
2018-12-06 10:58:09 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-12-10 13:15:00 +08:00
|
|
|
private bool focusNextTextBox()
|
2018-12-06 10:58:09 +08:00
|
|
|
{
|
2021-12-10 13:15:00 +08:00
|
|
|
var nextTextBox = nextUnfilledTextBox();
|
2019-04-01 11:16:05 +08:00
|
|
|
|
2021-12-10 13:15:00 +08:00
|
|
|
if (nextTextBox != null)
|
2018-12-06 10:58:09 +08:00
|
|
|
{
|
2021-12-10 13:15:00 +08:00
|
|
|
Schedule(() => GetContainingInputManager().ChangeFocus(nextTextBox));
|
2018-12-06 13:57:00 +08:00
|
|
|
return true;
|
2018-12-06 10:58:09 +08:00
|
|
|
}
|
|
|
|
|
2018-12-06 13:57:00 +08:00
|
|
|
return false;
|
2018-12-06 10:58:09 +08:00
|
|
|
}
|
2018-12-06 13:57:00 +08:00
|
|
|
|
2021-12-10 13:15:00 +08:00
|
|
|
private OsuTextBox nextUnfilledTextBox() => textboxes.FirstOrDefault(t => string.IsNullOrEmpty(t.Text));
|
2018-12-06 10:58:09 +08:00
|
|
|
}
|
|
|
|
}
|