Handle revoked tokens better
This commit is contained in:
@@ -46,7 +46,7 @@ Kirigami.ScrollablePage {
|
|||||||
text: i18n("Logout")
|
text: i18n("Logout")
|
||||||
iconName: "im-kick-user"
|
iconName: "im-kick-user"
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
Controller.logout(model.connection)
|
Controller.logout(model.connection, true)
|
||||||
if(Controller.accountCount === 1)
|
if(Controller.accountCount === 1)
|
||||||
pageStack.layers.pop()
|
pageStack.layers.pop()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,8 @@
|
|||||||
#include <KConfigGroup>
|
#include <KConfigGroup>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <KLocalizedString>
|
||||||
|
|
||||||
#include <QClipboard>
|
#include <QClipboard>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
@@ -150,7 +152,7 @@ void Controller::loginWithAccessToken(QString serverAddr, QString user, QString
|
|||||||
conn->connectWithToken(user, token, deviceName);
|
conn->connectWithToken(user, token, deviceName);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Controller::logout(Connection *conn)
|
void Controller::logout(Connection *conn, bool serverSideLogout)
|
||||||
{
|
{
|
||||||
if (!conn) {
|
if (!conn) {
|
||||||
qCritical() << "Attempt to logout null connection";
|
qCritical() << "Attempt to logout null connection";
|
||||||
@@ -173,20 +175,18 @@ void Controller::logout(Connection *conn)
|
|||||||
KConfigGroup tokensGroup(&config, "Tokens");
|
KConfigGroup tokensGroup(&config, "Tokens");
|
||||||
tokensGroup.deleteEntry(conn->userId());
|
tokensGroup.deleteEntry(conn->userId());
|
||||||
#endif
|
#endif
|
||||||
|
conn->stopSync();
|
||||||
|
Q_EMIT conn->stateChanged();
|
||||||
|
Q_EMIT conn->loggedOut();
|
||||||
|
if (!m_connections.isEmpty())
|
||||||
|
setConnection(m_connections[0]);
|
||||||
|
else
|
||||||
|
setConnection(nullptr);
|
||||||
|
if (!serverSideLogout) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
auto logoutJob = conn->callApi<LogoutJob>();
|
auto logoutJob = conn->callApi<LogoutJob>();
|
||||||
connect(logoutJob, &LogoutJob::finished, conn, [=] {
|
connect(logoutJob, &LogoutJob::failure, this, [=] { Q_EMIT errorOccured("Server-side Logout Failed", logoutJob->errorString()); });
|
||||||
conn->stopSync();
|
|
||||||
Q_EMIT conn->stateChanged();
|
|
||||||
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());
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Controller::addConnection(Connection *c)
|
void Controller::addConnection(Connection *c)
|
||||||
@@ -247,8 +247,13 @@ void Controller::invokeLogin()
|
|||||||
addConnection(c);
|
addConnection(c);
|
||||||
});
|
});
|
||||||
connect(c, &Connection::loginError, this, [=](QString error, QString) {
|
connect(c, &Connection::loginError, this, [=](QString error, QString) {
|
||||||
Q_EMIT errorOccured("Login Failed", error);
|
if (error == "Unrecognised access token") {
|
||||||
logout(c);
|
Q_EMIT errorOccured(i18n("Login Failed"), i18n("Access Token invalid or revoked"));
|
||||||
|
logout(c, false);
|
||||||
|
} else {
|
||||||
|
Q_EMIT errorOccured(i18n("Login Failed"), error);
|
||||||
|
logout(c, true);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
connect(c, &Connection::networkError, this, [=](QString error, QString, int, int) {
|
connect(c, &Connection::networkError, this, [=](QString error, QString, int, int) {
|
||||||
Q_EMIT errorOccured("Network Error", error);
|
Q_EMIT errorOccured("Network Error", error);
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ Q_SIGNALS:
|
|||||||
void passwordStatus(Controller::PasswordStatus status);
|
void passwordStatus(Controller::PasswordStatus status);
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void logout(Quotient::Connection *conn);
|
void logout(Quotient::Connection *conn, bool serverSideLogout);
|
||||||
void joinRoom(Quotient::Connection *c, const QString &alias);
|
void joinRoom(Quotient::Connection *c, const QString &alias);
|
||||||
void createRoom(Quotient::Connection *c, const QString &name, const QString &topic);
|
void createRoom(Quotient::Connection *c, const QString &name, const QString &topic);
|
||||||
void createDirectChat(Quotient::Connection *c, const QString &userID);
|
void createDirectChat(Quotient::Connection *c, const QString &userID);
|
||||||
|
|||||||
Reference in New Issue
Block a user