From: Manuel Nickschas Date: Tue, 24 Nov 2009 08:11:19 +0000 (+0100) Subject: Implement user authentication for core login X-Git-Tag: 0.6-beta1~159 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=8f7204aa8928f769a9cd74b3bfca4a4c5982c393 Implement user authentication for core login We now popup a little dialog to allow the user entering user/password when logging into a core with no or the wrong password. --- diff --git a/src/client/coreconnection.cpp b/src/client/coreconnection.cpp index 863f1bd8..f290756d 100644 --- a/src/client/coreconnection.cpp +++ b/src/client/coreconnection.cpp @@ -38,6 +38,7 @@ CoreConnection::CoreConnection(CoreAccountModel *model, QObject *parent) : QObject(parent), _model(model), _blockSize(0), + _state(Disconnected), _progressMinimum(0), _progressMaximum(-1), _progressValue(-1) @@ -98,6 +99,7 @@ void CoreConnection::resetConnection() { _netsToSync.clear(); _numNetsToSync = 0; + _state = Disconnected; setProgressMaximum(-1); // disable emit connectionMsg(tr("Disconnected from core.")); @@ -227,10 +229,8 @@ void CoreConnection::coreHasData() { } void CoreConnection::disconnectFromCore() { - if(isConnected()) { - Client::signalProxy()->removeAllPeers(); - resetConnection(); - } + Client::signalProxy()->removeAllPeers(); + resetConnection(); } void CoreConnection::reconnectToCore() { @@ -366,12 +366,14 @@ void CoreConnection::connectionReady() { resetWarningsHandler(); } -void CoreConnection::loginToCore() { +void CoreConnection::loginToCore(const QString &prevError) { emit connectionMsg(tr("Logging in...")); - if(currentAccount().user().isEmpty() || currentAccount().password().isEmpty()) { - emit userAuthenticationRequired(&_account); // *must* be a synchronous call - if(currentAccount().user().isEmpty() || currentAccount().password().isEmpty()) { + if(currentAccount().user().isEmpty() || currentAccount().password().isEmpty() || !prevError.isEmpty()) { + bool valid = false; + emit userAuthenticationRequired(&_account, &valid, prevError); // *must* be a synchronous call + if(!valid || currentAccount().user().isEmpty() || currentAccount().password().isEmpty()) { disconnectFromCore(); + emit connectionError(tr("Login canceled")); return; } } @@ -384,16 +386,16 @@ void CoreConnection::loginToCore() { } void CoreConnection::loginFailed(const QString &error) { - emit userAuthenticationRequired(&_account, error); // *must* be a synchronous call - if(currentAccount().user().isEmpty() || currentAccount().password().isEmpty()) { - disconnectFromCore(); - return; - } - loginToCore(); + loginToCore(error); } void CoreConnection::loginSuccess() { updateProgress(0, 0); + + // save current account data + _model->createOrUpdateAccount(currentAccount()); + _model->save(); + setProgressText(tr("Receiving session state")); setState(Synchronizing); emit connectionMsg(tr("Synchronizing to %1...").arg(currentAccount().accountName())); diff --git a/src/client/coreconnection.h b/src/client/coreconnection.h index 7a5d841f..a74c12d3 100644 --- a/src/client/coreconnection.h +++ b/src/client/coreconnection.h @@ -85,7 +85,7 @@ signals: void startCoreSetup(const QVariantList &); // This signal MUST be handled synchronously! - void userAuthenticationRequired(CoreAccount *, const QString &errorMessage = QString()); + void userAuthenticationRequired(CoreAccount *, bool *valid, const QString &errorMessage = QString()); void handleIgnoreWarnings(bool permanently); @@ -114,7 +114,7 @@ private slots: void connectionReady(); //void doCoreSetup(const QVariant &setupData); - void loginToCore(); + void loginToCore(const QString &previousError = QString()); void loginSuccess(); void loginFailed(const QString &errorMessage); diff --git a/src/qtui/CMakeLists.txt b/src/qtui/CMakeLists.txt index 6e9626e9..28e1b68a 100644 --- a/src/qtui/CMakeLists.txt +++ b/src/qtui/CMakeLists.txt @@ -119,6 +119,7 @@ set(FORMS coreconfigwizardadminuserpage.ui coreconfigwizardstorageselectionpage.ui coreconfigwizardsyncpage.ui + coreconnectauthdlg.ui coreinfodlg.ui debugbufferviewoverlay.ui debugconsole.ui diff --git a/src/qtui/coreconnectdlg.cpp b/src/qtui/coreconnectdlg.cpp index 10ee20f9..89f40a42 100644 --- a/src/qtui/coreconnectdlg.cpp +++ b/src/qtui/coreconnectdlg.cpp @@ -60,3 +60,33 @@ void CoreConnectDlg::accept() { _settingsPage->save(); QDialog::accept(); } + +/******** CoreConnectAuthDlg ****************************************************************/ + +CoreConnectAuthDlg::CoreConnectAuthDlg(CoreAccount *account, QWidget *parent) + : QDialog(parent), + _account(account) +{ + ui.setupUi(this); + + connect(ui.user, SIGNAL(textChanged(QString)), SLOT(setButtonStates())); + connect(ui.password, SIGNAL(textChanged(QString)), SLOT(setButtonStates())); + + ui.label->setText(tr("Please enter your credentials for %1:").arg(account->accountName())); + ui.user->setText(account->user()); + ui.password->setText(account->password()); + ui.rememberPasswd->setChecked(account->storePassword()); +} + +void CoreConnectAuthDlg::accept() { + _account->setUser(ui.user->text()); + _account->setPassword(ui.password->text()); + _account->setStorePassword(ui.rememberPasswd->isChecked()); + + QDialog::accept(); +} + +void CoreConnectAuthDlg::setButtonStates() { + bool valid = !(ui.user->text().isEmpty() || ui.password->text().isEmpty()); + ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(valid); +} diff --git a/src/qtui/coreconnectdlg.h b/src/qtui/coreconnectdlg.h index f7d29df6..b892a20d 100644 --- a/src/qtui/coreconnectdlg.h +++ b/src/qtui/coreconnectdlg.h @@ -25,6 +25,8 @@ #include "coreaccount.h" +#include "ui_coreconnectauthdlg.h" + class CoreAccountSettingsPage; class CoreConnectDlg : public QDialog { @@ -40,4 +42,20 @@ private: CoreAccountSettingsPage *_settingsPage; }; +class CoreConnectAuthDlg : public QDialog { + Q_OBJECT + +public: + CoreConnectAuthDlg(CoreAccount *account, QWidget *parent = 0); + + void accept(); + +private slots: + void setButtonStates(); + +private: + Ui::CoreConnectAuthDlg ui; + CoreAccount *_account; +}; + #endif diff --git a/src/qtui/mainwin.cpp b/src/qtui/mainwin.cpp index 522766b7..ed467cd4 100644 --- a/src/qtui/mainwin.cpp +++ b/src/qtui/mainwin.cpp @@ -158,6 +158,7 @@ void MainWin::init() { SLOT(messagesInserted(const QModelIndex &, int, int))); connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showChannelList(NetworkId)), SLOT(showChannelList(NetworkId))); connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showIgnoreList(QString)), SLOT(showIgnoreList(QString))); + connect(Client::coreConnection(), SIGNAL(userAuthenticationRequired(CoreAccount *, bool *, QString)), SLOT(userAuthenticationRequired(CoreAccount *, bool *, QString))); // Setup Dock Areas setDockNestingEnabled(true); @@ -840,6 +841,12 @@ void MainWin::showCoreConnectionDlg() { } } +void MainWin::userAuthenticationRequired(CoreAccount *account, bool *valid, const QString &errorMessage) { + Q_UNUSED(errorMessage) + CoreConnectAuthDlg dlg(account, this); + *valid = (dlg.exec() == QDialog::Accepted); +} + void MainWin::showChannelList(NetworkId netId) { ChannelListDlg *channelListDlg = new ChannelListDlg(); diff --git a/src/qtui/mainwin.h b/src/qtui/mainwin.h index a42c3f8b..d14a7c63 100644 --- a/src/qtui/mainwin.h +++ b/src/qtui/mainwin.h @@ -42,6 +42,7 @@ class BufferHotListFilter; class BufferView; class BufferViewConfig; class ClientBufferViewConfig; +class CoreAccount; class CoreConnectionStatusWidget; class BufferViewDock; class BufferWidget; @@ -119,6 +120,7 @@ class MainWin void showAboutDlg(); void showChannelList(NetworkId netId = NetworkId()); void startInternalCore(); + void userAuthenticationRequired(CoreAccount *, bool *valid, const QString &errorMessage); void showCoreConnectionDlg(); void showCoreInfoDlg(); void showAwayLog(); diff --git a/src/qtui/ui/coreconnectauthdlg.ui b/src/qtui/ui/coreconnectauthdlg.ui new file mode 100644 index 00000000..fb956872 --- /dev/null +++ b/src/qtui/ui/coreconnectauthdlg.ui @@ -0,0 +1,122 @@ + + + CoreConnectAuthDlg + + + + 0 + 0 + 395 + 183 + + + + Authentication Required + + + + + + Please enter your account data: + + + false + + + + + + + + + + + + Password: + + + + + + + QLineEdit::Password + + + + + + + Username: + + + + + + + + + Remember password + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + CoreConnectAuthDlg + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + CoreConnectAuthDlg + reject() + + + 316 + 260 + + + 286 + 274 + + + + +