mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 23:07:26 +08:00
Merge pull request #22172 from peppy/create-account-redirect-support
Add support for redirection to website during account creation process
This commit is contained in:
commit
0c1561bc82
@ -329,12 +329,35 @@ namespace osu.Game.Online.API
|
||||
{
|
||||
try
|
||||
{
|
||||
return JObject.Parse(req.GetResponseString().AsNonNull()).SelectToken("form_error", true).AsNonNull().ToObject<RegistrationRequest.RegistrationRequestErrors>();
|
||||
return JObject.Parse(req.GetResponseString().AsNonNull()).SelectToken(@"form_error", true).AsNonNull().ToObject<RegistrationRequest.RegistrationRequestErrors>();
|
||||
}
|
||||
catch
|
||||
{
|
||||
// if we couldn't deserialize the error message let's throw the original exception outwards.
|
||||
e.Rethrow();
|
||||
try
|
||||
{
|
||||
// attempt to parse a non-form error message
|
||||
var response = JObject.Parse(req.GetResponseString().AsNonNull());
|
||||
|
||||
string redirect = (string)response.SelectToken(@"url", true);
|
||||
string message = (string)response.SelectToken(@"error", false);
|
||||
|
||||
if (!string.IsNullOrEmpty(redirect))
|
||||
{
|
||||
return new RegistrationRequest.RegistrationRequestErrors
|
||||
{
|
||||
Redirect = redirect,
|
||||
Message = message,
|
||||
};
|
||||
}
|
||||
|
||||
// if we couldn't deserialize the error message let's throw the original exception outwards.
|
||||
e.Rethrow();
|
||||
}
|
||||
catch
|
||||
{
|
||||
// if we couldn't deserialize the error message let's throw the original exception outwards.
|
||||
e.Rethrow();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,17 +1,16 @@
|
||||
// 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 Newtonsoft.Json;
|
||||
|
||||
namespace osu.Game.Online.API
|
||||
{
|
||||
public class RegistrationRequest : OsuWebRequest
|
||||
{
|
||||
internal string Username;
|
||||
internal string Email;
|
||||
internal string Password;
|
||||
internal string Username = string.Empty;
|
||||
internal string Email = string.Empty;
|
||||
internal string Password = string.Empty;
|
||||
|
||||
protected override void PrePerform()
|
||||
{
|
||||
@ -24,18 +23,28 @@ namespace osu.Game.Online.API
|
||||
|
||||
public class RegistrationRequestErrors
|
||||
{
|
||||
public UserErrors User;
|
||||
/// <summary>
|
||||
/// An optional error message.
|
||||
/// </summary>
|
||||
public string? Message;
|
||||
|
||||
/// <summary>
|
||||
/// An optional URL which the user should be directed towards to complete registration.
|
||||
/// </summary>
|
||||
public string? Redirect;
|
||||
|
||||
public UserErrors? User;
|
||||
|
||||
public class UserErrors
|
||||
{
|
||||
[JsonProperty("username")]
|
||||
public string[] Username;
|
||||
public string[] Username = Array.Empty<string>();
|
||||
|
||||
[JsonProperty("user_email")]
|
||||
public string[] Email;
|
||||
public string[] Email = Array.Empty<string>();
|
||||
|
||||
[JsonProperty("password")]
|
||||
public string[] Password;
|
||||
public string[] Password = Array.Empty<string>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -47,6 +47,9 @@ namespace osu.Game.Overlays.AccountCreation
|
||||
[Resolved]
|
||||
private GameHost host { get; set; }
|
||||
|
||||
[Resolved]
|
||||
private OsuGame game { get; set; }
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
@ -194,9 +197,20 @@ namespace osu.Game.Overlays.AccountCreation
|
||||
{
|
||||
if (errors != null)
|
||||
{
|
||||
usernameDescription.AddErrors(errors.User.Username);
|
||||
emailAddressDescription.AddErrors(errors.User.Email);
|
||||
passwordDescription.AddErrors(errors.User.Password);
|
||||
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 });
|
||||
|
||||
game.OpenUrlExternally($"{errors.Redirect}?username={usernameTextBox.Text}&email={emailTextBox.Text}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user