private void TestAccount(TraktAuthentication account)
{
TraktUserToken response = null;
if (NewAccount)
{
// No longer supported with v2 API.
//if (lblTestConnect != null)
// GUIControl.SetControlLabel(GetID, lblTestConnect.GetID, Translation.CreatingAccount);
//GUIWindowManager.Process();
//response = TraktAPI.v1.TraktAPI.CreateAccount(account);
}
else
{
if (lblTestConnect != null)
GUIControl.SetControlLabel(GetID, lblTestConnect.GetID, Translation.SigningIntoAccount);
GUIWindowManager.Process();
response = TraktAPI.TraktAPI.Login(account.ToJSON());
}
if (response == null || string.IsNullOrEmpty(response.Token))
{
GUIUtils.ShowNotifyDialog(Translation.Error, Translation.FailedLogin);
if (lblTestConnect != null)
GUIControl.SetControlLabel(GetID, lblTestConnect.GetID, string.Empty);
}
else
{
// Save User Token
TraktAPI.TraktAPI.UserToken = response.Token;
// Save New Account Settings
TraktSettings.Username = account.Username;
TraktSettings.Password = account.Password;
if (!TraktSettings.UserLogins.Exists(u => u.Username == TraktSettings.Username))
{
TraktSettings.UserLogins.Add(new TraktAuthentication { Username = TraktSettings.Username, Password = TraktSettings.Password });
}
TraktSettings.AccountStatus = ConnectionState.Connected;
HideAccountControls();
InitProperties();
// clear caches
// watchlists are stored by user so dont need clearing.
GUINetwork.ClearCache();
GUICalendar.ClearCache();
GUIRecommendationsMovies.ClearCache();
GUIRecommendationsShows.ClearCache();
// clear any stored user data
TraktCache.ClearSyncCache();
}
}