/// <summary> /// The function that will be called when this frame is navigated to. /// /// Checks to see if Microsoft Passport is available and checks to see if an /// account was passed in. /// /// If an account was passed, check if it uses Microsoft Passport. /// and set the "adding user" flag so we don't add a new account /// to the list of users. /// </summary> /// <param name="e"></param> protected override void OnNavigatedTo(NavigationEventArgs e) { rootPage = MainPage.Current; PassportAvailableCheck(); if (e.Parameter != null) { m_account = (Account)e.Parameter; textbox_Username.Text = m_account.Email; textbox_Username.IsEnabled = false; m_addingAccount = false; if (m_account.UsesPassport == true) { SignInPassport(true); } } }
/// <summary> /// Handles user saving for our list of users if this is a new user /// and navigates to the main content. /// </summary> /// <param name="account">The account used to sign in</param> private void SuccessfulSignIn(Account account) { // If this is an already existing account, replace the old // version of this account in the account list. if (m_addingAccount == false) { foreach (Account a in UserSelect.accountList) { if (a.Email == account.Email) { UserSelect.accountList.Remove(a); break; } } } UserSelect.accountList.Add(account); CleanUpUserList(); this.Frame.Navigate(typeof(Content), account); }
/// <summary> /// The function called when the user wants to sign in with Passport but from /// the username/password dialog. /// /// First we check if they already use Passport as their primary login method /// /// Otherwise we authenticate their username/password and then begin the Passport /// enrollment process which consists of creating a Passport key and then sending that to /// the authentication server. /// </summary> /// <param name="passportIsPrimaryLogin">Boolean representing if primary login method is Passport</param> private async void SignInPassport(bool passportIsPrimaryLogin) { if (passportIsPrimaryLogin == true) { if (await AuthenticatePassport() == true) { SuccessfulSignIn(m_account); return; } } else if (await SignInPassword(true) == true) { if (await CreatePassportKey(textbox_Username.Text) == true) { bool serverAddedPassportToAccount = await AddPassportToAccountOnServer(); if (serverAddedPassportToAccount == true) { rootPage.NotifyUser("Successfully signed in with Microsoft Passport!", NotifyType.StatusMessage); if (m_addingAccount == true) { Account goodAccount = new Account() { Name = textbox_Username.Text, Email = textbox_Username.Text, UsesPassport = true }; SuccessfulSignIn(goodAccount); } else { m_account.UsesPassport = true; SuccessfulSignIn(m_account); } return; } } textblock_ErrorField.Text = "Sign In with Passport failed. Try later."; button_PassportSignIn.IsEnabled = false; } textblock_ErrorField.Text = "Invalid username or password."; }
/// <summary> /// Method called when a user clicks on the username/password Sign In button. /// /// Will attempt to authenticate the credentials with the server and then either sign in /// or display an error to the user if applicable. /// </summary> /// <param name="calledFromPassport">Boolean representing if this method was called from the user clicking "Sign In with Microsoft Passport"</param> /// <returns>Boolean representing if signing in with password succeeded</returns> private async Task<bool> SignInPassword(bool calledFromPassport) { textblock_ErrorField.Text = ""; if (textbox_Username.Text.Length == 0 || passwordbox_Password.Password.Length == 0) { textblock_ErrorField.Text = "Username/Password cannot be blank."; return false; } try { bool signedIn = await AuthenticatePasswordCredentials(); if (signedIn == false) { textblock_ErrorField.Text = "Unable to sign you in with those credentials."; } else { // TODO: Roaming Passport settings. Make it so the server can tell us if they prefer to use Passport and upsell immediately. Account goodAccount = new Account() { Name = textbox_Username.Text, Email = textbox_Username.Text, UsesPassport = false }; if (calledFromPassport == false) { rootPage.NotifyUser("Successfully signed in with traditional username/password!", NotifyType.StatusMessage); SuccessfulSignIn(goodAccount); } return true; } return false; } catch (Exception e) { rootPage.NotifyUser(e.Message, NotifyType.ErrorMessage); return false; } }
protected override void OnNavigatedTo(NavigationEventArgs e) { rootPage = MainPage.Current; activeAccount = (Account) e.Parameter; }