Esempio n. 1
0
        private void ShowNotAuthorisedDialog()
        {
            using (var dlg = new ErrorDialog(Messages.USER_NOT_AUTHORIZED)
            {
                WindowTitle = Messages.PERMISSION_DENIED
            })
            {
                dlg.ShowDialog(this);
            }

            TextBoxPassword.Focus();
            TextBoxPassword.SelectAll();
        }
Esempio n. 2
0
        private void ShowNotAuthorisedDialog()
        {
            using (var dlg = new ThreeButtonDialog(
                       new ThreeButtonDialog.Details(
                           SystemIcons.Error,
                           Messages.USER_NOT_AUTHORIZED,
                           Messages.PERMISSION_DENIED)))
            {
                dlg.ShowDialog(this);
            }

            TextBoxPassword.Focus();
            TextBoxPassword.SelectAll();
        }
Esempio n. 3
0
        public LoginWindow()
        {
            InitializeComponent();

            if (Settings.Contains(Property.LastServer))
            {
                TextBoxServer.Text = Settings.GetValue(Property.LastServer);
            }
            if (Settings.Contains(Property.LastUser))
            {
                TextBoxUser.Text = Settings.GetValue(Property.LastUser);
            }
            if (Settings.Contains(Property.LastPassword))
            {
                TextBoxPassword.Password = GetDecryptedPassword();

                CheckBoxSavePassword.IsChecked = true;
            }
            if (Settings.Contains(Property.AutoConnect))
            {
                CheckBoxAutoConnect.IsChecked = true;
            }

            if (TextBoxServer.Text != "" && TextBoxUser.Text != "" && TextBoxPassword.Password.Length == 0)
            {
                TextBoxPassword.SelectAll();
            }
            else if (TextBoxServer.Text.Length == 0)
            {
                TextBoxServer.Select(0, 0);
            }
            else if (TextBoxUser.Text.Length == 0)
            {
                TextBoxUser.Select(0, 0);
            }
        }
Esempio n. 4
0
        private void buttonAuthorize_Click(object sender, EventArgs e)
        {
            try
            {
                Exception delegateException = null;
                log.Debug("Testing logging in with the new credentials");
                DelegatedAsyncAction loginAction = new DelegatedAsyncAction(connection,
                                                                            Messages.AUTHORIZING_USER,
                                                                            Messages.CREDENTIALS_CHECKING,
                                                                            Messages.CREDENTIALS_CHECK_COMPLETE,
                                                                            delegate
                {
                    try
                    {
                        elevatedSession = connection.ElevatedSession(TextBoxUsername.Text.Trim(), TextBoxPassword.Text);
                    }
                    catch (Exception ex)
                    {
                        delegateException = ex;
                    }
                });

                using (var dlg = new ActionProgressDialog(loginAction, ProgressBarStyle.Marquee, false))
                    dlg.ShowDialog(this);

                // The exception would have been handled by the action progress dialog, just return the user to the sudo dialog
                if (loginAction.Exception != null)
                {
                    return;
                }

                if (HandledAnyDelegateException(delegateException))
                {
                    return;
                }

                if (elevatedSession.IsLocalSuperuser || SessionAuthorized(elevatedSession))
                {
                    elevatedUsername = TextBoxUsername.Text.Trim();
                    elevatedPassword = TextBoxPassword.Text;
                    DialogResult     = DialogResult.OK;
                    Close();
                    return;
                }

                ShowNotAuthorisedDialog();
            }
            catch (Exception ex)
            {
                log.DebugFormat("Exception when attempting to sudo action: {0} ", ex);
                using (var dlg = new ThreeButtonDialog(
                           new ThreeButtonDialog.Details(
                               SystemIcons.Error,
                               String.Format(Messages.USER_AUTHORIZATION_FAILED, TextBoxUsername.Text),
                               Messages.XENCENTER)))
                {
                    dlg.ShowDialog(Parent);
                }

                TextBoxPassword.Focus();
                TextBoxPassword.SelectAll();
            }
            finally
            {
                // Check whether we have a successful elevated session and whether we have been asked to log it out
                // If non successful (most likely the new subject is not authorized) then log it out anyway.
                if (elevatedSession != null && DialogResult != DialogResult.OK)
                {
                    elevatedSession.Connection.Logout(elevatedSession);
                    elevatedSession = null;
                }
            }
        }
Esempio n. 5
0
 private void OnPasswordGotFocus(object sender, RoutedEventArgs e)
 {
     TextBoxPassword.SelectAll();
 }