Implement password changing from client.
authorMartin T. H. Sandsmark <martin.sandsmark@kde.org>
Tue, 25 Nov 2014 00:43:18 +0000 (01:43 +0100)
committerManuel Nickschas <sputnick@quassel-irc.org>
Mon, 16 Feb 2015 22:29:37 +0000 (23:29 +0100)
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
src/client/client.h
src/core/core.cpp
src/core/core.h
src/core/coresession.cpp
src/core/coresession.h
src/core/sessionthread.cpp
src/core/sessionthread.h
src/qtui/mainwin.cpp
src/qtui/mainwin.h

index 7bbbefe..94a33d1 100644 (file)
@@ -48,6 +48,7 @@
 #include "quassel.h"
 #include "signalproxy.h"
 #include "util.h"
 #include "quassel.h"
 #include "signalproxy.h"
 #include "util.h"
+#include "clientauthhandler.h"
 
 #include <stdio.h>
 #include <stdlib.h>
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -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->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()));
     //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);
 }
 
         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)
 
 #if QT_VERSION < 0x050000
 void Client::logMessage(QtMsgType type, const char *msg)
index 8c707f3..445648b 100644 (file)
@@ -191,6 +191,8 @@ signals:
      */
     void bufferMarkedAsRead(BufferId id);
 
      */
     void bufferMarkedAsRead(BufferId id);
 
+    void clientChangePassword(QString password);
+
 public slots:
     void disconnectFromCore();
 
 public slots:
     void disconnectFromCore();
 
@@ -200,6 +202,8 @@ public slots:
 
     void markBufferAsRead(BufferId id);
 
 
     void markBufferAsRead(BufferId id);
 
+    void changePassword(QString newPassword);
+
 private slots:
     void setSyncedToCore();
     void setDisconnectedFromCore();
 private slots:
     void setSyncedToCore();
     void setDisconnectedFromCore();
index e7b5639..dfd2c95 100644 (file)
@@ -638,6 +638,7 @@ SessionThread *Core::sessionForUser(UserId uid, bool restore)
     SessionThread *session = new SessionThread(uid, restore, this);
     _sessions[uid] = session;
     session->start();
     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;
 }
 
     return session;
 }
 
index a17211d..deef911 100644 (file)
@@ -524,6 +524,8 @@ private slots:
     void socketError(QAbstractSocket::SocketError err, const QString &errorString);
     void setupClientSession(RemotePeer *, UserId);
 
     void socketError(QAbstractSocket::SocketError err, const QString &errorString);
     void setupClientSession(RemotePeer *, UserId);
 
+    void changeUserPass(const QString &username);
+
 private:
     Core();
     ~Core();
 private:
     Core();
     ~Core();
@@ -541,7 +543,6 @@ private:
     void unregisterStorageBackend(Storage *);
     bool selectBackend(const QString &backend);
     void createUser();
     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);
 
     void saveBackendSettings(const QString &backend, const QVariantMap &settings);
     QVariantMap promptForSettings(const Storage *storage);
 
index 112aa85..1f6345d 100644 (file)
@@ -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(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();
 
     loadSettings();
     initScriptEngine();
 
@@ -638,3 +640,8 @@ void CoreSession::globalAway(const QString &msg)
         net->userInputHandler()->issueAway(msg, false /* no force away */);
     }
 }
         net->userInputHandler()->issueAway(msg, false /* no force away */);
     }
 }
+
+void CoreSession::changePassword(QString password)
+{
+    emit passwordChangeRequested(_user, password);
+}
index 3eecc4b..0861b18 100644 (file)
@@ -132,6 +132,8 @@ public slots:
     //! Marks us away (or unaway) on all networks
     void globalAway(const QString &msg = QString());
 
     //! 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);
 signals:
     void initialized();
     void sessionState(const Protocol::SessionState &sessionState);
@@ -158,6 +160,8 @@ signals:
     void networkRemoved(NetworkId);
     void networkDisconnected(NetworkId);
 
     void networkRemoved(NetworkId);
     void networkDisconnected(NetworkId);
 
+    void passwordChangeRequested(UserId user, QString password);
+
 protected:
     virtual void customEvent(QEvent *event);
 
 protected:
     virtual void customEvent(QEvent *event);
 
index c2f9b5a..1439bfc 100644 (file)
@@ -121,6 +121,7 @@ void SessionThread::addInternalClientToSession(InternalPeer *internalPeer)
 void SessionThread::run()
 {
     _session = new CoreSession(user(), _restoreState);
 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)));
     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)));
index fee6e64..9a4a1b6 100644 (file)
@@ -57,6 +57,8 @@ signals:
     void addRemoteClient(RemotePeer *peer);
     void addInternalClient(InternalPeer *peer);
 
     void addRemoteClient(RemotePeer *peer);
     void addInternalClient(InternalPeer *peer);
 
+    void passwordChangeRequested(UserId user, QString newPassword);
+
 private:
     CoreSession *_session;
     UserId _user;
 private:
     CoreSession *_session;
     UserId _user;
index 70e2285..6d8aa6b 100644 (file)
@@ -25,6 +25,7 @@
 #include <QMessageBox>
 #include <QStatusBar>
 #include <QToolBar>
 #include <QMessageBox>
 #include <QStatusBar>
 #include <QToolBar>
+#include <QInputDialog>
 
 #ifdef HAVE_KDE4
 #  include <KHelpMenu>
 
 #ifdef HAVE_KDE4
 #  include <KHelpMenu>
@@ -196,6 +197,8 @@ void MainWin::init()
     connect(Client::coreConnection(), SIGNAL(handleSslErrors(const QSslSocket *, bool *, bool *)), SLOT(handleSslErrors(const QSslSocket *, bool *, bool *)));
 #endif
 
     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);
     // Setup Dock Areas
     setDockNestingEnabled(true);
     setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
@@ -410,6 +413,10 @@ void MainWin::setupActions()
 #endif
     coll->addAction("ConfigureQuassel", configureQuasselAct);
 
 #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()));
     // 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
 #else
     _settingsMenu->addAction(coll->action("ConfigureShortcuts"));
 #endif
+    _settingsMenu->addAction(coll->action("ChangePassword"));
     _settingsMenu->addAction(coll->action("ConfigureQuassel"));
 
     _settingsMenu->addAction(coll->action("ConfigureQuassel"));
 
+
     _helpMenu = menuBar()->addMenu(tr("&Help"));
 
     _helpMenu->addAction(coll->action("AboutQuassel"));
     _helpMenu = menuBar()->addMenu(tr("&Help"));
 
     _helpMenu->addAction(coll->action("AboutQuassel"));
@@ -731,6 +740,15 @@ void MainWin::changeActiveBufferView(int bufferViewId)
     nextBufferView(); // fallback
 }
 
     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)
 {
 
 void MainWin::changeActiveBufferView(bool backwards)
 {
index 445b1d4..4444426 100644 (file)
@@ -164,9 +164,12 @@ private slots:
     void changeActiveBufferView(bool backwards);
     void changeActiveBufferView(int bufferViewId);
 
     void changeActiveBufferView(bool backwards);
     void changeActiveBufferView(int bufferViewId);
 
+    void showChangePasswordDialog();
+
 signals:
     void connectToCore(const QVariantMap &connInfo);
     void disconnectFromCore();
 signals:
     void connectToCore(const QVariantMap &connInfo);
     void disconnectFromCore();
+    void changePassword(QString newPassword);
 
 private:
 #ifdef HAVE_KDE
 
 private:
 #ifdef HAVE_KDE