- moved the login management to cpp
This commit is contained in:
parent
4271bec598
commit
8b43d23733
9 changed files with 47 additions and 92 deletions
|
@ -1,9 +1,15 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
Jegliche Veräderungen werden hier dokumentiert
|
Jegliche Veräderungen werden hier dokumentiert
|
||||||
|
|
||||||
## [Unveröffentlicht]
|
## [0.9.0] - ALPHA - 2018-12-25
|
||||||
### Geändert
|
### 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
|
## [0.04] - 2018-07-19
|
||||||
### Behoben
|
### Behoben
|
||||||
|
@ -60,4 +66,4 @@ ohne Internetverbindung gestertet und diese dann während die app lief wieder he
|
||||||
- Anzeigen des Vertretungsplanes
|
- Anzeigen des Vertretungsplanes
|
||||||
- Anzeigen der Fanny-Webseite
|
- Anzeigen der Fanny-Webseite
|
||||||
- Anmelden und angemeldet bleiben
|
- Anmelden und angemeldet bleiben
|
||||||
- Abmelden
|
- Abmelden
|
|
@ -1,5 +1,5 @@
|
||||||
<?xml version="1.0"?>
|
<?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">
|
<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">
|
<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">
|
||||||
|
|
|
@ -27,7 +27,7 @@ typedef struct strReturnData{
|
||||||
class ServerConn : public QObject
|
class ServerConn : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(QString state READ getState WRITE setState NOTIFY stateChanged)
|
Q_PROPERTY(QString state READ getState NOTIFY stateChanged)
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString state;
|
QString state;
|
||||||
|
@ -41,14 +41,17 @@ private:
|
||||||
int authErrorCount;
|
int authErrorCount;
|
||||||
|
|
||||||
ReturnData_t senddata(QUrl serviceUrl, QUrlQuery postData);
|
ReturnData_t senddata(QUrl serviceUrl, QUrlQuery postData);
|
||||||
|
|
||||||
|
private slots:
|
||||||
void updateProgress(qint64 read, qint64 total);
|
void updateProgress(qint64 read, qint64 total);
|
||||||
|
|
||||||
void setState(QString state);
|
void setState(QString state);
|
||||||
|
|
||||||
public slots:
|
public:
|
||||||
explicit ServerConn(QObject *parent = nullptr);
|
explicit ServerConn(QObject *parent = nullptr);
|
||||||
~ServerConn();
|
~ServerConn();
|
||||||
|
|
||||||
|
public slots:
|
||||||
Q_INVOKABLE int login(QString username, QString password, bool permanent);
|
Q_INVOKABLE int login(QString username, QString password, bool permanent);
|
||||||
Q_INVOKABLE int logout();
|
Q_INVOKABLE int logout();
|
||||||
Q_INVOKABLE QString getDay(QString day);
|
Q_INVOKABLE QString getDay(QString day);
|
||||||
|
@ -60,7 +63,7 @@ public slots:
|
||||||
Q_INVOKABLE QString getState();
|
Q_INVOKABLE QString getState();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void stateChanged();
|
void stateChanged(QString newState);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QList<QList<QString>> m_weekplan;
|
QList<QList<QString>> m_weekplan;
|
||||||
|
|
|
@ -58,7 +58,7 @@ Page {
|
||||||
running: true
|
running: true
|
||||||
repeat: false
|
repeat: false
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
status = _cppServerConn.getEvents(day)
|
status = serverConn.getEvents(day)
|
||||||
pageLoader.source = "../Components/EventView.qml"
|
pageLoader.source = "../Components/EventView.qml"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,7 @@ Page {
|
||||||
running: true
|
running: true
|
||||||
repeat: false
|
repeat: false
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
root.status = _cppServerConn.getFoodPlan()
|
root.status = serverConn.getFoodPlan()
|
||||||
pageLoader.source = "../Components/FoodPlanView.qml"
|
pageLoader.source = "../Components/FoodPlanView.qml"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -177,7 +177,7 @@ Page {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
onAccepted: {
|
onAccepted: {
|
||||||
_cppServerConn.logout()
|
serverConn.logout()
|
||||||
app.state = "notLoggedIn"
|
app.state = "notLoggedIn"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -218,7 +218,7 @@ Page {
|
||||||
console.log(username, password, permanent)
|
console.log(username, password, permanent)
|
||||||
|
|
||||||
// trigger the login fucntion of the cpp backend and store the return code
|
// 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
|
// the request has finished
|
||||||
// close the busy dialog
|
// close the busy dialog
|
||||||
|
|
79
qml/main.qml
79
qml/main.qml
|
@ -49,72 +49,9 @@ ApplicationWindow {
|
||||||
|
|
||||||
ServerConn {
|
ServerConn {
|
||||||
id: serverConn
|
id: serverConn
|
||||||
}
|
|
||||||
|
|
||||||
// onBeforeRendering: {
|
onStateChanged: {
|
||||||
// if(!firstinitdone){
|
app.state = newState
|
||||||
// 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)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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) {
|
function getErrorInfo(errorCode) {
|
||||||
|
|
||||||
var infoLevel
|
var infoLevel
|
||||||
|
|
|
@ -4,18 +4,33 @@ ServerConn * pGlobalServConn = nullptr;
|
||||||
|
|
||||||
ServerConn::ServerConn(QObject *parent) : QObject(parent)
|
ServerConn::ServerConn(QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
qDebug("serverconn konstruktor");
|
qDebug("+----- serverconn konstruktor -----+");
|
||||||
pGlobalServConn = this;
|
pGlobalServConn = this;
|
||||||
this->networkManager = new QNetworkAccessManager();
|
this->networkManager = new QNetworkAccessManager();
|
||||||
this->refreshNetworkManager = 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 = new QTimer();
|
||||||
this->checkConnTimer->setInterval(1000);
|
this->checkConnTimer->setInterval(1000);
|
||||||
this->checkConnTimer->setSingleShot(true);
|
this->checkConnTimer->setSingleShot(true);
|
||||||
|
connect(checkConnTimer, SIGNAL(timeout()), this, SLOT(checkConn()));
|
||||||
this->checkConnTimer->start();
|
this->checkConnTimer->start();
|
||||||
|
|
||||||
connect(this->checkConnTimer, &QTimer::timeout, this, &ServerConn::checkConn);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int ServerConn::login(QString username, QString password, bool permanent)
|
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);
|
pGlobalAppSettings->writeSetting("password", password);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this->setState("loggedIn");
|
||||||
|
|
||||||
// return success
|
// return success
|
||||||
return(200);
|
return(200);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// if not 404 was returned -> error -> return the return code
|
// if not 404 was returned -> error -> return the return code
|
||||||
|
this->setState("notLoggedIn");
|
||||||
return(status_code);
|
return(status_code);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,6 +108,8 @@ int ServerConn::logout()
|
||||||
pGlobalAppSettings->writeSetting("permanent", "0");
|
pGlobalAppSettings->writeSetting("permanent", "0");
|
||||||
pGlobalAppSettings->writeSetting("username", "");
|
pGlobalAppSettings->writeSetting("username", "");
|
||||||
pGlobalAppSettings->writeSetting("password", "");
|
pGlobalAppSettings->writeSetting("password", "");
|
||||||
|
|
||||||
|
this->setState("notLoggedIn");
|
||||||
// return success
|
// return success
|
||||||
return(200);
|
return(200);
|
||||||
}
|
}
|
||||||
|
@ -172,7 +192,7 @@ int ServerConn::checkConn()
|
||||||
|
|
||||||
QEventLoop loop;
|
QEventLoop loop;
|
||||||
loop.connect(this->refreshNetworkManager, SIGNAL(finished(QNetworkReply*)), SLOT(quit()));
|
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();
|
loop.exec();
|
||||||
|
|
||||||
int status_code = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
int status_code = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||||
|
@ -744,6 +764,7 @@ QString ServerConn::getState() {
|
||||||
|
|
||||||
void ServerConn::setState(QString state) {
|
void ServerConn::setState(QString state) {
|
||||||
this->state = state;
|
this->state = state;
|
||||||
|
this->stateChanged(this->state);
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerConn::~ServerConn()
|
ServerConn::~ServerConn()
|
||||||
|
|
Reference in a new issue