forked from ondra/colnod-connector
stopep using config file
This commit is contained in:
parent
83c77c9b1c
commit
94edc63f5e
@ -7,14 +7,14 @@ RequestManager::RequestManager()
|
||||
loginStatus = false; //should be false, true for testing request header
|
||||
|
||||
|
||||
|
||||
/*
|
||||
QFile configFile(QDir::current().filePath("config.json"));
|
||||
if (!configFile.open(QIODevice::ReadOnly)) {
|
||||
qCritical() << "Couldn't open config file config.json" << QDir::current().filePath("config.json");
|
||||
QCoreApplication::exit(-1);
|
||||
return;
|
||||
}
|
||||
this->config = QJsonDocument::fromJson(configFile.readAll());
|
||||
this->config = QJsonDocument::fromJson(configFile.readAll());*/
|
||||
QObject::connect(manager, &QNetworkAccessManager::sslErrors, this, &RequestManager::onSSLError);
|
||||
}
|
||||
|
||||
@ -55,7 +55,8 @@ void RequestManager::getRequest(QString endpoint)
|
||||
{
|
||||
if (!loginStatus)
|
||||
{
|
||||
login(config.object()["host"].toString(), config.object()["username"].toString(), config.object()["password"].toString());
|
||||
// login(config.object()["host"].toString(), config.object()["username"].toString(), config.object()["password"].toString());
|
||||
login(host, user, password);
|
||||
// QEventLoop loop;
|
||||
// QObject::connect(this, &RequestManager::successLogin, &loop, &QEventLoop::quit);
|
||||
// loop.exec();
|
||||
|
||||
@ -1,72 +1,74 @@
|
||||
#ifndef REQUESTMANAGER_H
|
||||
#define REQUESTMANAGER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QNetworkReply>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkRequest>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <qcoreapplication.h>
|
||||
#include <qnetworkreply.h>
|
||||
#include <QByteArray>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonParseError>
|
||||
#include <QFile>
|
||||
#include <QString>
|
||||
#include <QMultiMap>
|
||||
#include <QPointer>
|
||||
#include <QDir>
|
||||
#include <QSslError>
|
||||
|
||||
|
||||
#include "databasemanager.h"
|
||||
#include "token.h"
|
||||
#include "subject.h"
|
||||
|
||||
class RequestManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
RequestManager();
|
||||
void getSubjects();
|
||||
void login(QString endpoint, QString username, QString password);
|
||||
void getRequest(QString endpoint);
|
||||
void loadSubjectsFromColnodToDB();
|
||||
|
||||
|
||||
|
||||
const QJsonDocument &getConfig() const {return config;}
|
||||
const QString &getResponse() const {return jsonResponse;}
|
||||
QString getToken(){return token;}
|
||||
|
||||
private:
|
||||
|
||||
QString getFromJson(QString json, const QString &member);
|
||||
QString encryptedPassword(QString password);
|
||||
QString getLoginHeader(QString username, QString hash);
|
||||
void prepareAuthHeader();
|
||||
|
||||
private slots:
|
||||
void onSSLError(QNetworkReply *reply, const QList<QSslError> &errors);
|
||||
|
||||
signals:
|
||||
void successLogin();
|
||||
void responseReady();
|
||||
|
||||
|
||||
private:
|
||||
QNetworkAccessManager* manager;
|
||||
QJsonDocument config;
|
||||
QString authHeader;
|
||||
QString host;
|
||||
QString token;
|
||||
QString jsonResponse;
|
||||
bool loginStatus;
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // REQUESTMANAGER_H
|
||||
#ifndef REQUESTMANAGER_H
|
||||
#define REQUESTMANAGER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QNetworkReply>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkRequest>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <qcoreapplication.h>
|
||||
#include <qnetworkreply.h>
|
||||
#include <QByteArray>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonParseError>
|
||||
#include <QFile>
|
||||
#include <QString>
|
||||
#include <QMultiMap>
|
||||
#include <QPointer>
|
||||
#include <QDir>
|
||||
#include <QSslError>
|
||||
|
||||
|
||||
#include "databasemanager.h"
|
||||
#include "token.h"
|
||||
#include "subject.h"
|
||||
|
||||
class RequestManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
RequestManager();
|
||||
void getSubjects();
|
||||
void login(QString endpoint, QString username, QString password);
|
||||
void getRequest(QString endpoint);
|
||||
void loadSubjectsFromColnodToDB();
|
||||
|
||||
|
||||
|
||||
const QJsonDocument &getConfig() const {return config;}
|
||||
const QString &getResponse() const {return jsonResponse;}
|
||||
QString getToken(){return token;}
|
||||
|
||||
private:
|
||||
|
||||
QString getFromJson(QString json, const QString &member);
|
||||
QString encryptedPassword(QString password);
|
||||
QString getLoginHeader(QString username, QString hash);
|
||||
void prepareAuthHeader();
|
||||
|
||||
private slots:
|
||||
void onSSLError(QNetworkReply *reply, const QList<QSslError> &errors);
|
||||
|
||||
signals:
|
||||
void successLogin();
|
||||
void responseReady();
|
||||
|
||||
|
||||
private:
|
||||
QNetworkAccessManager* manager;
|
||||
QJsonDocument config;
|
||||
QString authHeader;
|
||||
QString host = "https://192.168.1.3:8443";
|
||||
QString password = "spaceti1";
|
||||
QString user = "spaceti";
|
||||
QString token;
|
||||
QString jsonResponse;
|
||||
bool loginStatus;
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // REQUESTMANAGER_H
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user