mirror of
https://gitlab.com/niansa/qcommsy.git
synced 2025-03-06 20:53:33 +01:00
Updated
This commit is contained in:
parent
fec77a7967
commit
22b15b2ebb
2 changed files with 17 additions and 10 deletions
|
@ -14,6 +14,11 @@ class authFailureError : public std::exception {};
|
|||
|
||||
|
||||
class libCommsyAuth : QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
void reEmit(QNetworkReply *r);
|
||||
|
||||
public:
|
||||
QNetworkAccessManager *mNetMan = nullptr;
|
||||
QNetworkRequest *mNetReq = nullptr;
|
||||
|
@ -23,19 +28,20 @@ public:
|
|||
mNetReq = new QNetworkRequest();
|
||||
}
|
||||
|
||||
QNetworkReply *connect(const QUrl& serverBaseUrl) {
|
||||
void connectInit(const QUrl& serverBaseUrl) {
|
||||
// Initialise request
|
||||
//mNetReq->setTransferTimeout(15000);
|
||||
mNetReq->setUrl(serverBaseUrl);
|
||||
mNetReq->setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
|
||||
return mNetMan->get(*mNetReq);
|
||||
connect(mNetMan, &QNetworkAccessManager::finished, this, &libCommsyAuth::reEmit);
|
||||
mNetMan->get(*mNetReq);
|
||||
}
|
||||
|
||||
QString getAuthUrl(const QNetworkReply *reply) {
|
||||
return reply->url().toString();
|
||||
}
|
||||
|
||||
QNetworkReply *sendAuth(const QString& authUrl, const QString& username, const QString& password) {
|
||||
void sendAuth(const QString& authUrl, const QString& username, const QString& password) {
|
||||
QUrlQuery mNetQuery;
|
||||
// Set auth credentials
|
||||
mNetQuery.addQueryItem("user_id", username);
|
||||
|
@ -43,8 +49,9 @@ public:
|
|||
// Create request
|
||||
mNetReq->setUrl(authUrl + "&mod=context&fct=login");
|
||||
mNetReq->setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
|
||||
// Perform the request
|
||||
return mNetMan->post(*mNetReq, mNetQuery.toString(QUrl::FullyEncoded).toUtf8());
|
||||
// Perform the request return
|
||||
connect(mNetMan, &QNetworkAccessManager::finished, this, &libCommsyAuth::reEmit);
|
||||
mNetMan->post(*mNetReq, mNetQuery.toString(QUrl::FullyEncoded).toUtf8());
|
||||
}
|
||||
|
||||
QString getSID(QNetworkReply *reply) {
|
||||
|
|
10
main.cpp
10
main.cpp
|
@ -137,15 +137,13 @@ void _UILoader::loginWindow(QMainWindow *w, const QString& failure) {
|
|||
settings->setValue("server_url", thisui->adressLine->text());
|
||||
settings->setValue("server_room", thisui->roomLine->text());
|
||||
// Connect
|
||||
QNetworkReply *netReply = auther->connect(thisui->adressLine->text());
|
||||
w->connect(netReply, &QNetworkReply::finished, [this, thisui, w, netReply] () { // SIGSEGV
|
||||
w->connect(libCommsyAuth, &libCommsyAuth::reEmit, [this, thisui, w] (QNetworkReply *netReply) {
|
||||
std::cout << auther->getAuthUrl(netReply).toStdString() << std::endl;
|
||||
// Get SID
|
||||
QNetworkReply *netReply2 = auther->sendAuth(auther->getAuthUrl(netReply), thisui->usernameLine->text(), thisui->passwordLine->text());
|
||||
w->connect(netReply2, &QNetworkReply::readyRead, [this, thisui, w, netReply2] () {
|
||||
w->connect(libCommsyAuth, &libCommsyAuth::reEmit, [this, thisui, w] (QNetworkReply *netReply) {
|
||||
// Login
|
||||
try {
|
||||
settings->setValue("server_sid", auther->getSID(netReply2));
|
||||
settings->setValue("server_sid", auther->getSID(netReply));
|
||||
cacheInvalidate = true;
|
||||
overviewWindow(w, false);
|
||||
} catch (authFailureError&) {
|
||||
|
@ -154,7 +152,9 @@ void _UILoader::loginWindow(QMainWindow *w, const QString& failure) {
|
|||
thisui->failureText->setText("Der angegebene Raum existiert nicht");
|
||||
}
|
||||
});
|
||||
auther->sendAuth(auther->getAuthUrl(netReply), thisui->usernameLine->text(), thisui->passwordLine->text());
|
||||
});
|
||||
auther->connectInit(thisui->adressLine->text());
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue