This repository has been archived by the owner. It is now read-only.
Permalink
...
Comparing changes
Open a pull request
- 2 commits
- 20 files changed
- 0 commit comments
- 1 contributor
Unified
Split
Showing
with
637 additions
and 22 deletions.
- +2 −2 CMakeLists.txt
- +9 −3 src/gui/gui.pro
- +22 −0 src/gui/res/LoginWindow.h
- +149 −0 src/gui/res/LoginWindowBase.ui
- +6 −0 src/gui/src/AppConfig.cpp
- +10 −1 src/gui/src/AppConfig.h
- +98 −0 src/gui/src/LoginAuth.cpp
- +35 −0 src/gui/src/LoginAuth.h
- +15 −0 src/gui/src/LoginResult.h
- +158 −0 src/gui/src/LoginWindow.cpp
- +48 −0 src/gui/src/LoginWindow.h
- +28 −2 src/gui/src/MainWindow.cpp
- +3 −1 src/gui/src/MainWindow.h
- +17 −7 src/gui/src/main.cpp
- +1 −1 src/lib/server/Server.cpp
- +7 −4 src/lib/synergy/ArgParser.cpp
- +1 −1 src/lib/synergy/Screen.cpp
- +23 −0 src/lib/synergy/ToolApp.cpp
- +4 −0 src/lib/synergy/ToolApp.h
- +1 −0 src/lib/synergy/ToolArgs.h
View
4
CMakeLists.txt
| @@ -16,8 +16,8 @@ | ||
| # Version number for Synergy | ||
| set(VERSION_MAJOR 1) | ||
| -set(VERSION_MINOR 6) | ||
| -set(VERSION_REV 3) | ||
| +set(VERSION_MINOR 7) | ||
| +set(VERSION_REV 0) | ||
| set(VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_REV}") | ||
| cmake_minimum_required(VERSION 2.6) | ||
View
12
src/gui/gui.pro
| @@ -14,7 +14,8 @@ FORMS += res/MainWindowBase.ui \ | ||
| res/HotkeyDialogBase.ui \ | ||
| res/SettingsDialogBase.ui \ | ||
| res/SetupWizardBase.ui \ | ||
| - res/AddClientDialogBase.ui | ||
| + res/AddClientDialogBase.ui \ | ||
| + res/LoginWindowBase.ui | ||
| SOURCES += src/main.cpp \ | ||
| src/MainWindow.cpp \ | ||
| src/AboutDialog.cpp \ | ||
| @@ -50,7 +51,9 @@ SOURCES += src/main.cpp \ | ||
| src/ZeroconfService.cpp \ | ||
| src/DataDownloader.cpp \ | ||
| src/AddClientDialog.cpp \ | ||
| - src/CommandProcess.cpp | ||
| + src/CommandProcess.cpp \ | ||
| + src/LoginWindow.cpp \ | ||
| + src/LoginAuth.cpp | ||
| HEADERS += src/MainWindow.h \ | ||
| src/AboutDialog.h \ | ||
| src/ServerConfig.h \ | ||
| @@ -86,7 +89,10 @@ HEADERS += src/MainWindow.h \ | ||
| src/ZeroconfService.h \ | ||
| src/DataDownloader.h \ | ||
| src/AddClientDialog.h \ | ||
| - src/CommandProcess.h | ||
| + src/CommandProcess.h \ | ||
| + src/LoginWindow.h \ | ||
| + src/LoginAuth.h \ | ||
| + src/LoginResult.h | ||
| RESOURCES += res/Synergy.qrc | ||
| RC_FILE = res/win/Synergy.rc | ||
| macx { | ||
View
22
src/gui/res/LoginWindow.h
| @@ -0,0 +1,22 @@ | ||
| +#ifndef LOGINWINDOW_H | ||
| +#define LOGINWINDOW_H | ||
| + | ||
| +#include <QMainWindow> | ||
| + | ||
| +#include "ui_LoginWindowBase.h" | ||
| + | ||
| +class LoginWindow : public QMainWindow, public Ui::LoginWindowBase | ||
| +{ | ||
| + Q_OBJECT | ||
| +public: | ||
| + LoginWindow(QWidget *parent = 0); | ||
| + ~LoginWindow(); | ||
| + | ||
| +protected: | ||
| + void changeEvent(QEvent *e); | ||
| + | ||
| +private: | ||
| + Ui::LoginWindow *ui; | ||
| +}; | ||
| + | ||
| +#endif // LOGINWINDOW_H |
View
149
src/gui/res/LoginWindowBase.ui
| @@ -0,0 +1,149 @@ | ||
| +<?xml version="1.0" encoding="UTF-8"?> | ||
| +<ui version="4.0"> | ||
| + <class>LoginWindow</class> | ||
| + <widget class="QMainWindow" name="LoginWindow"> | ||
| + <property name="geometry"> | ||
| + <rect> | ||
| + <x>0</x> | ||
| + <y>0</y> | ||
| + <width>400</width> | ||
| + <height>200</height> | ||
| + </rect> | ||
| + </property> | ||
| + <property name="windowTitle"> | ||
| + <string>Synergy</string> | ||
| + </property> | ||
| + <widget class="QWidget" name="centralwidget"> | ||
| + <layout class="QVBoxLayout" name="verticalLayout"> | ||
| + <item> | ||
| + <layout class="QVBoxLayout" name="verticalLayout_2"> | ||
| + <property name="leftMargin"> | ||
| + <number>10</number> | ||
| + </property> | ||
| + <item> | ||
| + <widget class="QLabel" name="label"> | ||
| + <property name="text"> | ||
| + <string/> | ||
| + </property> | ||
| + <property name="pixmap"> | ||
| + <pixmap resource="Synergy.qrc">:/res/image/about.png</pixmap> | ||
| + </property> | ||
| + </widget> | ||
| + </item> | ||
| + </layout> | ||
| + </item> | ||
| + <item> | ||
| + <layout class="QFormLayout" name="formLayout"> | ||
| + <property name="leftMargin"> | ||
| + <number>20</number> | ||
| + </property> | ||
| + <property name="rightMargin"> | ||
| + <number>20</number> | ||
| + </property> | ||
| + <item row="0" column="0"> | ||
| + <widget class="QLabel" name="m_pLabelEmail"> | ||
| + <property name="text"> | ||
| + <string>Email:</string> | ||
| + </property> | ||
| + </widget> | ||
| + </item> | ||
| + <item row="0" column="1"> | ||
| + <widget class="QLineEdit" name="m_pLineEditEmail"> | ||
| + <property name="sizePolicy"> | ||
| + <sizepolicy hsizetype="Expanding" vsizetype="Fixed"> | ||
| + <horstretch>0</horstretch> | ||
| + <verstretch>0</verstretch> | ||
| + </sizepolicy> | ||
| + </property> | ||
| + </widget> | ||
| + </item> | ||
| + <item row="1" column="0"> | ||
| + <widget class="QLabel" name="m_pLabelPassword"> | ||
| + <property name="text"> | ||
| + <string>Password:</string> | ||
| + </property> | ||
| + </widget> | ||
| + </item> | ||
| + <item row="1" column="1"> | ||
| + <widget class="QLineEdit" name="m_pLineEditPassword"> | ||
| + <property name="inputMethodHints"> | ||
| + <set>Qt::ImhHiddenText</set> | ||
| + </property> | ||
| + <property name="echoMode"> | ||
| + <enum>QLineEdit::Password</enum> | ||
| + </property> | ||
| + </widget> | ||
| + </item> | ||
| + </layout> | ||
| + </item> | ||
| + <item> | ||
| + <layout class="QHBoxLayout" name="horizontalLayout"> | ||
| + <property name="leftMargin"> | ||
| + <number>20</number> | ||
| + </property> | ||
| + <property name="rightMargin"> | ||
| + <number>20</number> | ||
| + </property> | ||
| + <item> | ||
| + <widget class="QLabel" name="m_pLabelRegister"> | ||
| + <property name="text"> | ||
| + <string><a href="http://synergy-project.org/">Register</a></string> | ||
| + </property> | ||
| + <property name="openExternalLinks"> | ||
| + <bool>true</bool> | ||
| + </property> | ||
| + </widget> | ||
| + </item> | ||
| + <item> | ||
| + <widget class="QPushButton" name="m_pPushButtonLogin"> | ||
| + <property name="sizePolicy"> | ||
| + <sizepolicy hsizetype="Maximum" vsizetype="Fixed"> | ||
| + <horstretch>0</horstretch> | ||
| + <verstretch>0</verstretch> | ||
| + </sizepolicy> | ||
| + </property> | ||
| + <property name="text"> | ||
| + <string>Login</string> | ||
| + </property> | ||
| + <property name="shortcut"> | ||
| + <string>Return</string> | ||
| + </property> | ||
| + </widget> | ||
| + </item> | ||
| + <item> | ||
| + <widget class="QPushButton" name="m_pPushButtonCancel"> | ||
| + <property name="sizePolicy"> | ||
| + <sizepolicy hsizetype="Maximum" vsizetype="Fixed"> | ||
| + <horstretch>0</horstretch> | ||
| + <verstretch>0</verstretch> | ||
| + </sizepolicy> | ||
| + </property> | ||
| + <property name="text"> | ||
| + <string>Cancel</string> | ||
| + </property> | ||
| + <property name="shortcut"> | ||
| + <string>Esc</string> | ||
| + </property> | ||
| + </widget> | ||
| + </item> | ||
| + </layout> | ||
| + </item> | ||
| + </layout> | ||
| + </widget> | ||
| + <widget class="QMenuBar" name="menubar"> | ||
| + <property name="geometry"> | ||
| + <rect> | ||
| + <x>0</x> | ||
| + <y>0</y> | ||
| + <width>400</width> | ||
| + <height>21</height> | ||
| + </rect> | ||
| + </property> | ||
| + </widget> | ||
| + <widget class="QStatusBar" name="statusbar"/> | ||
| + </widget> | ||
| + <resources> | ||
| + <include location="Synergy.qrc"/> | ||
| + </resources> | ||
| + <connections/> | ||
| +</ui> |
View
6
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) | ||
View
11
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[]; | ||
View
98
src/gui/src/LoginAuth.cpp
| @@ -0,0 +1,98 @@ | ||
| +#include "LoginAuth.h" | ||
| + | ||
| +#include "LoginWindow.h" | ||
| +#include "AppConfig.h" | ||
| +#include "QUtility.h" | ||
| +#include "LoginResult.h" | ||
| + | ||
| +#include <QProcess> | ||
| +#include <QCoreApplication> | ||
| +#include <QCryptographicHash> | ||
| +#include <stdexcept> | ||
| + | ||
| +void LoginAuth::checkUserType() | ||
| +{ | ||
| + int result = doCheckUserType(); | ||
| + m_pLoginWindow->setLoginResult(result); | ||
| + emit finished(); | ||
| +} | ||
| + | ||
| +int LoginAuth::doCheckUserType() | ||
| +{ | ||
| + QString responseJson; | ||
| + | ||
| + try | ||
| + { | ||
| + responseJson = request(m_Email, m_Password); | ||
| + } | ||
| + catch (std::exception& e) | ||
| + { | ||
| + m_pLoginWindow->setError(e.what()); | ||
| + return ExceptionError; | ||
| + } | ||
| + | ||
| + QRegExp resultRegex(".*\"result\".*:.*(true|false).*"); | ||
| + if (resultRegex.exactMatch(responseJson)) { | ||
| + QString boolString = resultRegex.cap(1); | ||
| + if (boolString == "true") { | ||
| + return Home; | ||
| + } | ||
| + else if (boolString == "false") { | ||
| + return InvalidEmailPassword; | ||
| + } | ||
| + } | ||
| + else { | ||
| + QRegExp errorRegex(".*\"error\".*:.*\"(.+)\".*"); | ||
| + if (errorRegex.exactMatch(responseJson)) { | ||
| + | ||
| + // replace "\n" with real new lines. | ||
| + QString error = errorRegex.cap(1).replace("\\n", "\n"); | ||
| + m_pLoginWindow->setError(error); | ||
| + return Error; | ||
| + } | ||
| + } | ||
| + | ||
| + m_pLoginWindow->setError(responseJson); | ||
| + return ServerResponseError; | ||
| +} | ||
| + | ||
| +QString LoginAuth::request(const QString& email, const QString& password) | ||
| +{ | ||
| + QString program(QCoreApplication::applicationDirPath() + "/syntool"); | ||
| + QStringList args("--login-auth"); | ||
| + | ||
| + QProcess process; | ||
| + process.setReadChannel(QProcess::StandardOutput); | ||
| + process.start(program, args); | ||
| + bool success = process.waitForStarted(); | ||
| + | ||
| + QString out, error; | ||
| + if (success) | ||
| + { | ||
| + // hash password in case it contains interesting chars. | ||
| + QString credentials(email + ":" + hash(password) + "\n"); | ||
| + process.write(credentials.toStdString().c_str()); | ||
| + | ||
| + if (process.waitForFinished()) { | ||
| + out = process.readAllStandardOutput(); | ||
| + error = process.readAllStandardError(); | ||
| + } | ||
| + } | ||
| + | ||
| + out = out.trimmed(); | ||
| + error = error.trimmed(); | ||
| + | ||
| + if (out.isEmpty() || | ||
| + !error.isEmpty() || | ||
| + !success || | ||
| + process.exitCode() != 0) | ||
| + { | ||
| + throw std::runtime_error( | ||
| + QString("Code: %1\nError: %2") | ||
| + .arg(process.exitCode()) | ||
| + .arg(error.isEmpty() ? "Unknown" : error) | ||
| + .toStdString()); | ||
| + } | ||
| + | ||
| + return out; | ||
| +} |
Oops, something went wrong.