implemented ssl(https) for user data transfer (finally :D)
This commit is contained in:
parent
68a25689dc
commit
c82337d693
2 changed files with 14 additions and 9 deletions
|
@ -54,15 +54,16 @@ private:
|
||||||
QString password;
|
QString password;
|
||||||
QNetworkAccessManager *networkManager;
|
QNetworkAccessManager *networkManager;
|
||||||
QNetworkAccessManager *refreshNetworkManager;
|
QNetworkAccessManager *refreshNetworkManager;
|
||||||
|
QNetworkReply *networkReply;
|
||||||
QTimer *checkConnTimer;
|
QTimer *checkConnTimer;
|
||||||
int authErrorCount;
|
int authErrorCount;
|
||||||
|
|
||||||
ReturnData_t senddata(QUrl serviceUrl, QUrlQuery postData);
|
ReturnData_t senddata(QUrl serviceUrl, QUrlQuery postData);
|
||||||
|
|
||||||
|
|
||||||
QList<int> apiVersion = {0,2,1};
|
QList<int> apiVersion = {0,2,1};
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
|
||||||
void setState(QString state);
|
void setState(QString state);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -59,7 +59,7 @@ int ServerConn::login(QString username, QString password, bool permanent)
|
||||||
pdata.addQueryItem("password", password);
|
pdata.addQueryItem("password", password);
|
||||||
|
|
||||||
// send the request
|
// send the request
|
||||||
ReturnData_t ret = this->senddata(QUrl("http://www.fanny-leicht.de/j34/templates/g5_helium/intern/events.php"), pdata);
|
ReturnData_t ret = this->senddata(QUrl("https://www.fanny-leicht.de/j34/templates/g5_helium/intern/events.php"), pdata);
|
||||||
|
|
||||||
if(ret.status_code == 200){
|
if(ret.status_code == 200){
|
||||||
// if not 200 was returned -> user data was correct
|
// if not 200 was returned -> user data was correct
|
||||||
|
@ -124,7 +124,7 @@ int ServerConn::checkConn()
|
||||||
pdata.addQueryItem("password", this->password);
|
pdata.addQueryItem("password", this->password);
|
||||||
|
|
||||||
// send the request
|
// send the request
|
||||||
ReturnData_t ret = this->senddata(QUrl("http://www.fanny-leicht.de/j34/templates/g5_helium/intern/events.php"), pdata);
|
ReturnData_t ret = this->senddata(QUrl("https://www.fanny-leicht.de/j34/templates/g5_helium/intern/events.php"), pdata);
|
||||||
|
|
||||||
if(ret.status_code == 401){
|
if(ret.status_code == 401){
|
||||||
// if the stats code is 401 -> userdata is incorrect
|
// if the stats code is 401 -> userdata is incorrect
|
||||||
|
@ -155,7 +155,7 @@ int ServerConn::getEvents(QString day)
|
||||||
pdata.addQueryItem("day", day);
|
pdata.addQueryItem("day", day);
|
||||||
|
|
||||||
// send the request
|
// send the request
|
||||||
ReturnData_t ret = this->senddata(QUrl("http://www.fanny-leicht.de/j34/templates/g5_helium/intern/events.php"), pdata);
|
ReturnData_t ret = this->senddata(QUrl("https://www.fanny-leicht.de/j34/templates/g5_helium/intern/events.php"), pdata);
|
||||||
|
|
||||||
if(ret.status_code != 200){
|
if(ret.status_code != 200){
|
||||||
// if the request didn't result in a success, clear the old events, as they are probaply incorrect and return the error code
|
// if the request didn't result in a success, clear the old events, as they are probaply incorrect and return the error code
|
||||||
|
@ -369,11 +369,16 @@ ReturnData_t ServerConn::senddata(QUrl serviceUrl, QUrlQuery pdata)
|
||||||
request.setHeader(QNetworkRequest::ContentTypeHeader,
|
request.setHeader(QNetworkRequest::ContentTypeHeader,
|
||||||
"application/x-www-form-urlencoded");
|
"application/x-www-form-urlencoded");
|
||||||
|
|
||||||
|
QSslConfiguration config = QSslConfiguration::defaultConfiguration();
|
||||||
|
config.setProtocol(QSsl::TlsV1_2);
|
||||||
|
request.setSslConfiguration(config);
|
||||||
|
|
||||||
//send a POST request with the given url and data to the server
|
//send a POST request with the given url and data to the server
|
||||||
|
|
||||||
QNetworkReply *reply;
|
QNetworkReply *reply;
|
||||||
|
|
||||||
reply = this->networkManager->post(request, pdata.toString(QUrl::FullyEncoded).toUtf8());
|
reply = this->networkManager->post(request, pdata.toString(QUrl::FullyEncoded).toUtf8());
|
||||||
|
connect(reply, &QNetworkReply::sslErrors, this, [=](){ reply->ignoreSslErrors(); });
|
||||||
// loop to wait until the request has finished before processing the data
|
// loop to wait until the request has finished before processing the data
|
||||||
QEventLoop loop;
|
QEventLoop loop;
|
||||||
// timer to cancel the request after 3 seconds
|
// timer to cancel the request after 3 seconds
|
||||||
|
@ -397,9 +402,8 @@ ReturnData_t ServerConn::senddata(QUrl serviceUrl, QUrlQuery pdata)
|
||||||
//get the full text response
|
//get the full text response
|
||||||
ret.text = QString::fromUtf8(reply->readAll());
|
ret.text = QString::fromUtf8(reply->readAll());
|
||||||
|
|
||||||
if(reply->isOpen()){
|
// delete the reply object
|
||||||
delete reply;
|
delete reply;
|
||||||
}
|
|
||||||
|
|
||||||
//return the data
|
//return the data
|
||||||
return(ret);
|
return(ret);
|
||||||
|
|
Reference in a new issue