stored user email, token and type in settings #4168
This commit is contained in:
parent
ccc5834757
commit
319de60286
|
@ -91,7 +91,8 @@ HEADERS += src/MainWindow.h \
|
||||||
src/AddClientDialog.h \
|
src/AddClientDialog.h \
|
||||||
src/CommandProcess.h \
|
src/CommandProcess.h \
|
||||||
src/LoginWindow.h \
|
src/LoginWindow.h \
|
||||||
src/LoginAuth.h
|
src/LoginAuth.h \
|
||||||
|
src/LoginResult.h
|
||||||
RESOURCES += res/Synergy.qrc
|
RESOURCES += res/Synergy.qrc
|
||||||
RC_FILE = res/win/Synergy.rc
|
RC_FILE = res/win/Synergy.rc
|
||||||
macx {
|
macx {
|
||||||
|
|
|
@ -127,6 +127,9 @@ void AppConfig::loadSettings()
|
||||||
m_AutoConfig = settings().value("autoConfig", true).toBool();
|
m_AutoConfig = settings().value("autoConfig", true).toBool();
|
||||||
m_ElevateMode = settings().value("elevateMode", false).toBool();
|
m_ElevateMode = settings().value("elevateMode", false).toBool();
|
||||||
m_AutoConfigPrompted = settings().value("autoConfigPrompted", false).toBool();
|
m_AutoConfigPrompted = settings().value("autoConfigPrompted", false).toBool();
|
||||||
|
m_UserEmail = settings().value("userEmail", "").toString();
|
||||||
|
m_UserToken = settings().value("userToken", "").toString();
|
||||||
|
m_UserType = settings().value("userType", 0).toInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppConfig::saveSettings()
|
void AppConfig::saveSettings()
|
||||||
|
@ -145,6 +148,9 @@ void AppConfig::saveSettings()
|
||||||
settings().setValue("autoConfig", m_AutoConfig);
|
settings().setValue("autoConfig", m_AutoConfig);
|
||||||
settings().setValue("elevateMode", m_ElevateMode);
|
settings().setValue("elevateMode", m_ElevateMode);
|
||||||
settings().setValue("autoConfigPrompted", m_AutoConfigPrompted);
|
settings().setValue("autoConfigPrompted", m_AutoConfigPrompted);
|
||||||
|
settings().setValue("userEmail", m_UserEmail);
|
||||||
|
settings().setValue("userToken", m_UserToken);
|
||||||
|
settings().setValue("userType", m_UserType);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppConfig::setCryptoPass(const QString &s)
|
void AppConfig::setCryptoPass(const QString &s)
|
||||||
|
|
|
@ -47,6 +47,7 @@ class AppConfig
|
||||||
friend class SettingsDialog;
|
friend class SettingsDialog;
|
||||||
friend class MainWindow;
|
friend class MainWindow;
|
||||||
friend class SetupWizard;
|
friend class SetupWizard;
|
||||||
|
friend class LoginWindow;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AppConfig(QSettings* settings);
|
AppConfig(QSettings* settings);
|
||||||
|
@ -72,6 +73,9 @@ class AppConfig
|
||||||
void setAutoConfig(bool autoConfig);
|
void setAutoConfig(bool autoConfig);
|
||||||
bool autoConfigPrompted() { return m_AutoConfigPrompted; }
|
bool autoConfigPrompted() { return m_AutoConfigPrompted; }
|
||||||
void setAutoConfigPrompted(bool prompted);
|
void setAutoConfigPrompted(bool prompted);
|
||||||
|
const QString& userEmail() const { return m_UserEmail; }
|
||||||
|
const QString& userToken() const { return m_UserToken; }
|
||||||
|
const int userType() const { return m_UserType; }
|
||||||
|
|
||||||
QString synergysName() const { return m_SynergysName; }
|
QString synergysName() const { return m_SynergysName; }
|
||||||
QString synergycName() const { return m_SynergycName; }
|
QString synergycName() const { return m_SynergycName; }
|
||||||
|
@ -95,7 +99,9 @@ class AppConfig
|
||||||
void setLanguage(const QString language) { m_Language = language; }
|
void setLanguage(const QString language) { m_Language = language; }
|
||||||
void setStartedBefore(bool b) { m_StartedBefore = b; }
|
void setStartedBefore(bool b) { m_StartedBefore = b; }
|
||||||
void setElevateMode(bool b) { m_ElevateMode = b; }
|
void setElevateMode(bool b) { m_ElevateMode = b; }
|
||||||
|
void setUserEmail(const QString& e) { m_UserEmail = e; }
|
||||||
|
void setUserToken(const QString& t) { m_UserToken = t; }
|
||||||
|
void setUserType(int t) { m_UserType = t; }
|
||||||
void loadSettings();
|
void loadSettings();
|
||||||
void saveSettings();
|
void saveSettings();
|
||||||
|
|
||||||
|
@ -118,6 +124,9 @@ class AppConfig
|
||||||
bool m_AutoConfig;
|
bool m_AutoConfig;
|
||||||
bool m_ElevateMode;
|
bool m_ElevateMode;
|
||||||
bool m_AutoConfigPrompted;
|
bool m_AutoConfigPrompted;
|
||||||
|
QString m_UserEmail;
|
||||||
|
QString m_UserToken;
|
||||||
|
int m_UserType;
|
||||||
|
|
||||||
static const char m_SynergysName[];
|
static const char m_SynergysName[];
|
||||||
static const char m_SynergycName[];
|
static const char m_SynergycName[];
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
#include "LoginAuth.h"
|
#include "LoginAuth.h"
|
||||||
|
|
||||||
#include "LoginWindow.h"
|
#include "LoginWindow.h"
|
||||||
|
#include "AppConfig.h"
|
||||||
|
#include "QUtility.h"
|
||||||
|
#include "LoginResult.h"
|
||||||
|
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
|
@ -93,10 +96,3 @@ QString LoginAuth::request(const QString& email, const QString& password)
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString LoginAuth::hash(const QString& string)
|
|
||||||
{
|
|
||||||
QByteArray data = string.toUtf8();
|
|
||||||
QByteArray hash = QCryptographicHash::hash(data, QCryptographicHash::Md5);
|
|
||||||
return hash.toHex();
|
|
||||||
}
|
|
||||||
|
|
|
@ -5,18 +5,7 @@
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
class LoginWindow;
|
class LoginWindow;
|
||||||
|
class AppConfig;
|
||||||
enum qUserType {
|
|
||||||
Student,
|
|
||||||
Home,
|
|
||||||
Professional,
|
|
||||||
Error,
|
|
||||||
ExceptionError,
|
|
||||||
InvalidEmailPassword,
|
|
||||||
ServerResponseError,
|
|
||||||
Unknown
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
class LoginAuth : public QObject
|
class LoginAuth : public QObject
|
||||||
{
|
{
|
||||||
|
@ -36,7 +25,6 @@ signals:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString request(const QString& email, const QString& password);
|
QString request(const QString& email, const QString& password);
|
||||||
QString hash(const QString& string);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_Email;
|
QString m_Email;
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
#ifndef LOGINRESULT_H
|
||||||
|
#define LOGINRESULT_H
|
||||||
|
|
||||||
|
enum qLoginResult {
|
||||||
|
Unknown,
|
||||||
|
Student,
|
||||||
|
Home,
|
||||||
|
Professional,
|
||||||
|
Error,
|
||||||
|
ExceptionError,
|
||||||
|
InvalidEmailPassword,
|
||||||
|
ServerResponseError
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // LOGINRESULT_H
|
|
@ -4,6 +4,8 @@
|
||||||
#include "MainWindow.h"
|
#include "MainWindow.h"
|
||||||
#include "SetupWizard.h"
|
#include "SetupWizard.h"
|
||||||
#include "LoginAuth.h"
|
#include "LoginAuth.h"
|
||||||
|
#include "LoginResult.h"
|
||||||
|
#include "QUtility.h"
|
||||||
|
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QCloseEvent>
|
#include <QCloseEvent>
|
||||||
|
@ -19,11 +21,12 @@ LoginWindow::LoginWindow(
|
||||||
m_pSetupWizard(setupWizard),
|
m_pSetupWizard(setupWizard),
|
||||||
m_WizardShouldRun(wizardShouldRun),
|
m_WizardShouldRun(wizardShouldRun),
|
||||||
m_pLoginAuth(NULL),
|
m_pLoginAuth(NULL),
|
||||||
m_LoginResult(Unknown)
|
m_LoginResult(Unknown),
|
||||||
|
m_AppConfig(m_pMainWindow->appConfig())
|
||||||
{
|
{
|
||||||
setupUi(this);
|
setupUi(this);
|
||||||
|
|
||||||
|
m_pLineEditEmail->setText(m_AppConfig.userEmail());
|
||||||
}
|
}
|
||||||
|
|
||||||
LoginWindow::~LoginWindow()
|
LoginWindow::~LoginWindow()
|
||||||
|
@ -69,6 +72,17 @@ void LoginWindow::showNext()
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
m_pMainWindow->setLoginResult(m_LoginResult);
|
m_pMainWindow->setLoginResult(m_LoginResult);
|
||||||
|
if (!m_pLineEditEmail->text().isEmpty()) {
|
||||||
|
m_AppConfig.setUserEmail(m_pLineEditEmail->text());
|
||||||
|
|
||||||
|
if (m_LoginResult != Unknown) {
|
||||||
|
QString mac = getFirstMacAddress();
|
||||||
|
QString hashSrc = m_pLineEditEmail->text() + mac;
|
||||||
|
QString hashResult = hash(hashSrc);
|
||||||
|
m_AppConfig.setUserToken(hashResult);
|
||||||
|
m_AppConfig.setUserType(m_LoginResult);
|
||||||
|
}
|
||||||
|
}
|
||||||
m_pMainWindow->show();
|
m_pMainWindow->show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
class MainWindow;
|
class MainWindow;
|
||||||
class SetupWizard;
|
class SetupWizard;
|
||||||
class LoginAuth;
|
class LoginAuth;
|
||||||
|
class AppConfig;
|
||||||
|
|
||||||
class LoginWindow : public QMainWindow, public Ui::LoginWindow
|
class LoginWindow : public QMainWindow, public Ui::LoginWindow
|
||||||
{
|
{
|
||||||
|
@ -40,6 +41,7 @@ private:
|
||||||
LoginAuth* m_pLoginAuth;
|
LoginAuth* m_pLoginAuth;
|
||||||
int m_LoginResult;
|
int m_LoginResult;
|
||||||
QString m_Error;
|
QString m_Error;
|
||||||
|
AppConfig& m_AppConfig;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
#include "DataDownloader.h"
|
#include "DataDownloader.h"
|
||||||
#include "CommandProcess.h"
|
#include "CommandProcess.h"
|
||||||
#include "LoginAuth.h"
|
#include "LoginAuth.h"
|
||||||
|
#include "LoginResult.h"
|
||||||
|
|
||||||
#include <QtCore>
|
#include <QtCore>
|
||||||
#include <QtGui>
|
#include <QtGui>
|
||||||
|
|
|
@ -113,6 +113,7 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase
|
||||||
void serverDetected(const QString name);
|
void serverDetected(const QString name);
|
||||||
int checkWinArch();
|
int checkWinArch();
|
||||||
void setLoginResult(int result);
|
void setLoginResult(int result);
|
||||||
|
AppConfig& appConfig() { return m_AppConfig; }
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void appendLogRaw(const QString& text);
|
void appendLogRaw(const QString& text);
|
||||||
|
@ -140,7 +141,6 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QSettings& settings() { return m_Settings; }
|
QSettings& settings() { return m_Settings; }
|
||||||
AppConfig& appConfig() { return m_AppConfig; }
|
|
||||||
QProcess*& synergyProcess() { return m_pSynergy; }
|
QProcess*& synergyProcess() { return m_pSynergy; }
|
||||||
void setSynergyProcess(QProcess* p) { m_pSynergy = p; }
|
void setSynergyProcess(QProcess* p) { m_pSynergy = p; }
|
||||||
void initConnections();
|
void initConnections();
|
||||||
|
|
|
@ -24,6 +24,8 @@
|
||||||
#include "AppConfig.h"
|
#include "AppConfig.h"
|
||||||
#include "SetupWizard.h"
|
#include "SetupWizard.h"
|
||||||
#include "LoginWindow.h"
|
#include "LoginWindow.h"
|
||||||
|
#include "QUtility.h"
|
||||||
|
#include "LoginResult.h"
|
||||||
|
|
||||||
#include <QtCore>
|
#include <QtCore>
|
||||||
#include <QtGui>
|
#include <QtGui>
|
||||||
|
@ -93,13 +95,22 @@ int main(int argc, char* argv[])
|
||||||
|
|
||||||
MainWindow mainWindow(settings, appConfig);
|
MainWindow mainWindow(settings, appConfig);
|
||||||
SetupWizard setupWizard(mainWindow, true);
|
SetupWizard setupWizard(mainWindow, true);
|
||||||
|
|
||||||
LoginWindow loginWindow(
|
LoginWindow loginWindow(
|
||||||
&mainWindow,
|
&mainWindow,
|
||||||
&setupWizard,
|
&setupWizard,
|
||||||
appConfig.wizardShouldRun());
|
appConfig.wizardShouldRun());
|
||||||
|
|
||||||
|
QString email = appConfig.userEmail();
|
||||||
|
QString mac = getFirstMacAddress();
|
||||||
|
QString hashSrc = email + mac;
|
||||||
|
QString hashResult = hash(hashSrc);
|
||||||
|
if (hashResult == appConfig.userToken()) {
|
||||||
|
mainWindow.setLoginResult(appConfig.userType());
|
||||||
|
mainWindow.show();
|
||||||
|
}
|
||||||
|
else {
|
||||||
loginWindow.show();
|
loginWindow.show();
|
||||||
|
}
|
||||||
|
|
||||||
return app.exec();
|
return app.exec();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue