1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 06:47:24 +08:00

Add logout button and check for inputs before allowing login.

This commit is contained in:
Dean Herbert 2016-11-30 19:43:03 +09:00
parent 01dc7cb5c2
commit ed879f33df
2 changed files with 27 additions and 12 deletions

View File

@ -281,6 +281,7 @@ namespace osu.Game.Online.API
public void Logout()
{
ClearCredentials();
authentication.Clear();
State = APIState.Offline;
}

View File

@ -14,6 +14,7 @@ namespace osu.Game.Overlays.Options.General
public class LoginOptions : OptionsSubsection, IOnlineComponent
{
private Container loginForm;
private APIAccess api;
protected override string Header => "Sign In";
public LoginOptions()
@ -32,6 +33,7 @@ namespace osu.Game.Overlays.Options.General
[BackgroundDependencyLoader(permitNulls: true)]
private void load(APIAccess api)
{
this.api = api;
api?.Register(this);
}
@ -48,33 +50,44 @@ namespace osu.Game.Overlays.Options.General
case APIState.Failing:
loginForm.Children = new Drawable[]
{
new SpriteText
{
Text = @"Connection failing :(",
new SpriteText
{
Text = @"Connection failing :(",
},
};
break;
case APIState.Connecting:
loginForm.Children = new Drawable[]
{
new SpriteText
{
Text = @"Connecting...",
new SpriteText
{
Text = @"Connecting...",
},
};
break;
case APIState.Online:
loginForm.Children = new Drawable[]
{
new SpriteText
{
Text = $@"Connected as {api.Username}!",
new SpriteText
{
Text = $@"Connected as {api.Username}!",
},
new OsuButton
{
RelativeSizeAxes = Axes.X,
Text = "Sign out",
Action = performLogout
}
};
break;
}
}
}
private void performLogout()
{
api.Logout();
}
class LoginForm : FlowContainer
{
private APIAccess api;
@ -106,7 +119,8 @@ namespace osu.Game.Overlays.Options.General
private void performLogin()
{
api.Login(username.Text, password.Text);
if (!string.IsNullOrEmpty(username.Text) && !string.IsNullOrEmpty(password.Text))
api.Login(username.Text, password.Text);
}
[BackgroundDependencyLoader(permitNulls: true)]