コード例 #1
0
        private async void SignInPassportAsync()
        {
            if (_isExistingAccount)
            {
                if (await MicrosoftPassport.GetPassportAuthenticationMessageAsync(_account))
                {
                    Frame.Navigate(typeof(Welcome), _account);
                }
            }

            else if (AuthService.Instance.ValidateCredentials(UsernameTextBox.Text, PasswordBox.Password))
            {
                Guid userId = AuthService.Instance.GetUserId(UsernameTextBox.Text);

                if (userId != Guid.Empty)
                {
                    //Now that the account exists on server try and create the necessary passport details and add them to the account
                    bool isSuccessful = await MicrosoftPassport.CreatePassportKeyAsync(userId, UsernameTextBox.Text);

                    if (isSuccessful)
                    {
                        Debug.WriteLine("Successfully signed in with Windows Hello!");
                        //Navigate to the Welcome Screen.
                        _account = AuthService.Instance.GetUserAccount(userId);
                        Frame.Navigate(typeof(Welcome), _account);
                    }
                    else
                    {
                        //The passport account creation failed.
                        //Remove the account from the server as passport details were not configured
                        AuthService.Instance.PassportRemoveUser(userId);

                        ErrorMessage.Text = "Account aanmaken mislukt!";
                    }
                }
            }
            else
            {
                ErrorMessage.Text = "Ongeldige inloggegevens";
            }
        }
コード例 #2
0
        private async void RegisterButton_Click_Async(object sender, RoutedEventArgs e)
        {
            ErrorMessage.Text = "";

            //Validate entered credentials are acceptable
            if (!string.IsNullOrEmpty(UsernameTextBox.Text))
            {
                //Register an Account on the AuthService so that we can get back a userId
                AuthService.Instance.Register(UsernameTextBox.Text);
                Guid userId = AuthService.Instance.GetUserId(UsernameTextBox.Text);

                if (userId != Guid.Empty)
                {
                    //Now that the account exists on server try and create the necessary passport details and add them to the account
                    bool isSuccessful = await MicrosoftPassport.CreatePassportKeyAsync(userId, UsernameTextBox.Text);

                    if (isSuccessful)
                    {
                        //Navigate to the Welcome Screen.
                        Frame.Navigate(typeof(Welcome), AuthService.Instance.GetUserAccount(userId));
                    }
                    else
                    {
                        //The passport account creation failed.
                        //Remove the account from the server as passport details were not configured
                        AuthService.Instance.PassportRemoveUser(userId);

                        ErrorMessage.Text = "Aanmaak account mislukt!";
                    }
                }
            }
            else
            {
                ErrorMessage.Text = "Vul een gebruikersnaam in!";
            }
        }