Ejemplo n.º 1
0
        private static void UpdateUserObject(AccountUser user, Tokens tokens, LogInUser loginUser, User userUpdate)
        {
            if (tokens != null)
            {
                user.AccessToken = tokens.AccessToken;
                user.RefreshToken = tokens.RefreshToken;
                user.RefreshDate = GetUnixTime(DateTime.Now) + tokens.ExpiresIn;
            }

            if (loginUser != null)
            {
                user.Username = loginUser.OnlineId;
                user.AccountId = loginUser.AccountId;
                user.Region = loginUser.Region;
                user.Language = loginUser.Language;
            }

            if (userUpdate != null)
            {
                var avatars = userUpdate.AvatarUrls.LastOrDefault();
                if (avatars != null)
                {
                    user.AvatarUrl = avatars.AvatarUrlLink;
                }
                user.Username = userUpdate.OnlineId;
            }
        }
 public async Task<int> RemoveAccountUser(AccountUser user)
 {
     using (var db = new UserAccountDataSource(Platform, DbLocation))
     {
         return await db.AccountUserRepository.Delete(user);
     }
 }
Ejemplo n.º 3
0
 public async static Task<bool> CreateUserAccount(Tokens tokens, LogInUser loginUser, User userUpdate)
 {
     var user = new AccountUser();
     UpdateUserObject(user, tokens, loginUser, userUpdate);
     var result = await Db.AccountUserRepository.Create(user);
     return result > 0;
 }
 public async Task<int> UpdateAccountUser(AccountUser user)
 {
     using (var db = new UserAccountDataSource())
     {
         return await db.AccountUserRepository.Update(user);
     }
 }
Ejemplo n.º 5
0
        public async static Task<bool> UpdateTokens(AccountUser user, Result result)
        {
            if (result?.Tokens == null)
            {
                return false;
            }

            var tokens = JsonConvert.DeserializeObject<Tokens>(result.Tokens);
            return await UpdateUserAccount(user, tokens, null, null);
        }
 public async Task UpdateTokens()
 {
     try
     {
         CurrentUser = await _udb.GetUserAccount(CurrentUser.AccountId);
     }
     catch (Exception ex)
     {
         var tc = new TelemetryClient();
         var prop = new Dictionary<string, string> { { "errorMessage", ex.Message } };
         tc.TrackEvent("FailedToUploadTokens", prop);
     }
 }
 public async Task CheckAndNavigateToMainShell(AccountUser user)
 {
     if (IsLoading)
     {
         return;
     }
     var loginResult = false;
     loginResult = await LoginTest(user);
     if (loginResult)
     {
         Locator.ViewModels.MainPageVm.CurrentUser = user;
         Locator.ViewModels.MainPageVm.IsLoggedIn = true;
         Locator.ViewModels.MainPageVm.PopulateMenu();
         new NavigateToWhatsNewPage().Execute(null);
     }
 }
 private async Task<bool> LoginTest(AccountUser user)
 {
     Result result = new Result();
     try
     {
         result = await _authManager.RefreshAccessToken(user.RefreshToken);
         var tokenResult = JsonConvert.DeserializeObject<Tokens>(result.Tokens);
         user.AccessToken = tokenResult.AccessToken;
         user.RefreshToken = tokenResult.RefreshToken;
         user.RefreshDate = GetUnixTime(DateTime.Now) + (300);
         result.IsSuccess = true;
         await AccountDatabase.UpdateAccountUser(user);
     }
     catch (Exception ex)
     {
         result.IsSuccess = false;
         result.Error = ex.Message;
     }
     return result.IsSuccess;
 }
 private async Task<bool> LoginUser()
 {
     try
     {
         var defaultUsers = await AccountDatabase.GetDefaultUserAccounts();
         if (!defaultUsers.Any()) return false;
         var defaultUser = defaultUsers.First();
         var loginResult = await LoginTest(defaultUser);
         if (loginResult)
         {
             _accountUser = defaultUser;
             return true;
         }
         else
         {
             return false;
         }
     }
     catch (Exception ex)
     {
         return false;
     }
 }
        private async Task<bool> LoginTest(AccountUser user)
        {
            IsLoading = true;
            Result result = new Result();
            try
            {
                result = await _authManager.RefreshAccessToken(user.RefreshToken);
                var tokenResult = JsonConvert.DeserializeObject<Tokens>(result.Tokens);
                result = await _userManager.GetUser(user.Username,
                    new UserAuthenticationEntity(tokenResult.AccessToken, tokenResult.RefreshToken, tokenResult.ExpiresIn),
                    user.Region, user.Language);
                var userResult = JsonConvert.DeserializeObject<User>(result.ResultJson);
                

                var didUpdate = await AccountAuthHelpers.UpdateUserAccount(user, tokenResult, null, userResult);
                result.IsSuccess = didUpdate;
            }
            catch (Exception ex)
            {
                result.IsSuccess = false;
                result.Error = ex.Message;
            }
            await ResultChecker.CheckSuccess(result);
            IsLoading = false;
            return result.IsSuccess;
        }
 public async Task<bool> DeleteUserAccount(AccountUser user)
 {
     Locator.ViewModels.MainPageVm.MenuItems = new List<MenuItem>();
     try
     {
         var pages = App.RootFrame.BackStack;
         foreach (var page in pages)
         {
             App.RootFrame.BackStack.Remove(page);
         }
     }
     catch (Exception)
     {
         // Failed to delete backstack :\
     }
     var result = new Result();
     try
     {
         result.IsSuccess = await AccountAuthHelpers.DeleteUserAccount(user);
     }
     catch (Exception ex)
     {
         result.IsSuccess = false;
         result.Error = "Failed to delete user";
     }
     var resultCheck = await ResultChecker.CheckSuccess(result);
     if (resultCheck)
     {
         AccountUsers.Remove(user);
         if (AccountUsers.Any())
         {
             OnPropertyChanged("AccountUsers");
             return true;
         }
         App.RootFrame.Navigate(typeof (LoginPage));
         
     }
     return resultCheck;
 }
Ejemplo n.º 12
0
 public async static Task<bool> DeleteUserAccount(AccountUser user)
 {
     var result = await Db.AccountUserRepository.Delete(user);
     return result > 0;
 }
 public async Task<bool> DeleteUserAccount(AccountUser user)
 {
     var result = new Result();
     try
     {
         result.IsSuccess = await AccountAuthHelpers.DeleteUserAccount(user);
     }
     catch (Exception ex)
     {
         result.IsSuccess = false;
         result.Error = "Failed to delete user";
     }
     var resultCheck = await ResultChecker.CheckSuccess(result);
     if (resultCheck)
     {
         AccountUsers.Remove(user);
         if (Shell.Instance.ViewModel.CurrentUser != null && Shell.Instance.ViewModel.CurrentUser.Username == user.Username)
         {
             Shell.Instance.ViewModel.CurrentUser = null;
             Shell.Instance.ViewModel.IsLoggedIn = false;
             try
             {
                 var pages = App.Frame.BackStack;
                 foreach (var page in pages)
                 {
                     App.Frame.BackStack.Remove(page);
                 }
             }
             catch (Exception)
             {
                 // Failed to delete backstack :\
             }
         }
         if (!AccountUsers.Any())
         {
             NavigationService.Navigate(typeof(LoginPage));
         }
     }
     return resultCheck;
 }
Ejemplo n.º 14
0
 public async static Task<bool> UpdateUserIsDefault(AccountUser user, bool isDefault = false)
 {
     user.IsDefaultLogin = isDefault;
     var result = await Db.AccountUserRepository.Update(user);
     return result > 0;
 }
        public async Task<bool> LoginDefaultUser()
        {
            string errorMessage;
            try
            {
                var defaultUsers = await _udb.GetDefaultUserAccounts();
                if (!defaultUsers.Any()) return false;
                var defaultUser = defaultUsers.First();
                var loginResult = await LoginTest(defaultUser);
                if (loginResult)
                {
                    if (Shell.Instance.ViewModel.CurrentUser != null)
                    {
                        await AccountAuthHelpers.UpdateUserIsDefault(Shell.Instance.ViewModel.CurrentUser);
                    }
                    CurrentUser = defaultUser;
                    IsLoggedIn = true;
                    return true;
                    //new NavigateToWhatsNewPage().Execute(null);
                }
                else
                {
                    return false;
                }
            }
            catch (Exception ex)
            {
                errorMessage = ex.Message;
            }

            // Failed to log in with default user, tell them.
            await ResultChecker.SendMessageDialogAsync(errorMessage, false);
            return false;
        }