Skip to content

Commit

Permalink
Merge pull request #15 from beckf/devel
Browse files Browse the repository at this point in the history
Devel
  • Loading branch information
beckf authored Jun 2, 2019
2 parents 597fed7 + 6a39352 commit 8faa626
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 134 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.4.0
1.6.0
Binary file modified images/authorize.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
93 changes: 74 additions & 19 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtWebEngineCore import QWebEngineUrlRequestInterceptor
from PyQt5.QtWebEngineWidgets import QWebEnginePage, QWebEngineView
from mainwindow import Ui_MainWindow
import veracross_api
import lightspeed_api
import sys, getopt
import sys
import os
import datetime
import pytz
import config
import csv
from decimal import Decimal, ROUND_HALF_UP
import images
from urllib.parse import quote
import traceback
import requests


class Worker(QRunnable):
Expand Down Expand Up @@ -51,6 +51,39 @@ class WorkerSignals(QObject):
progress = pyqtSignal(int)


class AuthorizeLS(QMainWindow):
def __init__(self, auth_url):
QMainWindow.__init__(self)
self.auth_url = auth_url
self.page = QWebEnginePage()
self.view = QWebEngineView()
self.view.setPage(self.page)
self.interceptor = AuthCodeInterceptor()
self.page.profile().setRequestInterceptor(self.interceptor)
self.view.setUrl(QUrl(self.auth_url))
self.view.show()

def check_code(self):
return self.interceptor.code


class AuthCodeInterceptor(QWebEngineUrlRequestInterceptor):
code_returned = pyqtSignal()

def __init__(self):
super().__init__()

self.code = ""

def interceptRequest(self, info):
url = info.firstPartyUrl().toString()

if "localhost" in url:
code = url.split("code=")[1]
self.code = code
self.code_returned.emit()


class Main(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
Expand All @@ -61,6 +94,9 @@ def __init__(self):
self.debug_append_log("Multithreading enabled with maximum %d threads." % self.threadpool.maxThreadCount(),
"info")

# Output some debug stuff for cmdline
print("CWD: " + (os.path.abspath(os.__file__)) )

# Gather Config
if config.check_enc() is True:
self.config_passwd, ok = QInputDialog.getText(None,
Expand All @@ -75,13 +111,12 @@ def __init__(self):
QLineEdit.Password)

if ok and self.config_passwd:
print("password=%s" % self.config_passwd)
try:
self.c = config.load_settings("config", self.config_passwd)
except ValueError:
QMessageBox.question(self, 'Incorrect Encryption Password',
"The password provided will not decrypt the settings.",
QMessageBox.Ok)
try:
self.c = config.load_settings("config", self.config_passwd)
except ValueError:
QMessageBox.question(self, 'Incorrect Encryption Password',
"The password provided will not decrypt the settings.",
QMessageBox.Ok)

self.vc = veracross_api.Veracross(self.c)
self.ls = lightspeed_api.Lightspeed(self.c)
Expand Down Expand Up @@ -146,9 +181,6 @@ def __init__(self):
self.ui.txt_VCAPIURL.setText(self.c["vcurl"])
if "client_id" in self.c.keys():
self.ui.txt_LSDevelID.setText(self.c["client_id"])
self.ui.lbl_AuthorizeApp.setText("<a href=\"https://cloud.lightspeedapp.com/oauth/authorize.php"
"?response_type=code&client_id={}&scope=employee:all\">"
"Authorize Link</a>".format(self.c["client_id"]))
if "client_secret" in self.c.keys():
self.ui.txt_DevelSecret.setText(self.c["client_secret"])
if "refresh_token" in self.c.keys():
Expand Down Expand Up @@ -722,9 +754,28 @@ def authorize_app(self):
Authorize App
:return:
"""
if len(self.ui.txt_CodeReturned.text()) > 0:
token = self.ls.get_authorization_token(self.ui.txt_CodeReturned.text())
self.ui.txt_AuthorizeReturnedRefreshToken.setText(str(token))

if len(self.c["client_id"]) > 0:
self.auth_url = "https://cloud.lightspeedapp.com/oauth/authorize.php?" \
"response_type=code&client_id={}&scope=employee:all".format(self.c["client_id"])
self.authorize_window = AuthorizeLS(self.auth_url)
self.authorize_window.interceptor.code_returned.connect(self.authorization_complete)

@pyqtSlot()
def authorization_complete(self):
code = self.authorize_window.interceptor.code
self.authorize_window.view.hide()
self.debug_append_log('Authorization Code Returned: ' + code, "info")

if len(code) > 0:
token = self.ls.get_authorization_token(code)
self.debug_append_log('Refresh Token Returned: ' + token, "info")
self.ui.txt_RefreshToken.setText(token)
QMessageBox.question(self, 'Application Authorized with Lightspeed',
"Application is now authorized with your Lightspeed account. "
"Please restart application.",
QMessageBox.Ok)
self.save_settings_button()

def debug_append_log(self, text, level):
"""
Expand Down Expand Up @@ -752,9 +803,13 @@ def select_export_directory(self):
def save_log_to_file(self):
log_dir = QFileDialog.getExistingDirectory(self, 'Select Directory to Save Log')
filename = log_dir + str("/LSVCConnector.log")
filepath = open(filename, 'w')
with filepath:
filepath.write(self.ui.txtb_SyncLog.toPlainText())
try:
if os.path.isdir(log_dir):
filepath = open(filename, 'w')
with filepath:
filepath.write(self.ui.txtb_SyncLog.toPlainText())
except:
self.debug_append_log("Unable to save log file.", "info")

def save_settings_button(self):
"""
Expand Down
34 changes: 6 additions & 28 deletions mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

# Form implementation generated from reading ui file 'qt-lightspeed-pos-vc-connector/mainwindow.ui'
#
# Created by: PyQt5 UI code generator 5.11.3
# Created by: PyQt5 UI code generator 5.12.2
#
# WARNING! All changes made in this file will be lost!

from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
Expand Down Expand Up @@ -356,35 +357,14 @@ def setupUi(self, MainWindow):
self.tabs.addTab(self.tab, "")
self.tab_Authorize = QtWidgets.QWidget()
self.tab_Authorize.setObjectName("tab_Authorize")
self.lbl_AuthorizeApp = QtWidgets.QLabel(self.tab_Authorize)
self.lbl_AuthorizeApp.setGeometry(QtCore.QRect(260, 20, 91, 20))
self.lbl_AuthorizeApp.setStyleSheet("")
self.lbl_AuthorizeApp.setTextFormat(QtCore.Qt.RichText)
self.lbl_AuthorizeApp.setOpenExternalLinks(True)
self.lbl_AuthorizeApp.setTextInteractionFlags(QtCore.Qt.TextBrowserInteraction)
self.lbl_AuthorizeApp.setObjectName("lbl_AuthorizeApp")
self.txt_CodeReturned = QtWidgets.QLineEdit(self.tab_Authorize)
self.txt_CodeReturned.setGeometry(QtCore.QRect(160, 100, 301, 21))
self.txt_CodeReturned.setObjectName("txt_CodeReturned")
self.lbl_AuthorizeCodeReturned = QtWidgets.QLabel(self.tab_Authorize)
self.lbl_AuthorizeCodeReturned.setGeometry(QtCore.QRect(200, 40, 211, 61))
self.lbl_AuthorizeCodeReturned.setGeometry(QtCore.QRect(100, 60, 421, 191))
self.lbl_AuthorizeCodeReturned.setTextFormat(QtCore.Qt.RichText)
self.lbl_AuthorizeCodeReturned.setWordWrap(True)
self.lbl_AuthorizeCodeReturned.setObjectName("lbl_AuthorizeCodeReturned")
self.btn_Authorize = QtWidgets.QPushButton(self.tab_Authorize)
self.btn_Authorize.setGeometry(QtCore.QRect(250, 350, 121, 24))
self.btn_Authorize.setObjectName("btn_Authorize")
self.txt_AuthorizeReturnedRefreshToken = QtWidgets.QLineEdit(self.tab_Authorize)
self.txt_AuthorizeReturnedRefreshToken.setGeometry(QtCore.QRect(160, 170, 301, 21))
self.txt_AuthorizeReturnedRefreshToken.setObjectName("txt_AuthorizeReturnedRefreshToken")
self.label_15 = QtWidgets.QLabel(self.tab_Authorize)
self.label_15.setGeometry(QtCore.QRect(160, 150, 301, 20))
self.label_15.setObjectName("label_15")
self.label_16 = QtWidgets.QLabel(self.tab_Authorize)
self.label_16.setGeometry(QtCore.QRect(160, 200, 301, 141))
self.label_16.setTextFormat(QtCore.Qt.RichText)
self.label_16.setWordWrap(True)
self.label_16.setObjectName("label_16")
self.tabs.addTab(self.tab_Authorize, "")
self.tab_License = QtWidgets.QWidget()
self.tab_License.setObjectName("tab_License")
Expand Down Expand Up @@ -441,7 +421,7 @@ def setupUi(self, MainWindow):
self.menuBar.addAction(self.menuFile.menuAction())

self.retranslateUi(MainWindow)
self.tabs.setCurrentIndex(6)
self.tabs.setCurrentIndex(5)
QtCore.QMetaObject.connectSlotsByName(MainWindow)

def retranslateUi(self, MainWindow):
Expand Down Expand Up @@ -517,11 +497,8 @@ def retranslateUi(self, MainWindow):
self.btn_ChangeEncPassword.setText(_translate("MainWindow", "Change Password"))
self.label_17.setText(_translate("MainWindow", "Change Settings Encryption Password"))
self.tabs.setTabText(self.tabs.indexOf(self.tab), _translate("MainWindow", "Password"))
self.lbl_AuthorizeApp.setText(_translate("MainWindow", "<html><head/><body><p align=\"center\"><a href=\"https://cloud.lightspeedapp.com/oauth/authorize.php?scope=employee:all&amp;response_type=code&amp;client_id=__CLIENT_ID__\"><span style=\" text-decoration: underline; color:#0000ff;\">Authorize Link</span></a></p></body></html>"))
self.lbl_AuthorizeCodeReturned.setText(_translate("MainWindow", "<html><head/><body><p align=\"center\">Code Returned</p><p align=\"center\">Copy and Paste from URL</p></body></html>"))
self.lbl_AuthorizeCodeReturned.setText(_translate("MainWindow", "<html><head/><body><p align=\"center\"><span style=\" font-weight:600;\">To Authorize App</span></p><p align=\"center\">Enter Lightspeed Developer Client ID, Developer Secret, and Lightspeed Account Number into the Settings Tab.</p><p align=\"center\">Click Authorize</p></body></html>"))
self.btn_Authorize.setText(_translate("MainWindow", "Authorize"))
self.label_15.setText(_translate("MainWindow", "<html><head/><body><p align=\"center\">LS Refresh Token Returned</p></body></html>"))
self.label_16.setText(_translate("MainWindow", "<html><head/><body><p align=\"center\">Copy and paste the refresh token returned from Lightspeed into your Refresh Token setting on the settings tab. </p><p align=\"center\">Be sure to update the account number from Lightspeed as well.</p></body></html>"))
self.tabs.setTabText(self.tabs.indexOf(self.tab_Authorize), _translate("MainWindow", "Authorize App"))
self.tabs.setTabText(self.tabs.indexOf(self.tab_License), _translate("MainWindow", "License"))
self.lbl_Icon.setText(_translate("MainWindow", "icon"))
Expand All @@ -530,3 +507,4 @@ def retranslateUi(self, MainWindow):
self.menuFile.setTitle(_translate("MainWindow", "File"))
self.actionQuit.setText(_translate("MainWindow", "Quit"))


89 changes: 6 additions & 83 deletions qt-lightspeed-pos-vc-connector/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ max-height: 16px;
<string notr="true"/>
</property>
<property name="currentIndex">
<number>0</number>
<number>5</number>
</property>
<property name="usesScrollButtons">
<bool>false</bool>
Expand Down Expand Up @@ -736,52 +736,17 @@ max-height: 16px;
<attribute name="title">
<string>Authorize App</string>
</attribute>
<widget class="QLabel" name="lbl_AuthorizeApp">
<property name="geometry">
<rect>
<x>260</x>
<y>20</y>
<width>91</width>
<height>20</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;&lt;a href=&quot;https://cloud.lightspeedapp.com/oauth/authorize.php?scope=employee:all&amp;amp;response_type=code&amp;amp;client_id=__CLIENT_ID__&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;Authorize Link&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="textFormat">
<enum>Qt::RichText</enum>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
<property name="textInteractionFlags">
<set>Qt::TextBrowserInteraction</set>
</property>
</widget>
<widget class="QLineEdit" name="txt_CodeReturned">
<property name="geometry">
<rect>
<x>160</x>
<y>100</y>
<width>301</width>
<height>21</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="lbl_AuthorizeCodeReturned">
<property name="geometry">
<rect>
<x>200</x>
<y>40</y>
<width>211</width>
<height>61</height>
<x>100</x>
<y>60</y>
<width>421</width>
<height>191</height>
</rect>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;Code Returned&lt;/p&gt;&lt;p align=&quot;center&quot;&gt;Copy and Paste from URL&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;To Authorize App&lt;/span&gt;&lt;/p&gt;&lt;p align=&quot;center&quot;&gt;Enter Lightspeed Developer Client ID, Developer Secret, and Lightspeed Account Number into the Settings Tab.&lt;/p&gt;&lt;p align=&quot;center&quot;&gt;Click Authorize&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="textFormat">
<enum>Qt::RichText</enum>
Expand All @@ -803,48 +768,6 @@ max-height: 16px;
<string>Authorize</string>
</property>
</widget>
<widget class="QLineEdit" name="txt_AuthorizeReturnedRefreshToken">
<property name="geometry">
<rect>
<x>160</x>
<y>170</y>
<width>301</width>
<height>21</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="label_15">
<property name="geometry">
<rect>
<x>160</x>
<y>150</y>
<width>301</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;LS Refresh Token Returned&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
<widget class="QLabel" name="label_16">
<property name="geometry">
<rect>
<x>160</x>
<y>200</y>
<width>301</width>
<height>141</height>
</rect>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;Copy and paste the refresh token returned from Lightspeed into your Refresh Token setting on the settings tab. &lt;/p&gt;&lt;p align=&quot;center&quot;&gt;Be sure to update the account number from Lightspeed as well.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="textFormat">
<enum>Qt::RichText</enum>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</widget>
<widget class="QWidget" name="tab_License">
<attribute name="title">
Expand Down
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
altgraph==0.16.1
asn1crypto==0.24.0
bottle==0.12.16
certifi==2019.3.9
cffi==1.12.3
chardet==3.0.4
cryptography==2.6.1
future==0.17.1
idna==2.8
macholib==1.11
Naked==0.1.31
pefile==2019.4.18
pipdeptree==0.13.2
py-dateutil==2.2
pyAesCrypt==0.4.3
pycparser==2.19
PyInstaller==3.4
PyQt5==5.12.2
PyQt5-sip==4.19.17
PyQtWebEngine==5.12.1
pytz==2019.1
PyYAML==5.1
requests==2.22.0
shellescape==3.4.1
sip==4.19.8
six==1.12.0
urllib3==1.25.3

0 comments on commit 8faa626

Please sign in to comment.