Esempio n. 1
0
        private async void loginButton_Click(object sender, RoutedEventArgs e)
        {
            StackPanel  loginPanel       = (StackPanel)accountList.FindName("addAccountPanel");
            TextBox     usernameTextBox  = ((TextBox)loginPanel.FindName("usernameTextBox"));
            PasswordBox passwordBox      = ((PasswordBox)loginPanel.FindName("passwordTextBox"));
            ComboBox    questionComboBox = ((ComboBox)loginPanel.FindName("questionComboBox"));
            TextBox     answerTextBox    = ((TextBox)loginPanel.FindName("answerTextBox"));

            string username = usernameTextBox.Text.Trim().ToLower();
            string password = passwordBox.Password.Trim();
            int    question = questionComboBox.SelectedIndex;
            string answer   = answerTextBox.Text.Trim();

            // 清除当前的登录cookie
            httpClient.ClearCookies();

            if (!string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(password))
            {
                bool isOk = await AccountSettings.LoginAndAdd(username, password, question, answer, true);

                if (isOk)
                {
                    Refresh();
                }
                else
                {
                    await new MessageDialog(DataSource.LoginMessage, "账号登录失败").ShowAsync();
                }
            }

            usernameTextBox.Text           = string.Empty;
            passwordBox.Password           = string.Empty;
            questionComboBox.SelectedIndex = 0;
            answerTextBox.Text             = string.Empty;
            answerTextBox.Visibility       = Windows.UI.Xaml.Visibility.Collapsed;
        }