mirror of
https://gitlab.com/comunic/comunicwatcher
synced 2024-11-22 05:19:25 +00:00
Start service
This commit is contained in:
parent
b9b509aca1
commit
7244068ad5
@ -18,14 +18,16 @@ SOURCES += \
|
|||||||
apirequest.cpp \
|
apirequest.cpp \
|
||||||
apiresponse.cpp \
|
apiresponse.cpp \
|
||||||
main.cpp \
|
main.cpp \
|
||||||
loginwindow.cpp
|
loginwindow.cpp \
|
||||||
|
refreshservice.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
accounthelper.h \
|
accounthelper.h \
|
||||||
apirequest.h \
|
apirequest.h \
|
||||||
apiresponse.h \
|
apiresponse.h \
|
||||||
config.h \
|
config.h \
|
||||||
loginwindow.h
|
loginwindow.h \
|
||||||
|
refreshservice.h
|
||||||
|
|
||||||
FORMS += \
|
FORMS += \
|
||||||
loginwindow.ui
|
loginwindow.ui
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
#include "accounthelper.h"
|
#include "accounthelper.h"
|
||||||
#include "apirequest.h"
|
#include "apirequest.h"
|
||||||
|
|
||||||
AccountHelper::AccountHelper()
|
#include <QSettings>
|
||||||
{
|
|
||||||
|
|
||||||
}
|
#define LOGIN_TOKEN_VALUE "login_token"
|
||||||
|
|
||||||
void AccountHelper::LoginUser(const QString &email, const QString &password, const vLoginCallback cb)
|
void AccountHelper::LoginUser(const QString &email, const QString &password, const vLoginCallback cb)
|
||||||
{
|
{
|
||||||
@ -21,6 +20,7 @@ void AccountHelper::LoginUser(const QString &email, const QString &password, con
|
|||||||
case 200:
|
case 200:
|
||||||
// Save login token
|
// Save login token
|
||||||
token = res.getObject().value("tokens").toObject().value("token1").toString();
|
token = res.getObject().value("tokens").toObject().value("token1").toString();
|
||||||
|
QSettings().setValue(LOGIN_TOKEN_VALUE, token);
|
||||||
|
|
||||||
cb(LoginResult::SUCCESS);
|
cb(LoginResult::SUCCESS);
|
||||||
break;
|
break;
|
||||||
@ -40,3 +40,18 @@ void AccountHelper::LoginUser(const QString &email, const QString &password, con
|
|||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool AccountHelper::SignedIn()
|
||||||
|
{
|
||||||
|
return QSettings().value(LOGIN_TOKEN_VALUE).isValid();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString AccountHelper::GetLoginToken()
|
||||||
|
{
|
||||||
|
return QSettings().value(LOGIN_TOKEN_VALUE).toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AccountHelper::RemoveLoginToken()
|
||||||
|
{
|
||||||
|
QSettings().remove(LOGIN_TOKEN_VALUE);
|
||||||
|
}
|
||||||
|
@ -22,8 +22,6 @@ typedef std::function<void (LoginResult)> vLoginCallback;
|
|||||||
class AccountHelper
|
class AccountHelper
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
AccountHelper();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempt to login user
|
* Attempt to login user
|
||||||
*
|
*
|
||||||
@ -31,5 +29,20 @@ public:
|
|||||||
* @param password User password
|
* @param password User password
|
||||||
*/
|
*/
|
||||||
static void LoginUser(const QString &email, const QString &password, const vLoginCallback cb);
|
static void LoginUser(const QString &email, const QString &password, const vLoginCallback cb);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check out whether a user is currently signed in or not
|
||||||
|
*/
|
||||||
|
static bool SignedIn();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve user login token
|
||||||
|
*/
|
||||||
|
static QString GetLoginToken();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destroy the login token of a user
|
||||||
|
*/
|
||||||
|
static void RemoveLoginToken();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include "accounthelper.h"
|
#include "accounthelper.h"
|
||||||
#include "apirequest.h"
|
#include "apirequest.h"
|
||||||
#include "loginwindow.h"
|
#include "loginwindow.h"
|
||||||
|
#include "refreshservice.h"
|
||||||
#include "ui_loginwindow.h"
|
#include "ui_loginwindow.h"
|
||||||
|
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
@ -68,6 +69,9 @@ void LoginWindow::onResponse(LoginResult res)
|
|||||||
|
|
||||||
case SUCCESS:
|
case SUCCESS:
|
||||||
QMessageBox::information(this, "ok", "success");
|
QMessageBox::information(this, "ok", "success");
|
||||||
|
RefreshService::startService();
|
||||||
|
close();
|
||||||
|
deleteLater();
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case BAD_PASSWORD:
|
case BAD_PASSWORD:
|
||||||
|
14
main.cpp
14
main.cpp
@ -1,19 +1,23 @@
|
|||||||
#include "loginwindow.h"
|
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
|
||||||
|
#include "loginwindow.h"
|
||||||
|
#include "refreshservice.h"
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
QApplication a(argc, argv);
|
QApplication a(argc, argv);
|
||||||
|
|
||||||
// Initialize configuration
|
// Initialize configuration
|
||||||
QCoreApplication::setOrganizationName("Comuniquons");
|
QCoreApplication::setOrganizationName("Communiquons");
|
||||||
QCoreApplication::setOrganizationDomain("communiquons.org");
|
QCoreApplication::setOrganizationDomain("communiquons.org");
|
||||||
QCoreApplication::setApplicationName("ComunicWatcher");
|
QCoreApplication::setApplicationName("ComunicWatcher");
|
||||||
|
|
||||||
LoginWindow w;
|
if(!AccountHelper::SignedIn()) {
|
||||||
w.show();
|
(new LoginWindow())->show();
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
RefreshService::startService();
|
||||||
|
|
||||||
return a.exec();
|
return a.exec();
|
||||||
}
|
}
|
||||||
|
29
refreshservice.cpp
Normal file
29
refreshservice.cpp
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#include "refreshservice.h"
|
||||||
|
|
||||||
|
RefreshService *RefreshService::svc = nullptr;
|
||||||
|
|
||||||
|
|
||||||
|
void RefreshService::startService()
|
||||||
|
{
|
||||||
|
if(svc != nullptr)
|
||||||
|
return;
|
||||||
|
|
||||||
|
svc = new RefreshService();
|
||||||
|
}
|
||||||
|
|
||||||
|
void RefreshService::stopService()
|
||||||
|
{
|
||||||
|
if(svc != nullptr)
|
||||||
|
svc->deleteLater();
|
||||||
|
svc = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
RefreshService::RefreshService()
|
||||||
|
{
|
||||||
|
qDebug("Start refresh service");
|
||||||
|
}
|
||||||
|
|
||||||
|
RefreshService::~RefreshService()
|
||||||
|
{
|
||||||
|
qDebug("Stop refresh service");
|
||||||
|
}
|
25
refreshservice.h
Normal file
25
refreshservice.h
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
/**
|
||||||
|
* Refresh service
|
||||||
|
*
|
||||||
|
* @author Pierre Hubert
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
class RefreshService : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
static void startService();
|
||||||
|
static void stopService();
|
||||||
|
|
||||||
|
private:
|
||||||
|
RefreshService();
|
||||||
|
~RefreshService();
|
||||||
|
|
||||||
|
// Class members
|
||||||
|
static RefreshService *svc;
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user