mirror of
https://gitlab.com/spaceti-app/integrations/acs/colnod-connector.git
synced 2026-07-12 13:10:45 +02:00
test login using serversdk
This commit is contained in:
parent
7c49c7a1ec
commit
0e377a3554
@ -3,6 +3,8 @@
|
||||
#include "datamanager.h"
|
||||
#include "syncmanager.h"
|
||||
#include <QCommandLineParser>
|
||||
#include "serversdk/requestmanager.h"
|
||||
#include "serversdk/request.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
@ -20,27 +22,54 @@ int main(int argc, char *argv[])
|
||||
parser.addOption(createTablesOption);
|
||||
parser.process(app);
|
||||
SyncManager api(parser.isSet(dryModeOption));
|
||||
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();
|
||||
|
||||
//
|
||||
serversdk::RequestManager reqMan;
|
||||
QJsonObject reqBody;
|
||||
QByteArray hash(QCryptographicHash::hash(QString("spaceti1").toLocal8Bit(), QCryptographicHash::Sha512).toHex().toUpper());
|
||||
reqBody.insert("password", QJsonValue::fromVariant(hash));
|
||||
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.";
|
||||
}
|
||||
}
|
||||
});
|
||||
//
|
||||
|
||||
// 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();
|
||||
}
|
||||
|
||||
@ -4,6 +4,7 @@ CONFIG += c++14
|
||||
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/colnodapi.cpp \
|
||||
$$PWD/databasemanager.cpp \
|
||||
$$PWD/datamanager.cpp \
|
||||
$$PWD/entity.cpp \
|
||||
@ -15,6 +16,7 @@ SOURCES += \
|
||||
$$PWD/token.cpp
|
||||
|
||||
HEADERS += \
|
||||
$$PWD/colnodapi.h \
|
||||
$$PWD/databasemanager.h \
|
||||
$$PWD/datamanager.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}
|
||||
};
|
||||
request.setUrl(this->host + "/AaaManager/authSession");
|
||||
qDebug() << authHeader.toLocal8Bit();
|
||||
request.setRawHeader("Authorization", authHeader.toLocal8Bit());
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json; charset=UTF-8");
|
||||
QJsonDocument jsonDocument;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user