Add accounts management page
This commit is contained in:
@@ -34,6 +34,7 @@
|
||||
#include "csapi/joining.h"
|
||||
#include "csapi/logout.h"
|
||||
#include "csapi/profile.h"
|
||||
#include "csapi/registration.h"
|
||||
#include "events/eventcontent.h"
|
||||
#include "events/roommessageevent.h"
|
||||
#include "settings.h"
|
||||
@@ -173,6 +174,8 @@ void Controller::logout(Connection *conn)
|
||||
Q_EMIT conn->loggedOut();
|
||||
if (!m_connections.isEmpty())
|
||||
setConnection(m_connections[0]);
|
||||
else
|
||||
setConnection(nullptr);
|
||||
});
|
||||
connect(logoutJob, &LogoutJob::failure, this, [=] {
|
||||
Q_EMIT errorOccured("Server-side Logout Failed", logoutJob->errorString());
|
||||
@@ -424,3 +427,44 @@ KAboutData Controller::aboutData() const
|
||||
{
|
||||
return m_aboutData;
|
||||
}
|
||||
|
||||
void Controller::changePassword(Connection *connection, const QString ¤tPassword, const QString &newPassword)
|
||||
{
|
||||
NeochatChangePasswordJob *job = connection->callApi<NeochatChangePasswordJob>(newPassword, false);
|
||||
connect(job, &BaseJob::result, this, [this, job, currentPassword, newPassword, connection] {
|
||||
if(job->error() == 103) {
|
||||
QJsonObject replyData = job->jsonData();
|
||||
QJsonObject authData;
|
||||
authData["session"] = replyData["session"];
|
||||
authData["password"] = currentPassword;
|
||||
authData["type"] = "m.login.password";
|
||||
authData["user"] = connection->user()->id();
|
||||
QJsonObject identifier = {{"type", "m.id.user"}, {"user", connection->user()->id()}};
|
||||
authData["identifier"] = identifier;
|
||||
NeochatChangePasswordJob *innerJob = connection->callApi<NeochatChangePasswordJob>(newPassword, false, authData);
|
||||
connect(innerJob, &BaseJob::success, this, [this]() {
|
||||
Q_EMIT passwordStatus(PasswordStatus::Success);
|
||||
});
|
||||
connect(innerJob, &BaseJob::failure, this, [innerJob, this] () {
|
||||
if(innerJob->jsonData()["errcode"] == "M_FORBIDDEN") {
|
||||
Q_EMIT passwordStatus(PasswordStatus::Wrong);
|
||||
} else {
|
||||
Q_EMIT passwordStatus(PasswordStatus::Other);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
NeochatChangePasswordJob::NeochatChangePasswordJob(const QString& newPassword,
|
||||
bool logoutDevices,
|
||||
const Omittable<QJsonObject>& auth)
|
||||
: BaseJob(HttpVerb::Post, QStringLiteral("ChangePasswordJob"),
|
||||
QStringLiteral("/_matrix/client/r0") % "/account/password")
|
||||
{
|
||||
QJsonObject _data;
|
||||
addParam<>(_data, QStringLiteral("new_password"), newPassword);
|
||||
addParam<IfNotEmpty>(_data, QStringLiteral("logout_devices"), logoutDevices);
|
||||
addParam<IfNotEmpty>(_data, QStringLiteral("auth"), auth);
|
||||
setRequestData(std::move(_data));
|
||||
}
|
||||
|
||||
@@ -43,6 +43,8 @@ public:
|
||||
Q_INVOKABLE void loginWithCredentials(QString, QString, QString, QString);
|
||||
Q_INVOKABLE void loginWithAccessToken(QString, QString, QString, QString);
|
||||
|
||||
Q_INVOKABLE void changePassword(Connection *connection, const QString ¤tPassword, const QString &newPassword);
|
||||
|
||||
QVector<Connection *> connections() const
|
||||
{
|
||||
return m_connections;
|
||||
@@ -108,6 +110,13 @@ public:
|
||||
void setAboutData(KAboutData aboutData);
|
||||
KAboutData aboutData() const;
|
||||
|
||||
enum PasswordStatus {
|
||||
Success,
|
||||
Wrong,
|
||||
Other
|
||||
};
|
||||
Q_ENUM(PasswordStatus);
|
||||
|
||||
private:
|
||||
explicit Controller(QObject *parent = nullptr);
|
||||
~Controller();
|
||||
@@ -143,6 +152,7 @@ Q_SIGNALS:
|
||||
void connectionChanged();
|
||||
void isOnlineChanged();
|
||||
void aboutDataChanged();
|
||||
void passwordStatus(PasswordStatus status);
|
||||
|
||||
public Q_SLOTS:
|
||||
void logout(Quotient::Connection *conn);
|
||||
@@ -154,4 +164,12 @@ public Q_SLOTS:
|
||||
void markAllMessagesAsRead(Quotient::Connection *conn);
|
||||
};
|
||||
|
||||
//TODO libQuotient 0.7: Drop
|
||||
class NeochatChangePasswordJob : public BaseJob {
|
||||
public:
|
||||
explicit NeochatChangePasswordJob(const QString& newPassword,
|
||||
bool logoutDevices,
|
||||
const Omittable<QJsonObject>& auth = none);
|
||||
};
|
||||
|
||||
#endif // CONTROLLER_H
|
||||
|
||||
@@ -1,6 +1,33 @@
|
||||
#include "spectraluser.h"
|
||||
|
||||
#include "csapi/profile.h"
|
||||
|
||||
QColor SpectralUser::color()
|
||||
{
|
||||
return QColor::fromHslF(hueF(), 0.7, 0.5, 1);
|
||||
}
|
||||
//TODO libQuotient 0.7: remove default name
|
||||
void SpectralUser::setDefaultName(QString defaultName)
|
||||
{
|
||||
rename(defaultName);
|
||||
connect(this, &Quotient::User::defaultNameChanged, this, [this]() {
|
||||
m_defaultName = "";
|
||||
qDebug() << "asdf";
|
||||
Q_EMIT nameChanged();
|
||||
});
|
||||
}
|
||||
|
||||
QString SpectralUser::defaultName()
|
||||
{
|
||||
if(m_defaultName.isEmpty()) {
|
||||
GetDisplayNameJob *job = connection()->callApi<GetDisplayNameJob>(id());
|
||||
connect(job, &BaseJob::success, this, [this, job] {
|
||||
if(job->displayname().isEmpty())
|
||||
m_defaultName = id();
|
||||
else
|
||||
m_defaultName = job->displayname();
|
||||
Q_EMIT nameChanged();
|
||||
});
|
||||
}
|
||||
return m_defaultName;
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ class SpectralUser : public User
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QColor color READ color CONSTANT)
|
||||
Q_PROPERTY(QString defaultName READ defaultName WRITE setDefaultName NOTIFY nameChanged)
|
||||
public:
|
||||
SpectralUser(QString userId, Connection *connection)
|
||||
: User(userId, connection)
|
||||
@@ -19,6 +20,16 @@ public:
|
||||
}
|
||||
|
||||
QColor color();
|
||||
|
||||
//TODO libQuotient 0.7: remove
|
||||
void setDefaultName(QString defaultName);
|
||||
QString defaultName();
|
||||
|
||||
Q_SIGNALS:
|
||||
void nameChanged();
|
||||
|
||||
private:
|
||||
QString m_defaultName;
|
||||
};
|
||||
|
||||
#endif // SpectralUser_H
|
||||
|
||||
Reference in New Issue
Block a user