From 8b43d237336c870bcf13f4c4b31c51b12f65d602 Mon Sep 17 00:00:00 2001 From: dorian Date: Tue, 25 Dec 2018 20:34:53 +0100 Subject: [PATCH] - moved the login management to cpp --- CHANGELOG => CHANGELOG.md | 12 +++-- android-sources/AndroidManifest.xml | 2 +- headers/serverconn.h | 9 ++-- qml/Forms/EventForm.qml | 2 +- qml/Forms/FoodPlanForm.qml | 2 +- qml/Forms/HomeForm.qml | 2 +- qml/Pages/LoginPage.qml | 2 +- qml/main.qml | 79 +---------------------------- sources/serverconn.cpp | 29 +++++++++-- 9 files changed, 47 insertions(+), 92 deletions(-) rename CHANGELOG => CHANGELOG.md (85%) diff --git a/CHANGELOG b/CHANGELOG.md similarity index 85% rename from CHANGELOG rename to CHANGELOG.md index 7e713a3..7786fb5 100644 --- a/CHANGELOG +++ b/CHANGELOG.md @@ -1,9 +1,15 @@ # Changelog Jegliche Veräderungen werden hier dokumentiert -## [Unveröffentlicht] +## [0.9.0] - ALPHA - 2018-12-25 ### Geändert -- Auf der Anmelde Seite ist jetzt der gesamte Text auf deutsch +- Komplett neues Design +- der Vertretungsplan wird jetzt innerhalb der App angezeigt +- Auf der Anmelde-Seite ist jetzt der gesamte Text auf deutsch +- Die fanny-Webseite wird jetzt nicht mehr innerhalb der App angezeigt + +### Behoben +- Viele interne Verbesserungen, die zu besserer performance führen ## [0.04] - 2018-07-19 ### Behoben @@ -60,4 +66,4 @@ ohne Internetverbindung gestertet und diese dann während die app lief wieder he - Anzeigen des Vertretungsplanes - Anzeigen der Fanny-Webseite - Anmelden und angemeldet bleiben -- Abmelden \ No newline at end of file +- Abmelden diff --git a/android-sources/AndroidManifest.xml b/android-sources/AndroidManifest.xml index 9a9bb63..7a4aca8 100644 --- a/android-sources/AndroidManifest.xml +++ b/android-sources/AndroidManifest.xml @@ -1,5 +1,5 @@ - + diff --git a/headers/serverconn.h b/headers/serverconn.h index 12853f8..0580da5 100644 --- a/headers/serverconn.h +++ b/headers/serverconn.h @@ -27,7 +27,7 @@ typedef struct strReturnData{ class ServerConn : public QObject { Q_OBJECT - Q_PROPERTY(QString state READ getState WRITE setState NOTIFY stateChanged) + Q_PROPERTY(QString state READ getState NOTIFY stateChanged) private: QString state; @@ -41,14 +41,17 @@ private: int authErrorCount; ReturnData_t senddata(QUrl serviceUrl, QUrlQuery postData); + +private slots: void updateProgress(qint64 read, qint64 total); void setState(QString state); -public slots: +public: explicit ServerConn(QObject *parent = nullptr); ~ServerConn(); +public slots: Q_INVOKABLE int login(QString username, QString password, bool permanent); Q_INVOKABLE int logout(); Q_INVOKABLE QString getDay(QString day); @@ -60,7 +63,7 @@ public slots: Q_INVOKABLE QString getState(); signals: - void stateChanged(); + void stateChanged(QString newState); public: QList> m_weekplan; diff --git a/qml/Forms/EventForm.qml b/qml/Forms/EventForm.qml index e2eb3d5..623be06 100644 --- a/qml/Forms/EventForm.qml +++ b/qml/Forms/EventForm.qml @@ -58,7 +58,7 @@ Page { running: true repeat: false onTriggered: { - status = _cppServerConn.getEvents(day) + status = serverConn.getEvents(day) pageLoader.source = "../Components/EventView.qml" } } diff --git a/qml/Forms/FoodPlanForm.qml b/qml/Forms/FoodPlanForm.qml index 74ade4d..46892d9 100644 --- a/qml/Forms/FoodPlanForm.qml +++ b/qml/Forms/FoodPlanForm.qml @@ -59,7 +59,7 @@ Page { running: true repeat: false onTriggered: { - root.status = _cppServerConn.getFoodPlan() + root.status = serverConn.getFoodPlan() pageLoader.source = "../Components/FoodPlanView.qml" } } diff --git a/qml/Forms/HomeForm.qml b/qml/Forms/HomeForm.qml index 2377c76..760fee7 100644 --- a/qml/Forms/HomeForm.qml +++ b/qml/Forms/HomeForm.qml @@ -177,7 +177,7 @@ Page { } } onAccepted: { - _cppServerConn.logout() + serverConn.logout() app.state = "notLoggedIn" } } diff --git a/qml/Pages/LoginPage.qml b/qml/Pages/LoginPage.qml index e1b1637..32880fc 100644 --- a/qml/Pages/LoginPage.qml +++ b/qml/Pages/LoginPage.qml @@ -218,7 +218,7 @@ Page { console.log(username, password, permanent) // trigger the login fucntion of the cpp backend and store the return code - var ret = _cppServerConn.login(username, password, permanent); + var ret = serverConn.login(username, password, permanent); // the request has finished // close the busy dialog diff --git a/qml/main.qml b/qml/main.qml index 0c97bda..8dc3ea5 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -49,72 +49,9 @@ ApplicationWindow { ServerConn { id: serverConn - } -// onBeforeRendering: { -// if(!firstinitdone){ -// var isinit = _cppAppSettings.loadSetting("permanent") -// console.log("getinit"); -// console.log(isinit); -// if(isinit === "0"){ -// stackView.push("qrc:/LoginPage.qml", {}); -// } -// } -// firstinitdone = true -// } - - Timer { - //runs only one time at applictaion lauch - property bool finished: true - id: initTimer - interval: 1; - running: true - repeat: false - onTriggered: { - var init = _cppAppSettings.loadSetting("init") - var perm = _cppAppSettings.loadSetting("permanent") - console.log("checkoldlogin:", perm); - if(perm === "1"){ - console.log("Perm") - var ret = _cppServerConn.login(_cppAppSettings.loadSetting("username"), _cppAppSettings.loadSetting("password"), true); - if(ret === "OK"){ - app.initdone = true - _cppAppSettings.writeSetting("init", 1); - if(app.state !== "loggedIn"){ - app.state = "loggedIn" - } - app.is_error = false; - } - else if(ret === "Keine Verbindung zum Server."){ - handleError(0) - //initTimer.interval = 1000 - finished = true - return - } - - else { - ret = _cppServerConn.checkConn() - app.handleError(ret) - } - } - else { - app.initdone = false - if(app.state !== "notLoggedIn"){ - app.state = "notLoggedIn" - } - } - app.initdone = true - } - } - - Timer { - id: refreshTimer - interval: 1000; - running: app.initdone && app.state !== "notLoggedIn" - repeat: true - onTriggered: { - var ret = _cppServerConn.checkConn() - app.handleError(ret) + onStateChanged: { + app.state = newState } } @@ -142,18 +79,6 @@ ApplicationWindow { } } - function handleError(error_code){ - if(error_code === 401){ - console.warn("401") - if(app.state !== "notLoggedIn"){ - console.log("switching to login page") - app.state = "notLoggedIn" - } - app.is_error = true; - app.error = "Nicht angemeldet!!"; - } - } - function getErrorInfo(errorCode) { var infoLevel diff --git a/sources/serverconn.cpp b/sources/serverconn.cpp index ba95852..9ce2d34 100644 --- a/sources/serverconn.cpp +++ b/sources/serverconn.cpp @@ -4,18 +4,33 @@ ServerConn * pGlobalServConn = nullptr; ServerConn::ServerConn(QObject *parent) : QObject(parent) { - qDebug("serverconn konstruktor"); + qDebug("+----- serverconn konstruktor -----+"); pGlobalServConn = this; this->networkManager = new QNetworkAccessManager(); this->refreshNetworkManager = new QNetworkAccessManager(); + // check login state + int perm = pGlobalAppSettings->loadSetting("permanent").toInt(); + qDebug() << "+-- login state: " << perm; + + if(perm == 1){ + // permanent login + // restore login + this->username = pGlobalAppSettings->loadSetting("username"); + this->password = pGlobalAppSettings->loadSetting("password"); + + this->setState("loggedIn"); + } + else { + this->setState("notLoggedIn"); + } + this->checkConnTimer = new QTimer(); this->checkConnTimer->setInterval(1000); this->checkConnTimer->setSingleShot(true); + connect(checkConnTimer, SIGNAL(timeout()), this, SLOT(checkConn())); this->checkConnTimer->start(); - connect(this->checkConnTimer, &QTimer::timeout, this, &ServerConn::checkConn); - } int ServerConn::login(QString username, QString password, bool permanent) @@ -72,11 +87,14 @@ int ServerConn::login(QString username, QString password, bool permanent) pGlobalAppSettings->writeSetting("password", password); } + this->setState("loggedIn"); + // return success return(200); } else { // if not 404 was returned -> error -> return the return code + this->setState("notLoggedIn"); return(status_code); } } @@ -90,6 +108,8 @@ int ServerConn::logout() pGlobalAppSettings->writeSetting("permanent", "0"); pGlobalAppSettings->writeSetting("username", ""); pGlobalAppSettings->writeSetting("password", ""); + + this->setState("notLoggedIn"); // return success return(200); } @@ -172,7 +192,7 @@ int ServerConn::checkConn() QEventLoop loop; loop.connect(this->refreshNetworkManager, SIGNAL(finished(QNetworkReply*)), SLOT(quit())); - loop.connect(&timer, SLOT(timeout()), SLOT(quit())); + loop.connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit())); loop.exec(); int status_code = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); @@ -744,6 +764,7 @@ QString ServerConn::getState() { void ServerConn::setState(QString state) { this->state = state; + this->stateChanged(this->state); } ServerConn::~ServerConn()