public static Task <bool> IsLoggedInAsync(bool allowOffline = true) { EnsureInitialized(); return(Task.Run(() => { //try the request try { if (SessionKey == null) { return false; } var resp = Rest.DoPost <bool>("Key/Validate", new { SessionKey = SessionKey }); return resp.Data; } catch (UnableToAccessAccountServerException) { //Check offline if (!allowOffline) { return false; } if (User != null) { return true; //The cached data is correct } } return false; })); }
private static LoginResult LoginAsyncBody(string email, string pass) { Rest.Model <LoginResponse> resp = null; //PLEASE, FOR THE LOVE OF GOD, NEVER ENABLE OPTIMIZATION. IT WILL DESTROY THIS CODE resp = Rest.DoPost <LoginResponse>("Login", new Dictionary <string, string>() { { "emailAddress", email }, { "password", pass } }); if (resp.Message == "email_not_confirmed") { throw new AccountEmailNotConfirmedException(); } if (resp.Message == "username_or_password_incorrect") { throw new AccountDetailsIncorrectException(); } if (!resp.Error) { StoredData.SessionKey = resp.Data.SessionKey; UpdateUserInfo(); } return(new LoginResult() { Expires = resp.Data.ExpiryDate, FullUserInfo = User }); }
public static Task LogOutAsync() { EnsureInitialized(); return(Task.Run(() => { if (SessionKey == null) { return; } var resp = Rest.DoPost("Logout", new { SessionKey = SessionKey }); StoredData = new PersistentStorageData(); RaiseStorageChanged(); })); }
public static Task UpdateUserInfoAsync() { return(Task.Run(() => { //Redownload the user info from the account server var accountData = Rest.DoPost <FullUserInfo>("Key/Validate/Info", new { SessionKey = SessionKey }); if (accountData.Data == null) //Welp, something happened that shouldn't have { throw new NotLoggedInException(); } StoredData.CachedInfo = accountData.Data; })); }
public static Task InitializeAsync(string persistentData = null) { return(Task.Run(() => { if (persistentData != null) { PersistentData = persistentData; } _initialized = true; //Try online login and token refresh -- if logged in if (StoredData != null && StoredData.CachedInfo != null && StoredData.SessionKey != null) { try { var resp = Rest.DoPost("Key/Refresh", new { SessionKey = StoredData.SessionKey }); if (resp.Error) { if (resp.Message == "not_logged_in") { //not logged in, clear cached data StoredData.SessionKey = null; StoredData.CachedInfo = null; } } //And update the user info try { UpdateUserInfo(); } catch (NotLoggedInException) { } } catch (UnableToAccessAccountServerException) { } //we're in offline mode, I guess } })); }