From 319de60286c22af880d84b45cb51614c9afd6a7a Mon Sep 17 00:00:00 2001 From: XinyuHou Date: Fri, 30 Jan 2015 17:38:12 +0000 Subject: [PATCH] stored user email, token and type in settings #4168 --- src/gui/gui.pro | 3 ++- src/gui/src/AppConfig.cpp | 6 ++++++ src/gui/src/AppConfig.h | 11 ++++++++++- src/gui/src/LoginAuth.cpp | 10 +++------- src/gui/src/LoginAuth.h | 14 +------------- src/gui/src/LoginResult.h | 15 +++++++++++++++ src/gui/src/LoginWindow.cpp | 18 ++++++++++++++++-- src/gui/src/LoginWindow.h | 2 ++ src/gui/src/MainWindow.cpp | 1 + src/gui/src/MainWindow.h | 2 +- src/gui/src/main.cpp | 21 ++++++++++++++++----- 11 files changed, 73 insertions(+), 30 deletions(-) create mode 100644 src/gui/src/LoginResult.h diff --git a/src/gui/gui.pro b/src/gui/gui.pro index 2fb96912..077e79b3 100644 --- a/src/gui/gui.pro +++ b/src/gui/gui.pro @@ -91,7 +91,8 @@ HEADERS += src/MainWindow.h \ src/AddClientDialog.h \ src/CommandProcess.h \ src/LoginWindow.h \ - src/LoginAuth.h + src/LoginAuth.h \ + src/LoginResult.h RESOURCES += res/Synergy.qrc RC_FILE = res/win/Synergy.rc macx { diff --git a/src/gui/src/AppConfig.cpp b/src/gui/src/AppConfig.cpp index 2054e0a3..5e1746b0 100644 --- a/src/gui/src/AppConfig.cpp +++ b/src/gui/src/AppConfig.cpp @@ -127,6 +127,9 @@ void AppConfig::loadSettings() m_AutoConfig = settings().value("autoConfig", true).toBool(); m_ElevateMode = settings().value("elevateMode", 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() @@ -145,6 +148,9 @@ void AppConfig::saveSettings() settings().setValue("autoConfig", m_AutoConfig); settings().setValue("elevateMode", m_ElevateMode); 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) diff --git a/src/gui/src/AppConfig.h b/src/gui/src/AppConfig.h index e53bd438..6144844b 100644 --- a/src/gui/src/AppConfig.h +++ b/src/gui/src/AppConfig.h @@ -47,6 +47,7 @@ class AppConfig friend class SettingsDialog; friend class MainWindow; friend class SetupWizard; + friend class LoginWindow; public: AppConfig(QSettings* settings); @@ -72,6 +73,9 @@ class AppConfig void setAutoConfig(bool autoConfig); bool autoConfigPrompted() { return m_AutoConfigPrompted; } 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 synergycName() const { return m_SynergycName; } @@ -95,7 +99,9 @@ class AppConfig void setLanguage(const QString language) { m_Language = language; } void setStartedBefore(bool b) { m_StartedBefore = 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 saveSettings(); @@ -118,6 +124,9 @@ class AppConfig bool m_AutoConfig; bool m_ElevateMode; bool m_AutoConfigPrompted; + QString m_UserEmail; + QString m_UserToken; + int m_UserType; static const char m_SynergysName[]; static const char m_SynergycName[]; diff --git a/src/gui/src/LoginAuth.cpp b/src/gui/src/LoginAuth.cpp index 3b744e1c..6aeb83ef 100644 --- a/src/gui/src/LoginAuth.cpp +++ b/src/gui/src/LoginAuth.cpp @@ -1,6 +1,9 @@ #include "LoginAuth.h" #include "LoginWindow.h" +#include "AppConfig.h" +#include "QUtility.h" +#include "LoginResult.h" #include #include @@ -93,10 +96,3 @@ QString LoginAuth::request(const QString& email, const QString& password) return out; } - -QString LoginAuth::hash(const QString& string) -{ - QByteArray data = string.toUtf8(); - QByteArray hash = QCryptographicHash::hash(data, QCryptographicHash::Md5); - return hash.toHex(); -} diff --git a/src/gui/src/LoginAuth.h b/src/gui/src/LoginAuth.h index 15d1f378..ed0a67ca 100644 --- a/src/gui/src/LoginAuth.h +++ b/src/gui/src/LoginAuth.h @@ -5,18 +5,7 @@ #include class LoginWindow; - -enum qUserType { - Student, - Home, - Professional, - Error, - ExceptionError, - InvalidEmailPassword, - ServerResponseError, - Unknown - -}; +class AppConfig; class LoginAuth : public QObject { @@ -36,7 +25,6 @@ signals: private: QString request(const QString& email, const QString& password); - QString hash(const QString& string); private: QString m_Email; diff --git a/src/gui/src/LoginResult.h b/src/gui/src/LoginResult.h new file mode 100644 index 00000000..62cc5093 --- /dev/null +++ b/src/gui/src/LoginResult.h @@ -0,0 +1,15 @@ +#ifndef LOGINRESULT_H +#define LOGINRESULT_H + +enum qLoginResult { + Unknown, + Student, + Home, + Professional, + Error, + ExceptionError, + InvalidEmailPassword, + ServerResponseError +}; + +#endif // LOGINRESULT_H diff --git a/src/gui/src/LoginWindow.cpp b/src/gui/src/LoginWindow.cpp index d1e886e7..dcb80f61 100644 --- a/src/gui/src/LoginWindow.cpp +++ b/src/gui/src/LoginWindow.cpp @@ -4,6 +4,8 @@ #include "MainWindow.h" #include "SetupWizard.h" #include "LoginAuth.h" +#include "LoginResult.h" +#include "QUtility.h" #include #include @@ -19,11 +21,12 @@ LoginWindow::LoginWindow( m_pSetupWizard(setupWizard), m_WizardShouldRun(wizardShouldRun), m_pLoginAuth(NULL), - m_LoginResult(Unknown) + m_LoginResult(Unknown), + m_AppConfig(m_pMainWindow->appConfig()) { setupUi(this); - + m_pLineEditEmail->setText(m_AppConfig.userEmail()); } LoginWindow::~LoginWindow() @@ -69,6 +72,17 @@ void LoginWindow::showNext() } else { 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(); } } diff --git a/src/gui/src/LoginWindow.h b/src/gui/src/LoginWindow.h index 3171f447..1490b792 100644 --- a/src/gui/src/LoginWindow.h +++ b/src/gui/src/LoginWindow.h @@ -8,6 +8,7 @@ class MainWindow; class SetupWizard; class LoginAuth; +class AppConfig; class LoginWindow : public QMainWindow, public Ui::LoginWindow { @@ -40,6 +41,7 @@ private: LoginAuth* m_pLoginAuth; int m_LoginResult; QString m_Error; + AppConfig& m_AppConfig; }; diff --git a/src/gui/src/MainWindow.cpp b/src/gui/src/MainWindow.cpp index 35a7d87d..e6519fc5 100644 --- a/src/gui/src/MainWindow.cpp +++ b/src/gui/src/MainWindow.cpp @@ -29,6 +29,7 @@ #include "DataDownloader.h" #include "CommandProcess.h" #include "LoginAuth.h" +#include "LoginResult.h" #include #include diff --git a/src/gui/src/MainWindow.h b/src/gui/src/MainWindow.h index 5ac76fb7..9814c7e9 100644 --- a/src/gui/src/MainWindow.h +++ b/src/gui/src/MainWindow.h @@ -113,6 +113,7 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase void serverDetected(const QString name); int checkWinArch(); void setLoginResult(int result); + AppConfig& appConfig() { return m_AppConfig; } public slots: void appendLogRaw(const QString& text); @@ -140,7 +141,6 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase protected: QSettings& settings() { return m_Settings; } - AppConfig& appConfig() { return m_AppConfig; } QProcess*& synergyProcess() { return m_pSynergy; } void setSynergyProcess(QProcess* p) { m_pSynergy = p; } void initConnections(); diff --git a/src/gui/src/main.cpp b/src/gui/src/main.cpp index 9ad63f0f..f07c859a 100644 --- a/src/gui/src/main.cpp +++ b/src/gui/src/main.cpp @@ -24,6 +24,8 @@ #include "AppConfig.h" #include "SetupWizard.h" #include "LoginWindow.h" +#include "QUtility.h" +#include "LoginResult.h" #include #include @@ -93,13 +95,22 @@ int main(int argc, char* argv[]) MainWindow mainWindow(settings, appConfig); SetupWizard setupWizard(mainWindow, true); - LoginWindow loginWindow( - &mainWindow, - &setupWizard, - appConfig.wizardShouldRun()); + &mainWindow, + &setupWizard, + appConfig.wizardShouldRun()); - loginWindow.show(); + 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(); + } return app.exec(); }