1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-14 02:13:21 +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() public void Logout()
{ {
ClearCredentials();
authentication.Clear(); authentication.Clear();
State = APIState.Offline; State = APIState.Offline;
} }

View File

@ -14,6 +14,7 @@ namespace osu.Game.Overlays.Options.General
public class LoginOptions : OptionsSubsection, IOnlineComponent public class LoginOptions : OptionsSubsection, IOnlineComponent
{ {
private Container loginForm; private Container loginForm;
private APIAccess api;
protected override string Header => "Sign In"; protected override string Header => "Sign In";
public LoginOptions() public LoginOptions()
@ -32,6 +33,7 @@ namespace osu.Game.Overlays.Options.General
[BackgroundDependencyLoader(permitNulls: true)] [BackgroundDependencyLoader(permitNulls: true)]
private void load(APIAccess api) private void load(APIAccess api)
{ {
this.api = api;
api?.Register(this); api?.Register(this);
} }
@ -70,11 +72,22 @@ namespace osu.Game.Overlays.Options.General
{ {
Text = $@"Connected as {api.Username}!", Text = $@"Connected as {api.Username}!",
}, },
new OsuButton
{
RelativeSizeAxes = Axes.X,
Text = "Sign out",
Action = performLogout
}
}; };
break; break;
} }
} }
private void performLogout()
{
api.Logout();
}
class LoginForm : FlowContainer class LoginForm : FlowContainer
{ {
private APIAccess api; private APIAccess api;
@ -106,7 +119,8 @@ namespace osu.Game.Overlays.Options.General
private void performLogin() 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)] [BackgroundDependencyLoader(permitNulls: true)]