Esempio n. 1
0
        private async void RegisterButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(RegisterUsername) || string.IsNullOrWhiteSpace(RegisterPassword) || string.IsNullOrWhiteSpace(ConfirmPassword) ||
                    string.IsNullOrWhiteSpace(FirstName) || string.IsNullOrWhiteSpace(LastName))
                {
                    throw new InvalidOperationException("Please fill in all the fields.");
                }
                if (RegisterPassword != ConfirmPassword)
                {
                    throw new InvalidOperationException("Passwords don't match, please try again.");
                }
                IMService.AddUser(new User {
                    Username = RegisterUsername, Password = RegisterPassword, FirstName = FirstName, LastName = LastName
                });
                await IMService.SetUsernameInDb(RegisterUsername);

                RaiseSignInEvent(this, new SignInEventArgs(RegisterUsername));
                Close();
            }
            catch (InvalidOperationException exception)
            {
                MessageBox.Show(exception.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Esempio n. 2
0
        private async void SignInButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(SignInUsername) || string.IsNullOrWhiteSpace(SignInPassword))
                {
                    throw new InvalidOperationException("Please enter your username and password");
                }
                var user = IMService.GetUser(SignInUsername);
                if (user == null)
                {
                    throw new InvalidOperationException("Invalid username, please try again");
                }
                if (user.Password != SignInPassword)
                {
                    throw new InvalidOperationException("Wrong password, please try again");
                }
                await IMService.SetUsernameInDb(SignInUsername);

                RaiseSignInEvent(this, new SignInEventArgs(SignInUsername));
                Close();
            }
            catch (InvalidOperationException exception)
            {
                MessageBox.Show(exception.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }