Пример #1
0
        private void btnAddTwitterPin_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            try
            {
                OAuthTokenResponse authToken = OAuthUtility.GetAccessToken(_consumerKey, _consumerSecret, _requestToken.Token, txtTwitterOauthPin.Text);

                accessTokenToken  = authToken.Token;
                accessTokenSecret = authToken.TokenSecret;
            }
            catch (Exception e1)
            {
                MessageBox.Show(e1.Message + "Can't build access token");
            }

            try
            {
                if (ConfigurationManager.AuthenticateUser())
                {
                    //MessageBox.Show("Utilizador autenticado");
                    if (_accountId > -1 && ConfigurationManager.UserAccountExists(this._accountId))
                    {
                        Account account = ConfigurationManager.GetUserAccount(this._accountId);
                        account.Name    = txtTwitterAccountName.Text;
                        account.Enabled = cbTwitterAccountEnabled.IsChecked.Value;
                    }
                    else
                    {
                        Account twitterAccount = new Account();
                        twitterAccount.Type    = Account.TWITTERTYPE;
                        twitterAccount.Name    = txtTwitterAccountName.Text;
                        twitterAccount.Enabled = cbTwitterAccountEnabled.IsChecked.Value;
                        twitterAccount.addOption("username", txtTwitterUsername.Text);
                        twitterAccount.addOption("accessTokenToken", accessTokenToken);
                        twitterAccount.addOption("accessTokenSecret", ConfigurationManager.AuthenticatedUser.Encrypt(accessTokenSecret));

                        ConfigurationManager.AddUserAccount(twitterAccount);


                        MessageBox.Show("Account added with sucess", "Information");
                    }

                    if (this._parentWindow != null)
                    {
                        this._parentWindow.CancelTwitterAccountEdit();
                    }
                }
                else
                {
                    MessageBox.Show("No user logged in");
                }
            }
            catch (Exception)
            {
                MessageBox.Show("User Can not be added", "Warning");
            }
        }
Пример #2
0
        private void ValidateMailAccount_ButtonClick(object sender, System.Windows.RoutedEventArgs e)
        {
            //txtMailAccountName.Text = "";
            //txtMailUsername.Text = "";
            //smtpserver.Text = "";
            //popserver.Text = "";
            //portpop.Text = "";
            //portsmtp.Text = "";
            //txtMailPassword.Password = "";

            if (txtMailAccountName.Text == "" || txtMailUsername.Text == "" || smtpserver.Text == "" || popserver.Text == "" || portsmtp.Text == "" || portpop.Text == "" || txtMailPassword.Password.Equals(""))
            {
                lblMailUsernameError.Content = "Please fill all fields";
                return;
            }

            else
            {
                Account emailAccount = new Account();
                emailAccount.Type    = Account.EMAILTYPE;
                emailAccount.Name    = txtMailAccountName.Text;
                emailAccount.Enabled = cbEnableAccount.IsChecked.Value;
                emailAccount.addOption("smtpserver", smtpserver.Text);
                emailAccount.addOption("smtpport", portsmtp.Text);
                emailAccount.addOption("popserver", popserver.Text);
                emailAccount.addOption("popport", portpop.Text);
                emailAccount.addOption("username", txtMailAccountName.Text);
                emailAccount.addOption("password", ConfigurationManager.AuthenticatedUser.Encrypt(txtMailPassword.Password));
                emailAccount.addOption("email", txtMailUsername.Text);
                emailAccount.addOption("ssl", cbSsl.IsChecked.Value.ToString());

                ConfigurationManager.AddUserAccount(emailAccount);
                ExtendedVisualStateManager.GoToElementState(this.BaseGrid as FrameworkElement, "MainAppState", true);
            }



            //MessageBox.Show("Aqui tens de fazer a magia acontecer,... linha 440");
            // Dá uma vista deolhos de como eu fiz nos dois botões que tenho do twitter

            //btnAddTwitterUser_Click - este faço as validações, basicas, se os campos estao ou não preenchidos
            // btnAddTwitterPin_Click aqui movo o ecrã para o inicio
            //Apenas precisas de fazer tudo num
        }
Пример #3
0
        /// <summary>
        /// Event for saving a moodle account
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SaveMoodleAccount(object sender, System.Windows.RoutedEventArgs e) {
            lblValidating.Visibility = System.Windows.Visibility.Visible;
            MoodleAccountForm.IsEnabled = false;

            BackgroundWorker bgWorker = new BackgroundWorker();
            String serverUrl = txtMoodleUrl.Text + Properties.Settings.Default.MoodleModuleUrl;
            String username = txtMoodleUsername.Text;
            String password = txtMoodlePassword.Password;
            String accountName = txtMoodleAccountName.Text;
            Boolean enabled = cbMoodleAccountEnabled.IsChecked.Value;

            bgWorker.DoWork += (wsender, we) => {
                DoWorkEventArgs args = we as DoWorkEventArgs;
                BackgroundWorker worker = wsender as BackgroundWorker;

                try {
                    Account account = null;
                    UedWs.UEDWSPortTypeClient client = new UedWs.UEDWSPortTypeClient();
                    client.Endpoint.Address = new EndpointAddress(serverUrl);

                    UedWs.UedCredentials credentials = new UedWs.UedCredentials();
                    credentials.username = username;
                    
                    credentials.autorizationKey = "";
                    // if it's an existing account and the password is empty, use the previous authorization key
                    if(this._accountId > -1 && password.Equals("") && ConfigurationManager.UserAccountExists(this._accountId)) {
                         account = ConfigurationManager.GetUserAccount(this._accountId);
                         if(account != null) {
                             credentials.autorizationKey = account.getOption(Properties.Settings.Default.MoodleServiceAutorizationKeySettingName);
                         }
                    } else {
                        // else, retrieve a new authorization key
                        credentials.autorizationKey = client.getAuthorizationKey(credentials.username, password, "iBoard");
                    }

                    // if the credentials are valid
                    if(!credentials.autorizationKey.Equals("") && client.validateCredentials(credentials)) {
                        if(account != null) {
                            account.Name = accountName;
                            account.Type = Account.MOODLETYPE;
                            account.Enabled = enabled;
                            account.setOption(Properties.Settings.Default.MoodleServiceUrlSettingName, serverUrl);
                            account.setOption(Properties.Settings.Default.MoodleServiceUsernameSettingName, credentials.username);
                            account.setOption(Properties.Settings.Default.MoodleServiceAutorizationKeySettingName, credentials.autorizationKey);
                            ConfigurationManager.UpdateUserAccount(account);
                        } else {
                            account = new Account(accountName, Account.MOODLETYPE, enabled);
                            account.addOption(Properties.Settings.Default.MoodleServiceUrlSettingName, serverUrl);
                            account.addOption(Properties.Settings.Default.MoodleServiceUsernameSettingName, credentials.username);
                            account.addOption(Properties.Settings.Default.MoodleServiceAutorizationKeySettingName, credentials.autorizationKey);
                            ConfigurationManager.AddUserAccount(account);
                        }
                        UedWs.UedUser user = client.getMyUserPublicProfile(credentials);
                        
                        args.Result = user;
                    } else {
                        throw new Exception();
                    }
                } catch(Exception ex) {
                    args.Result = ex.Message;
                    args.Cancel = true;
                }
            };

            bgWorker.RunWorkerCompleted += (wsender, we) => {
                RunWorkerCompletedEventArgs args = we as RunWorkerCompletedEventArgs;
                if(args.Cancelled || args.Error != null) {
                    ExtendedVisualStateManager.GoToElementState(AddMoodleAccountGrid as FrameworkElement, MoodleAccountValidationFailedState.Name, true);
                }else{
                    lblMoodleAccountSaved.Content = "The moodle account " + accountName + " was saved:";

                    UedWs.UedUser user = args.Result as UedWs.UedUser;
                    if(user != null) {
                        if(user.imageUrl != null && !user.imageUrl.Equals("")) {
                            imgNewMoodleAccountAvatar.Source = new BitmapImage(new Uri(user.imageUrl));
                        }
                        if(user.fullName != null) {
                            lblNewMoodleAccountName.Content = user.fullName;
                        }
                    }

                    ConfigurationManager.ConfigurationUpdated();
                    ExtendedVisualStateManager.GoToElementState(AddMoodleAccountGrid as FrameworkElement, MoodleAccountValidationOkState.Name, true);
                }
                lblValidating.Visibility = System.Windows.Visibility.Hidden;
                MoodleAccountForm.IsEnabled = true;
            };

            bgWorker.RunWorkerAsync();
        }