- moved the login management to cpp

This commit is contained in:
Dorian Zedler 2018-12-25 20:34:53 +01:00
parent 4271bec598
commit 8b43d23733
9 changed files with 47 additions and 92 deletions

View file

@ -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
- Abmelden

View file

@ -1,5 +1,5 @@
<?xml version="1.0"?>
<manifest package="com.itsblue.flgvertretungtest" xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="0.04.1" android:versionCode="8" android:installLocation="auto">
<manifest package="com.itsblue.flgvertretung" xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="0.9.0" android:versionCode="9" android:installLocation="auto">
<application android:hardwareAccelerated="true" android:name="org.qtproject.qt5.android.bindings.QtApplication" android:label="fannyapp" android:icon="@drawable/icon">
<activity android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|layoutDirection|locale|fontScale|keyboard|keyboardHidden|navigation" android:name="com.itsblue.flgvertretung.MainActivity" android:label="fannyapp" android:screenOrientation="unspecified" android:launchMode="singleTop">

View file

@ -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<QList<QString>> m_weekplan;

View file

@ -58,7 +58,7 @@ Page {
running: true
repeat: false
onTriggered: {
status = _cppServerConn.getEvents(day)
status = serverConn.getEvents(day)
pageLoader.source = "../Components/EventView.qml"
}
}

View file

@ -59,7 +59,7 @@ Page {
running: true
repeat: false
onTriggered: {
root.status = _cppServerConn.getFoodPlan()
root.status = serverConn.getFoodPlan()
pageLoader.source = "../Components/FoodPlanView.qml"
}
}

View file

@ -177,7 +177,7 @@ Page {
}
}
onAccepted: {
_cppServerConn.logout()
serverConn.logout()
app.state = "notLoggedIn"
}
}

View file

@ -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

View file

@ -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

View file

@ -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()