From 8379f6f725cf8ed2fdad1a19bd10743436c2d086 Mon Sep 17 00:00:00 2001 From: "Martin T. H. Sandsmark" Date: Tue, 25 Nov 2014 01:43:18 +0100 Subject: [PATCH] Implement password changing from client. Add menu item and dialog for getting a new password from the user, signal from client to core to give the new password, and wire up the signal on the core to change the password in the database. Also update the stored password on the client side. --- src/client/client.cpp | 10 ++++++++++ src/client/client.h | 4 ++++ src/core/core.cpp | 1 + src/core/core.h | 3 ++- src/core/coresession.cpp | 7 +++++++ src/core/coresession.h | 4 ++++ src/core/sessionthread.cpp | 1 + src/core/sessionthread.h | 2 ++ src/qtui/mainwin.cpp | 18 ++++++++++++++++++ src/qtui/mainwin.h | 3 +++ 10 files changed, 52 insertions(+), 1 deletion(-) diff --git a/src/client/client.cpp b/src/client/client.cpp index 7bbbefe7..94a33d1b 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -48,6 +48,7 @@ #include "quassel.h" #include "signalproxy.h" #include "util.h" +#include "clientauthhandler.h" #include #include @@ -152,6 +153,8 @@ void Client::init() p->attachSlot(SIGNAL(networkCreated(NetworkId)), this, SLOT(coreNetworkCreated(NetworkId))); p->attachSlot(SIGNAL(networkRemoved(NetworkId)), this, SLOT(coreNetworkRemoved(NetworkId))); + p->attachSignal(this, SIGNAL(clientChangePassword(QString))); + //connect(mainUi(), SIGNAL(connectToCore(const QVariantMap &)), this, SLOT(connectToCore(const QVariantMap &))); connect(mainUi(), SIGNAL(disconnectFromCore()), this, SLOT(disconnectFromCore())); connect(this, SIGNAL(connected()), mainUi(), SLOT(connectedToCore())); @@ -645,6 +648,13 @@ void Client::markBufferAsRead(BufferId id) bufferSyncer()->requestMarkBufferAsRead(id); } +void Client::changePassword(QString newPassword) { + CoreAccount account = currentCoreAccount(); + account.setPassword(newPassword); + coreAccountModel()->createOrUpdateAccount(account); + emit clientChangePassword(newPassword); +} + #if QT_VERSION < 0x050000 void Client::logMessage(QtMsgType type, const char *msg) diff --git a/src/client/client.h b/src/client/client.h index 8c707f34..445648b2 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -191,6 +191,8 @@ signals: */ void bufferMarkedAsRead(BufferId id); + void clientChangePassword(QString password); + public slots: void disconnectFromCore(); @@ -200,6 +202,8 @@ public slots: void markBufferAsRead(BufferId id); + void changePassword(QString newPassword); + private slots: void setSyncedToCore(); void setDisconnectedFromCore(); diff --git a/src/core/core.cpp b/src/core/core.cpp index e7b56392..dfd2c95a 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -638,6 +638,7 @@ SessionThread *Core::sessionForUser(UserId uid, bool restore) SessionThread *session = new SessionThread(uid, restore, this); _sessions[uid] = session; session->start(); + connect(session, SIGNAL(passwordChangeRequested(UserId, QString)), _storage, SLOT(updateUser(UserId, QString))); return session; } diff --git a/src/core/core.h b/src/core/core.h index a17211d8..deef9114 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -524,6 +524,8 @@ private slots: void socketError(QAbstractSocket::SocketError err, const QString &errorString); void setupClientSession(RemotePeer *, UserId); + void changeUserPass(const QString &username); + private: Core(); ~Core(); @@ -541,7 +543,6 @@ private: void unregisterStorageBackend(Storage *); bool selectBackend(const QString &backend); void createUser(); - void changeUserPass(const QString &username); void saveBackendSettings(const QString &backend, const QVariantMap &settings); QVariantMap promptForSettings(const Storage *storage); diff --git a/src/core/coresession.cpp b/src/core/coresession.cpp index 112aa856..1f6345d0 100644 --- a/src/core/coresession.cpp +++ b/src/core/coresession.cpp @@ -100,6 +100,8 @@ CoreSession::CoreSession(UserId uid, bool restoreState, QObject *parent) p->attachSlot(SIGNAL(createNetwork(const NetworkInfo &, const QStringList &)), this, SLOT(createNetwork(const NetworkInfo &, const QStringList &))); p->attachSlot(SIGNAL(removeNetwork(NetworkId)), this, SLOT(removeNetwork(NetworkId))); + p->attachSlot(SIGNAL(clientChangePassword(QString)), this, SLOT(changePassword(QString))); + loadSettings(); initScriptEngine(); @@ -638,3 +640,8 @@ void CoreSession::globalAway(const QString &msg) net->userInputHandler()->issueAway(msg, false /* no force away */); } } + +void CoreSession::changePassword(QString password) +{ + emit passwordChangeRequested(_user, password); +} diff --git a/src/core/coresession.h b/src/core/coresession.h index 3eecc4bb..0861b18c 100644 --- a/src/core/coresession.h +++ b/src/core/coresession.h @@ -132,6 +132,8 @@ public slots: //! Marks us away (or unaway) on all networks void globalAway(const QString &msg = QString()); + void changePassword(QString password); + signals: void initialized(); void sessionState(const Protocol::SessionState &sessionState); @@ -158,6 +160,8 @@ signals: void networkRemoved(NetworkId); void networkDisconnected(NetworkId); + void passwordChangeRequested(UserId user, QString password); + protected: virtual void customEvent(QEvent *event); diff --git a/src/core/sessionthread.cpp b/src/core/sessionthread.cpp index c2f9b5a2..1439bfce 100644 --- a/src/core/sessionthread.cpp +++ b/src/core/sessionthread.cpp @@ -121,6 +121,7 @@ void SessionThread::addInternalClientToSession(InternalPeer *internalPeer) void SessionThread::run() { _session = new CoreSession(user(), _restoreState); + connect(_session, SIGNAL(passwordChangeRequested(UserId, QString)), SIGNAL(passwordChangeRequested(UserId, QString))); connect(this, SIGNAL(addRemoteClient(RemotePeer*)), _session, SLOT(addClient(RemotePeer*))); connect(this, SIGNAL(addInternalClient(InternalPeer*)), _session, SLOT(addClient(InternalPeer*))); connect(_session, SIGNAL(sessionState(Protocol::SessionState)), Core::instance(), SIGNAL(sessionState(Protocol::SessionState))); diff --git a/src/core/sessionthread.h b/src/core/sessionthread.h index fee6e64f..9a4a1b6b 100644 --- a/src/core/sessionthread.h +++ b/src/core/sessionthread.h @@ -57,6 +57,8 @@ signals: void addRemoteClient(RemotePeer *peer); void addInternalClient(InternalPeer *peer); + void passwordChangeRequested(UserId user, QString newPassword); + private: CoreSession *_session; UserId _user; diff --git a/src/qtui/mainwin.cpp b/src/qtui/mainwin.cpp index 70e22852..6d8aa6bb 100644 --- a/src/qtui/mainwin.cpp +++ b/src/qtui/mainwin.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #ifdef HAVE_KDE4 # include @@ -196,6 +197,8 @@ void MainWin::init() connect(Client::coreConnection(), SIGNAL(handleSslErrors(const QSslSocket *, bool *, bool *)), SLOT(handleSslErrors(const QSslSocket *, bool *, bool *))); #endif + connect(this, SIGNAL(changePassword(QString)), Client::instance(), SLOT(changePassword(QString))); + // Setup Dock Areas setDockNestingEnabled(true); setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea); @@ -410,6 +413,10 @@ void MainWin::setupActions() #endif coll->addAction("ConfigureQuassel", configureQuasselAct); + QAction *changePasswordAct = new Action(QIcon::fromTheme("dialog-password"), tr("&Change password..."), coll, + this, SLOT(showChangePasswordDialog())); + coll->addAction("ChangePassword", changePasswordAct); + // Help QAction *aboutQuasselAct = new Action(QIcon(":/icons/quassel.png"), tr("&About Quassel"), coll, this, SLOT(showAboutDlg())); @@ -552,8 +559,10 @@ void MainWin::setupMenus() #else _settingsMenu->addAction(coll->action("ConfigureShortcuts")); #endif + _settingsMenu->addAction(coll->action("ChangePassword")); _settingsMenu->addAction(coll->action("ConfigureQuassel")); + _helpMenu = menuBar()->addMenu(tr("&Help")); _helpMenu->addAction(coll->action("AboutQuassel")); @@ -731,6 +740,15 @@ void MainWin::changeActiveBufferView(int bufferViewId) nextBufferView(); // fallback } +void MainWin::showChangePasswordDialog() +{ + bool ok; + QString newPassword = QInputDialog::getText(this, tr("Set new password"), tr("New password:"), QLineEdit::Password, QString(), &ok); + if (ok && !newPassword.isEmpty()) { + emit changePassword(newPassword); + } +} + void MainWin::changeActiveBufferView(bool backwards) { diff --git a/src/qtui/mainwin.h b/src/qtui/mainwin.h index 445b1d4e..44444266 100644 --- a/src/qtui/mainwin.h +++ b/src/qtui/mainwin.h @@ -164,9 +164,12 @@ private slots: void changeActiveBufferView(bool backwards); void changeActiveBufferView(int bufferViewId); + void showChangePasswordDialog(); + signals: void connectToCore(const QVariantMap &connInfo); void disconnectFromCore(); + void changePassword(QString newPassword); private: #ifdef HAVE_KDE -- 2.20.1