mirror of
https://gitlab.com/niansa/qcommsy.git
synced 2025-03-06 20:53:33 +01:00
Fixed flow
This commit is contained in:
parent
6f2f703c9e
commit
702d79d9e6
2 changed files with 35 additions and 32 deletions
|
@ -20,29 +20,34 @@ class libCommsyAuth : public QObject {
|
|||
|
||||
public:
|
||||
Q_SIGNALS:
|
||||
void reEmit(QNetworkReply *r);
|
||||
void connectionDone(QNetworkReply *r);
|
||||
void authDone(QNetworkReply *r);
|
||||
|
||||
public:
|
||||
QNetworkAccessManager *mNetManTestconn = nullptr;
|
||||
QNetworkAccessManager *mNetManAuth = nullptr;
|
||||
QNetworkRequest *mNetReq = nullptr;
|
||||
|
||||
explicit libCommsyAuth(QObject *p = nullptr) : QObject (p){
|
||||
mNetMan = new QNetworkAccessManager(this);
|
||||
mNetManTestconn = new QNetworkAccessManager(this);
|
||||
mNetManAuth = new QNetworkAccessManager(this);
|
||||
mNetReq = new QNetworkRequest();
|
||||
connect(mNetMan, &QNetworkAccessManager::finished, this, &libCommsyAuth::reEmit);
|
||||
connect(mNetManTestconn, &QNetworkAccessManager::finished, this, &libCommsyAuth::connectionDone);
|
||||
connect(mNetManAuth, &QNetworkAccessManager::finished, this, &libCommsyAuth::authDone);
|
||||
}
|
||||
|
||||
~libCommsyAuth() {
|
||||
delete mNetMan;
|
||||
delete mNetManTestconn;
|
||||
delete mNetManAuth;
|
||||
delete mNetReq;
|
||||
}
|
||||
|
||||
QNetworkAccessManager *mNetMan = nullptr;
|
||||
QNetworkRequest *mNetReq = nullptr;
|
||||
|
||||
void connectInit(const QUrl& serverBaseUrl) {
|
||||
void connectionInit(const QUrl& serverBaseUrl) {
|
||||
// Initialise request
|
||||
//mNetReq->setTransferTimeout(15000);
|
||||
mNetReq->setUrl(serverBaseUrl);
|
||||
mNetReq->setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
|
||||
mNetMan->get(*mNetReq);
|
||||
mNetManTestconn->get(*mNetReq);
|
||||
}
|
||||
|
||||
QString getAuthUrl(const QNetworkReply *reply) {
|
||||
|
@ -61,7 +66,7 @@ public:
|
|||
mNetReq->setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
|
||||
|
||||
// Perform the request
|
||||
mNetMan->post(*mNetReq, mNetQuery.toString(QUrl::FullyEncoded).toUtf8());
|
||||
mNetManAuth->post(*mNetReq, mNetQuery.toString(QUrl::FullyEncoded).toUtf8());
|
||||
}
|
||||
|
||||
QString getSID(QNetworkReply *reply) {
|
||||
|
|
42
main.cpp
42
main.cpp
|
@ -135,6 +135,25 @@ void _UILoader::loginWindow(QMainWindow *w, const QString& failure) {
|
|||
// Set failure text
|
||||
thisui->failureText->setText(failure);
|
||||
|
||||
// Connect connection handlers
|
||||
w->connect(auther, &libCommsyAuth::authDone, [this, thisui, w] (QNetworkReply *netReply) {
|
||||
// Login
|
||||
try {
|
||||
settings->setValue("server_sid", auther->getSID(netReply));
|
||||
cacheInvalidate = true;
|
||||
overviewWindow(w, false);
|
||||
} catch (authFailureError&) {
|
||||
thisui->failureText->setText("Die eingegebenen Anmeldedaten sind ungültig");
|
||||
} catch (invalidRoomError&) {
|
||||
thisui->failureText->setText("Der angegebene Raum existiert nicht");
|
||||
}
|
||||
});
|
||||
w->connect(auther, &libCommsyAuth::connectionDone, [this, thisui, w] (QNetworkReply *netReply) {
|
||||
QString authUrl = auther->getAuthUrl(netReply);
|
||||
auther->sendAuth(authUrl, thisui->usernameLine->text(), thisui->passwordLine->text());
|
||||
});
|
||||
|
||||
|
||||
// Add button handlers
|
||||
w->connect(thisui->loginButton, &QPushButton::pressed, [this, thisui, w] () {
|
||||
// Check input lines
|
||||
|
@ -148,28 +167,7 @@ void _UILoader::loginWindow(QMainWindow *w, const QString& failure) {
|
|||
settings->setValue("server_room", thisui->roomLine->text());
|
||||
|
||||
// Connect
|
||||
w->connect(auther, &libCommsyAuth::reEmit, [this, thisui, w] (QNetworkReply *netReply) {
|
||||
auther->disconnect();
|
||||
|
||||
w->connect(auther, &libCommsyAuth::reEmit, [this, thisui, w] (QNetworkReply *netReply) {
|
||||
auther->disconnect();
|
||||
|
||||
// Login
|
||||
try {
|
||||
settings->setValue("server_sid", auther->getSID(netReply));
|
||||
cacheInvalidate = true;
|
||||
overviewWindow(w, false);
|
||||
} catch (authFailureError&) {
|
||||
thisui->failureText->setText("Die eingegebenen Anmeldedaten sind ungültig");
|
||||
} catch (invalidRoomError&) {
|
||||
thisui->failureText->setText("Der angegebene Raum existiert nicht");
|
||||
}
|
||||
});
|
||||
|
||||
auther->sendAuth(auther->getAuthUrl(netReply), thisui->usernameLine->text(), thisui->passwordLine->text());
|
||||
});
|
||||
|
||||
auther->connectInit(thisui->adressLine->text());
|
||||
auther->connectionInit(thisui->adressLine->text());
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue