mirror of
https://gitlab.com/spaceti-app/integrations/acs/colnod-connector.git
synced 2026-07-12 14:30:50 +02:00
test login using serversdk
This commit is contained in:
parent
7c49c7a1ec
commit
0e377a3554
@ -3,6 +3,8 @@
|
|||||||
#include "datamanager.h"
|
#include "datamanager.h"
|
||||||
#include "syncmanager.h"
|
#include "syncmanager.h"
|
||||||
#include <QCommandLineParser>
|
#include <QCommandLineParser>
|
||||||
|
#include "serversdk/requestmanager.h"
|
||||||
|
#include "serversdk/request.h"
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
@ -20,27 +22,54 @@ int main(int argc, char *argv[])
|
|||||||
parser.addOption(createTablesOption);
|
parser.addOption(createTablesOption);
|
||||||
parser.process(app);
|
parser.process(app);
|
||||||
SyncManager api(parser.isSet(dryModeOption));
|
SyncManager api(parser.isSet(dryModeOption));
|
||||||
QObject::connect(&api, &SyncManager::error, &app, [](){
|
|
||||||
qDebug() << "error";
|
//
|
||||||
QCoreApplication::exit(1);
|
serversdk::RequestManager reqMan;
|
||||||
}, Qt::QueuedConnection);
|
QJsonObject reqBody;
|
||||||
if (parser.isSet(dropTablesOption)){
|
QByteArray hash(QCryptographicHash::hash(QString("spaceti1").toLocal8Bit(), QCryptographicHash::Sha512).toHex().toUpper());
|
||||||
api.dropTables();
|
reqBody.insert("password", QJsonValue::fromVariant(hash));
|
||||||
return 0;
|
reqBody.insert("username", "spaceti");
|
||||||
|
QJsonDocument doc(reqBody);
|
||||||
|
auto loginRequest = std::make_shared<serversdk::Request>("POST", "https://192.168.1.3:8443/AaaManager/authSession", doc.toJson());
|
||||||
|
loginRequest->setUserName("spaceti");
|
||||||
|
loginRequest->setPassword(hash);
|
||||||
|
reqMan.processRequest(loginRequest);
|
||||||
|
QObject::connect(loginRequest.get(), &serversdk::Request::finished, [=](){
|
||||||
|
if (loginRequest->networkReply()->error()) {
|
||||||
|
qDebug() << loginRequest->networkReply()->errorString();
|
||||||
|
qDebug() << "response data:" << loginRequest->responseData();
|
||||||
|
if (!loginRequest->responseData().isEmpty() && !loginRequest->responseData().contains("error")){
|
||||||
|
auto jsonDoc = QJsonDocument::fromJson(loginRequest->responseData());
|
||||||
|
QString token = jsonDoc.object()["id"].toString();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
qDebug() << "Login failed.";
|
||||||
}
|
}
|
||||||
if (parser.isSet(createTablesOption)){
|
|
||||||
api.createTables();
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
api.loadDataFromDB();
|
|
||||||
api.loadDataFromColnod();
|
|
||||||
QObject::connect(&api, &SyncManager::dataDownloaded, [&](){
|
|
||||||
QObject::connect(&api, &SyncManager::syncFinished, [](){
|
|
||||||
qDebug() << "Quit";
|
|
||||||
QCoreApplication::exit();
|
|
||||||
});
|
|
||||||
api.syncDataFromColnodToDB();
|
|
||||||
api.syncDataFromDBToColnod();
|
|
||||||
});
|
});
|
||||||
|
//
|
||||||
|
|
||||||
|
// QObject::connect(&api, &SyncManager::error, &app, [](){
|
||||||
|
// qDebug() << "error";
|
||||||
|
// QCoreApplication::exit(1);
|
||||||
|
// }, Qt::QueuedConnection);
|
||||||
|
// if (parser.isSet(dropTablesOption)){
|
||||||
|
// api.dropTables();
|
||||||
|
// return 0;
|
||||||
|
// }
|
||||||
|
// if (parser.isSet(createTablesOption)){
|
||||||
|
// api.createTables();
|
||||||
|
// return 0;
|
||||||
|
// }
|
||||||
|
// api.loadDataFromDB();
|
||||||
|
// api.loadDataFromColnod();
|
||||||
|
// QObject::connect(&api, &SyncManager::dataDownloaded, [&](){
|
||||||
|
// QObject::connect(&api, &SyncManager::syncFinished, [](){
|
||||||
|
// qDebug() << "Quit";
|
||||||
|
// QCoreApplication::exit();
|
||||||
|
// });
|
||||||
|
// api.syncDataFromColnodToDB();
|
||||||
|
// api.syncDataFromDBToColnod();
|
||||||
|
// });
|
||||||
return QCoreApplication::exec();
|
return QCoreApplication::exec();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,6 +4,7 @@ CONFIG += c++14
|
|||||||
|
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
|
$$PWD/colnodapi.cpp \
|
||||||
$$PWD/databasemanager.cpp \
|
$$PWD/databasemanager.cpp \
|
||||||
$$PWD/datamanager.cpp \
|
$$PWD/datamanager.cpp \
|
||||||
$$PWD/entity.cpp \
|
$$PWD/entity.cpp \
|
||||||
@ -15,6 +16,7 @@ SOURCES += \
|
|||||||
$$PWD/token.cpp
|
$$PWD/token.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
|
$$PWD/colnodapi.h \
|
||||||
$$PWD/databasemanager.h \
|
$$PWD/databasemanager.h \
|
||||||
$$PWD/datamanager.h \
|
$$PWD/datamanager.h \
|
||||||
$$PWD/entity.h \
|
$$PWD/entity.h \
|
||||||
|
|||||||
6
src/colnod/colnodapi.cpp
Normal file
6
src/colnod/colnodapi.cpp
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#include "colnodapi.h"
|
||||||
|
|
||||||
|
ColnodAPI::ColnodAPI()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
15
src/colnod/colnodapi.h
Normal file
15
src/colnod/colnodapi.h
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "serversdk/requestmanager.h"
|
||||||
|
#include "serversdk/request.h"
|
||||||
|
|
||||||
|
|
||||||
|
class ColnodAPI: public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
ColnodAPI();
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
@ -18,6 +18,7 @@ std::shared_ptr<Response> RequestManager::login()
|
|||||||
{"username", this->user}
|
{"username", this->user}
|
||||||
};
|
};
|
||||||
request.setUrl(this->host + "/AaaManager/authSession");
|
request.setUrl(this->host + "/AaaManager/authSession");
|
||||||
|
qDebug() << authHeader.toLocal8Bit();
|
||||||
request.setRawHeader("Authorization", authHeader.toLocal8Bit());
|
request.setRawHeader("Authorization", authHeader.toLocal8Bit());
|
||||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json; charset=UTF-8");
|
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json; charset=UTF-8");
|
||||||
QJsonDocument jsonDocument;
|
QJsonDocument jsonDocument;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user