Exemplo n.º 1
0
        /// <summary>Registers the new user.</summary>
        /// <param name="username">The username.</param>
        /// <param name="password">The password.</param>
        /// <returns></returns>
        internal async Task <bool> RegisterNewUser(string username, string password)
        {
            if (ValidateUserInput(username, password))
            {
                User newUser = new User()
                {
                    UserName = username, Password = password
                };

                if (await usersDataAccess.AddUser(newUser))
                {
                    return(true);
                }
                else
                {
                    ToastCreator.ShowUserToast("Lost connection with database, can't add user");
                    return(false);
                }
            }
            else
            {
                ToastCreator.ShowUserToast("Invalid username or password");
                return(false);
            }
        }
Exemplo n.º 2
0
 private async void SimulationPage_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
 {
     try
     {
         await ViewModel.LoadDecks().ConfigureAwait(true);
     }
     catch (JsonReaderException ex)
     {
         ToastCreator.ShowUserToast("No database connection, could not load decks");
     }
 }
Exemplo n.º 3
0
 private async void Register_OnClick(object sender, Windows.UI.Xaml.RoutedEventArgs e)
 {
     //Registration complete, navigate back to loginpage
     if (await ViewModel.RegisterNewUser(UsernameBox.Text, PasswordBox.Password))
     {
         NavigationService.Navigate(typeof(LoginPage));
     }
     else
     {
         ToastCreator.ShowUserToast("ERROR: User could not be created");
     }
 }
Exemplo n.º 4
0
 private void DrawNewHand_OnClick(object sender, RoutedEventArgs e)
 {
     if (DeckComboBox.Items != null)
     {
         try
         {
             var currentDeck = DeckComboBox.Items[DeckComboBox.SelectedIndex] as Deck;
             ViewModel.DrawNewHand(currentDeck, 7);
         }
         catch (ArgumentOutOfRangeException ex)
         {
             ToastCreator.ShowUserToast("No deck selected");
         }
     }
 }
Exemplo n.º 5
0
 private async void MainPage_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
 {
     try
     {
         await ViewModel.LoadCardsAsync().ConfigureAwait(true);
     }
     catch (HttpRequestException ex)
     {
         ToastCreator.ShowUserToast("No database connection, can't load cards");
     }
     catch (NullReferenceException ex)
     {
         ToastCreator.ShowUserToast("No database connection, can't find cards");
     }
 }
Exemplo n.º 6
0
 private async void LoadUserDecks(object sender, RoutedEventArgs e)
 {
     try
     {
         await ViewModel.GetUserDecks();
     }
     catch (HttpRequestException ex)
     {
         ToastCreator.ShowUserToast("No database connection, can't display user decks");
     }
     catch (JsonReaderException ex)
     {
         ToastCreator.ShowUserToast("No database connection, can't display user decks");
     }
 }
Exemplo n.º 7
0
 private async void DeckViewerPage_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
 {
     try
     {
         await ViewModel.GetUserDecks().ConfigureAwait(true);
     }
     catch (HttpRequestException ex)
     {
         ToastCreator.ShowUserToast("Could not load decks");
     }
     catch (JsonReaderException ex)
     {
         ToastCreator.ShowUserToast("Could not read data from database");
     }
 }
Exemplo n.º 8
0
        /// <summary>Validates the user with the database</summary>
        /// <param name="username">The username.</param>
        /// <param name="password">The password.</param>
        /// <returns></returns>
        public async Task <User> ValidateUser(string username, string password)
        {
            if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
            {
                ToastCreator.ShowUserToast("Input error: Either name or password is missing");
                return(null);
            }


            var allUsers = await _usersDataAccess.GetUsersAsync().ConfigureAwait(true);

            //If null, means database caught an exception.
            if (allUsers == null)
            {
                ToastCreator.ShowUserToast("Database connection lost: Cannot validate user");
                return(null);
            }

            var checkUser = (from x in allUsers
                             where x.UserName == username
                             select x).FirstOrDefault();

            if (checkUser != null)
            {
                if (checkUser.Password == password)
                {
                    return(checkUser);
                }
                else
                {
                    ToastCreator.ShowUserToast("Input error: Wrong password inserted");

                    return(null);
                }
            }
            else
            {
                ToastCreator.ShowUserToast("Input error: No username found");

                return(null);
            }
        }
Exemplo n.º 9
0
        private async void ChangeUserPassword()
        {
            ChangePasswordDialog pwDialog = new ChangePasswordDialog();
            await pwDialog.ShowAsync();

            if (pwDialog.Content != null)
            {
                string pw = (string)pwDialog.Content;
                _user.Password = pw;

                if (await _usersDataAccess.ChangePassword(_user))
                {
                    ToastCreator.ShowUserToast("Password changed!");
                }
                else
                {
                    ToastCreator.ShowUserToast("No database connection, password was not changed");
                }
            }
        }