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
|
||||
contentItem: Kirigami.InlineMessage {
|
||||
id: inlineMessage
|
||||
type: Kirigami.MessageType.Error
|
||||
visible: false
|
||||
showCloseButton: true
|
||||
}
|
||||
@@ -74,7 +73,8 @@ Kirigami.ScrollablePage {
|
||||
Connections {
|
||||
target: Controller
|
||||
onErrorOccured: {
|
||||
if (detail.length !== 0) {
|
||||
inlineMessage.type = Kirigami.MessageType.Error;
|
||||
if (detail && detail.length !== 0) {
|
||||
inlineMessage.text = i18n("%1: %2", error, detail);
|
||||
} else {
|
||||
inlineMessage.text = error;
|
||||
@@ -85,6 +85,9 @@ Kirigami.ScrollablePage {
|
||||
}
|
||||
|
||||
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) {
|
||||
Controller.loginWithAccessToken(serverField.text.trim(), usernameField.text.trim(), accessTokenField.text, deviceNameField.text.trim());
|
||||
} else {
|
||||
|
||||
@@ -99,50 +99,43 @@ void Controller::loginWithCredentials(const QString &serverAddr, const QString &
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (deviceName.isEmpty()) {
|
||||
deviceName = "NeoChat " + QSysInfo::machineHostName() + " " + QSysInfo::productType() + " " + QSysInfo::productVersion() + " " + QSysInfo::currentCpuArchitecture();
|
||||
}
|
||||
|
||||
QUrl serverUrl(serverAddr);
|
||||
|
||||
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()) {
|
||||
conn->setHomeserver(serverUrl);
|
||||
auto *job = conn->callApi<GetWellknownJob>();
|
||||
connect(job, &BaseJob::finished, this, [=]() {
|
||||
if (job->status() == BaseJob::Success) {
|
||||
QUrl url(job->data().homeserver.baseUrl);
|
||||
auto finalConn = new Connection(this);
|
||||
finalConn->setHomeserver(url);
|
||||
finalConn->connectToServer(user, pass, deviceName, "");
|
||||
connect(finalConn, &Connection::connected, this, [=] {
|
||||
AccountSettings account(finalConn->userId());
|
||||
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));
|
||||
});
|
||||
connect(conn, &Connection::homeserverChanged, this, [this, user, conn, pass, deviceName]() {
|
||||
conn->connectToServer(user, pass, deviceName, "");
|
||||
connect(conn, &Connection::connected, this, [this, conn, deviceName] {
|
||||
AccountSettings account(conn->userId());
|
||||
account.setKeepLoggedIn(true);
|
||||
account.clearAccessToken(); // Drop the legacy - just in case
|
||||
account.setHomeserver(conn->homeserver());
|
||||
account.setDeviceId(conn->deviceId());
|
||||
account.setDeviceName(deviceName);
|
||||
if (!saveAccessTokenToKeyChain(account, conn->accessToken())) {
|
||||
qWarning() << "Couldn't save access token";
|
||||
}
|
||||
account.sync();
|
||||
addConnection(conn);
|
||||
setActiveConnection(conn);
|
||||
});
|
||||
connect(job, &BaseJob::retryScheduled, this, [=](int, Quotient::BaseJob::duration_ms_t) {
|
||||
Q_EMIT errorOccured(i18n("%1 is not a matrix server or is unreachable", serverUrl.toString()), QString());
|
||||
job->abandon();
|
||||
connect(conn, &Connection::networkError, [=](QString error, const QString &, int, int) {
|
||||
Q_EMIT globalErrorOccured(i18n("Network Error"), std::move(error));
|
||||
});
|
||||
}
|
||||
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)
|
||||
|
||||
@@ -94,10 +94,10 @@ private Q_SLOTS:
|
||||
Q_SIGNALS:
|
||||
void busyChanged();
|
||||
/// 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
|
||||
void globalErrorOccured(QString _t1, QString _t2);
|
||||
void globalErrorOccured(QString error, QString detail);
|
||||
void syncDone();
|
||||
void connectionAdded(Quotient::Connection *_t1);
|
||||
void connectionDropped(Quotient::Connection *_t1);
|
||||
|
||||
Reference in New Issue
Block a user