Completely rework login job
Now .well-know is obsolete and also error message are correctly displayed
This commit is contained in:
@@ -23,7 +23,6 @@ Kirigami.ScrollablePage {
|
|||||||
padding: Kirigami.Units.smallSpacing
|
padding: Kirigami.Units.smallSpacing
|
||||||
contentItem: Kirigami.InlineMessage {
|
contentItem: Kirigami.InlineMessage {
|
||||||
id: inlineMessage
|
id: inlineMessage
|
||||||
type: Kirigami.MessageType.Error
|
|
||||||
visible: false
|
visible: false
|
||||||
showCloseButton: true
|
showCloseButton: true
|
||||||
}
|
}
|
||||||
@@ -74,7 +73,8 @@ Kirigami.ScrollablePage {
|
|||||||
Connections {
|
Connections {
|
||||||
target: Controller
|
target: Controller
|
||||||
onErrorOccured: {
|
onErrorOccured: {
|
||||||
if (detail.length !== 0) {
|
inlineMessage.type = Kirigami.MessageType.Error;
|
||||||
|
if (detail && detail.length !== 0) {
|
||||||
inlineMessage.text = i18n("%1: %2", error, detail);
|
inlineMessage.text = i18n("%1: %2", error, detail);
|
||||||
} else {
|
} else {
|
||||||
inlineMessage.text = error;
|
inlineMessage.text = error;
|
||||||
@@ -85,6 +85,9 @@ Kirigami.ScrollablePage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function doLogin() {
|
function doLogin() {
|
||||||
|
inlineMessage.text = i18n("Loading, this might take up to 10 seconds.");
|
||||||
|
inlineMessage.type = Kirigami.MessageType.Information
|
||||||
|
inlineMessage.visible = true;
|
||||||
if (accessTokenField.text.length > 0) {
|
if (accessTokenField.text.length > 0) {
|
||||||
Controller.loginWithAccessToken(serverField.text.trim(), usernameField.text.trim(), accessTokenField.text, deviceNameField.text.trim());
|
Controller.loginWithAccessToken(serverField.text.trim(), usernameField.text.trim(), accessTokenField.text, deviceNameField.text.trim());
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -99,50 +99,43 @@ void Controller::loginWithCredentials(const QString &serverAddr, const QString &
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (deviceName.isEmpty()) {
|
if (deviceName.isEmpty()) {
|
||||||
deviceName = "NeoChat " + QSysInfo::machineHostName() + " " + QSysInfo::productType() + " " + QSysInfo::productVersion() + " " + QSysInfo::currentCpuArchitecture();
|
deviceName = "NeoChat " + QSysInfo::machineHostName() + " " + QSysInfo::productType() + " " + QSysInfo::productVersion() + " " + QSysInfo::currentCpuArchitecture();
|
||||||
}
|
}
|
||||||
|
|
||||||
QUrl serverUrl(serverAddr);
|
|
||||||
|
|
||||||
auto conn = new Connection(this);
|
auto conn = new Connection(this);
|
||||||
|
const QUrl serverUrl = QUrl(serverAddr);
|
||||||
|
// we are using a fake mixd since resolveServer just set the homeserver url :sigh:
|
||||||
|
conn->resolveServer("@username:" + serverUrl.host() + ":" + QString::number(serverUrl.port(443)));
|
||||||
|
|
||||||
if (serverUrl.isValid()) {
|
connect(conn, &Connection::homeserverChanged, this, [this, user, conn, pass, deviceName]() {
|
||||||
conn->setHomeserver(serverUrl);
|
conn->connectToServer(user, pass, deviceName, "");
|
||||||
auto *job = conn->callApi<GetWellknownJob>();
|
connect(conn, &Connection::connected, this, [this, conn, deviceName] {
|
||||||
connect(job, &BaseJob::finished, this, [=]() {
|
AccountSettings account(conn->userId());
|
||||||
if (job->status() == BaseJob::Success) {
|
account.setKeepLoggedIn(true);
|
||||||
QUrl url(job->data().homeserver.baseUrl);
|
account.clearAccessToken(); // Drop the legacy - just in case
|
||||||
auto finalConn = new Connection(this);
|
account.setHomeserver(conn->homeserver());
|
||||||
finalConn->setHomeserver(url);
|
account.setDeviceId(conn->deviceId());
|
||||||
finalConn->connectToServer(user, pass, deviceName, "");
|
account.setDeviceName(deviceName);
|
||||||
connect(finalConn, &Connection::connected, this, [=] {
|
if (!saveAccessTokenToKeyChain(account, conn->accessToken())) {
|
||||||
AccountSettings account(finalConn->userId());
|
qWarning() << "Couldn't save access token";
|
||||||
account.setKeepLoggedIn(true);
|
|
||||||
account.clearAccessToken(); // Drop the legacy - just in case
|
|
||||||
account.setHomeserver(finalConn->homeserver());
|
|
||||||
account.setDeviceId(finalConn->deviceId());
|
|
||||||
account.setDeviceName(deviceName);
|
|
||||||
if (!saveAccessTokenToKeyChain(account, finalConn->accessToken())) {
|
|
||||||
qWarning() << "Couldn't save access token";
|
|
||||||
}
|
|
||||||
account.sync();
|
|
||||||
addConnection(finalConn);
|
|
||||||
setActiveConnection(finalConn);
|
|
||||||
});
|
|
||||||
connect(finalConn, &Connection::networkError, [=](QString error, const QString &, int, int) {
|
|
||||||
Q_EMIT globalErrorOccured(i18n("Network Error"), std::move(error));
|
|
||||||
});
|
|
||||||
connect(finalConn, &Connection::loginError, [=](QString error, const QString &) {
|
|
||||||
Q_EMIT errorOccured(i18n("Login Failed"), std::move(error));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
account.sync();
|
||||||
|
addConnection(conn);
|
||||||
|
setActiveConnection(conn);
|
||||||
});
|
});
|
||||||
connect(job, &BaseJob::retryScheduled, this, [=](int, Quotient::BaseJob::duration_ms_t) {
|
connect(conn, &Connection::networkError, [=](QString error, const QString &, int, int) {
|
||||||
Q_EMIT errorOccured(i18n("%1 is not a matrix server or is unreachable", serverUrl.toString()), QString());
|
Q_EMIT globalErrorOccured(i18n("Network Error"), std::move(error));
|
||||||
job->abandon();
|
|
||||||
});
|
});
|
||||||
}
|
connect(conn, &Connection::loginError, [=](QString error, const QString &) {
|
||||||
|
Q_EMIT errorOccured(i18n("Login Failed"), std::move(error));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
connect(conn, &Connection::resolveError, this, [=](QString error) {
|
||||||
|
Q_EMIT globalErrorOccured(i18n("Network Error"), std::move(error));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void Controller::loginWithAccessToken(const QString &serverAddr, const QString &user, const QString &token, const QString &deviceName)
|
void Controller::loginWithAccessToken(const QString &serverAddr, const QString &user, const QString &token, const QString &deviceName)
|
||||||
|
|||||||
@@ -94,10 +94,10 @@ private Q_SLOTS:
|
|||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void busyChanged();
|
void busyChanged();
|
||||||
/// Error occured because of user inputs
|
/// Error occured because of user inputs
|
||||||
void errorOccured(QString _t1, QString _t2);
|
void errorOccured(QString error, QString detail);
|
||||||
|
|
||||||
/// Error occured because of server or bug in NeoChat
|
/// Error occured because of server or bug in NeoChat
|
||||||
void globalErrorOccured(QString _t1, QString _t2);
|
void globalErrorOccured(QString error, QString detail);
|
||||||
void syncDone();
|
void syncDone();
|
||||||
void connectionAdded(Quotient::Connection *_t1);
|
void connectionAdded(Quotient::Connection *_t1);
|
||||||
void connectionDropped(Quotient::Connection *_t1);
|
void connectionDropped(Quotient::Connection *_t1);
|
||||||
|
|||||||
Reference in New Issue
Block a user