diff --git a/osu.Game/Online/API/APIAccess.cs b/osu.Game/Online/API/APIAccess.cs
index bab53cb462..40584006cd 100644
--- a/osu.Game/Online/API/APIAccess.cs
+++ b/osu.Game/Online/API/APIAccess.cs
@@ -10,6 +10,7 @@ using System.Threading;
using osu.Framework.Configuration;
using osu.Framework.Logging;
using osu.Framework.Threading;
+using osu.Game.Configuration;
using osu.Game.Online.API.Requests;
using osu.Game.Users;
@@ -17,6 +18,7 @@ namespace osu.Game.Online.API
{
public class APIAccess : IAPIProvider
{
+ private readonly OsuConfigManager config;
private readonly OAuth authentication;
public string Endpoint = @"https://osu.ppy.sh";
@@ -27,11 +29,12 @@ namespace osu.Game.Online.API
public Scheduler Scheduler = new Scheduler();
- public string Username;
+ ///
+ /// The username/email provided by the user when initiating a login.
+ ///
+ public string ProvidedUsername { get; private set; }
- //private SecurePassword password;
-
- public string Password;
+ private string password;
public Bindable LocalUser { get; } = new Bindable(createGuestUser());
@@ -41,18 +44,23 @@ namespace osu.Game.Online.API
set { authentication.Token = string.IsNullOrEmpty(value) ? null : OAuthToken.Parse(value); }
}
- protected bool HasLogin => Token != null || !string.IsNullOrEmpty(Username) && !string.IsNullOrEmpty(Password);
+ protected bool HasLogin => Token != null || !string.IsNullOrEmpty(ProvidedUsername) && !string.IsNullOrEmpty(password);
// ReSharper disable once PrivateFieldCanBeConvertedToLocalVariable (should dispose of this or at very least keep a reference).
private readonly Thread thread;
private readonly Logger log;
- public APIAccess()
+ public APIAccess(OsuConfigManager config)
{
+ this.config = config;
+
authentication = new OAuth(client_id, client_secret, Endpoint);
log = Logger.GetLogger(LoggingTarget.Network);
+ ProvidedUsername = config.Get(OsuSetting.Username);
+ Token = config.Get(OsuSetting.Token);
+
thread = new Thread(run) { IsBackground = true };
thread.Start();
}
@@ -111,12 +119,15 @@ namespace osu.Game.Online.API
State = APIState.Connecting;
- if (!authentication.HasValidAccessToken && !authentication.AuthenticateWithLogin(Username, Password))
+ // save the username at this point, if the user requested for it to be.
+ config.Set(OsuSetting.Username, config.Get(OsuSetting.SaveUsername) ? ProvidedUsername : string.Empty);
+
+ if (!authentication.HasValidAccessToken && !authentication.AuthenticateWithLogin(ProvidedUsername, password))
{
//todo: this fails even on network-related issues. we should probably handle those differently.
//NotificationOverlay.ShowMessage("Login failed!");
log.Add(@"Login failed!");
- Password = null;
+ password = null;
authentication.Clear();
continue;
}
@@ -173,8 +184,8 @@ namespace osu.Game.Online.API
{
Debug.Assert(State == APIState.Offline);
- Username = username;
- Password = password;
+ ProvidedUsername = username;
+ this.password = password;
}
///
@@ -283,8 +294,8 @@ namespace osu.Game.Online.API
public void Logout(bool clearUsername = true)
{
flushQueue();
- if (clearUsername) Username = null;
- Password = null;
+ if (clearUsername) ProvidedUsername = null;
+ password = null;
authentication.Clear();
LocalUser.Value = createGuestUser();
}
diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs
index f3c46269d5..2096318a32 100644
--- a/osu.Game/OsuGameBase.cs
+++ b/osu.Game/OsuGameBase.cs
@@ -34,7 +34,7 @@ using osu.Game.Skinning;
namespace osu.Game
{
- public class OsuGameBase : Framework.Game, IOnlineComponent, ICanAcceptFiles
+ public class OsuGameBase : Framework.Game, ICanAcceptFiles
{
protected OsuConfigManager LocalConfig;
@@ -108,11 +108,7 @@ namespace osu.Game
dependencies.Cache(SkinManager = new SkinManager(Host.Storage, contextFactory, Host, Audio));
- dependencies.Cache(API = new APIAccess
- {
- Username = LocalConfig.Get(OsuSetting.Username),
- Token = LocalConfig.Get(OsuSetting.Token)
- });
+ dependencies.Cache(API = new APIAccess(LocalConfig));
dependencies.CacheAs(API);
dependencies.Cache(RulesetStore = new RulesetStore(contextFactory));
@@ -183,8 +179,6 @@ namespace osu.Game
lastBeatmap = b;
};
- API.Register(this);
-
FileStore.Cleanup();
}
@@ -211,16 +205,6 @@ namespace osu.Game
private WorkingBeatmap lastBeatmap;
- public void APIStateChanged(APIAccess api, APIState state)
- {
- switch (state)
- {
- case APIState.Online:
- LocalConfig.Set(OsuSetting.Username, LocalConfig.Get(OsuSetting.SaveUsername) ? API.Username : string.Empty);
- break;
- }
- }
-
protected override void LoadComplete()
{
base.LoadComplete();
diff --git a/osu.Game/Overlays/Settings/Sections/General/LoginSettings.cs b/osu.Game/Overlays/Settings/Sections/General/LoginSettings.cs
index a5d068adbd..4a4fc7363e 100644
--- a/osu.Game/Overlays/Settings/Sections/General/LoginSettings.cs
+++ b/osu.Game/Overlays/Settings/Sections/General/LoginSettings.cs
@@ -210,7 +210,7 @@ namespace osu.Game.Overlays.Settings.Sections.General
{
PlaceholderText = "Email address",
RelativeSizeAxes = Axes.X,
- Text = api?.Username ?? string.Empty,
+ Text = api?.ProvidedUsername ?? string.Empty,
TabbableContentContainer = this
},
password = new OsuPasswordTextBox