diff options
author | Nao Pross <np@0hm.ch> | 2022-11-17 04:20:33 +0100 |
---|---|---|
committer | Nao Pross <np@0hm.ch> | 2022-11-17 04:20:33 +0100 |
commit | 98db57ed705ce165d45cc7fb23915bdbc8ca08c0 (patch) | |
tree | 826944337f930f6e873b6ba7fcaac439417ab530 | |
parent | Update README (diff) | |
download | Muddle-98db57ed705ce165d45cc7fb23915bdbc8ca08c0.tar.gz Muddle-98db57ed705ce165d45cc7fb23915bdbc8ca08c0.zip |
Create login dialog for SWITCH
-rw-r--r-- | muddle/gui.py | 68 | ||||
-rw-r--r-- | poetry.lock | 35 | ||||
-rw-r--r-- | pyproject.toml | 1 |
3 files changed, 101 insertions, 3 deletions
diff --git a/muddle/gui.py b/muddle/gui.py index 5ea34f8..d3bdebf 100644 --- a/muddle/gui.py +++ b/muddle/gui.py @@ -15,8 +15,12 @@ import enum import html import logging import tempfile +import code + +from http.cookiejar import Cookie from PyQt6 import uic + from PyQt6.QtGui import ( QFileSystemModel, QFont, @@ -25,7 +29,6 @@ from PyQt6.QtGui import ( QStandardItemModel, ) - from PyQt6.QtCore import ( QDir, QModelIndex, @@ -35,6 +38,7 @@ from PyQt6.QtCore import ( QSortFilterProxyModel, QThread, Qt, + QUrl, pyqtSignal, pyqtSlot, ) @@ -42,6 +46,7 @@ from PyQt6.QtCore import ( from PyQt6.QtWidgets import ( QApplication, QCheckBox, + QDialog, QFileDialog, QGridLayout, QHBoxLayout, @@ -60,8 +65,13 @@ from PyQt6.QtWidgets import ( QWidget, ) +from PyQt6.QtWebEngineCore import (QWebEnginePage, QWebEngineProfile) +from PyQt6.QtWebEngineWidgets import QWebEngineView +from PyQt6.QtNetwork import QNetworkCookie + from . import moodle + log = logging.getLogger("muddle.gui") class MoodleItem(QStandardItem): @@ -173,6 +183,40 @@ class MoodleFetcher(QThread): return [] +class SwitchLoginDialog(QDialog): + def __init__(self, parent, url): + super().__init__(parent) + self.setWindowTitle("SWICH AAI Login") + + self.webview = QWebEngineView(self) + self.profile = QWebEngineProfile(self.webview) + self.cookies = [] + + self.profile.cookieStore().cookieAdded.connect(self.onCookieAdded) + + self.webview.setPage(QWebEnginePage(self.profile, self.webview)) + self.webview.load(QUrl(url)) + self.webview.show() + + layout = QGridLayout() + layout.addWidget(self.webview) + self.setLayout(layout) + self.setMinimumSize(800, 600) + + @pyqtSlot(QNetworkCookie) + def onCookieAdded(self, cookie): + for c in self.cookies: + if c.hasSameIdentifier(cookie): + return + self.cookies.append(QNetworkCookie(cookie)) + + def pyCookies(self): + """ Converts the QNetworkCookies into http.cookiejar cookies that can + be used in requests """ + for c in self.cookies: + raise NotImplemented + + class MoodleTreeFilterModel(QSortFilterProxyModel): def __init__(self): super().__init__() @@ -316,7 +360,10 @@ class MuddleWindow(QMainWindow): if config.has_option("muddle", "default_download_dir"): defaultDownloadPathEdit.setText(config["muddle"]["default_download_dir"]) - + ## switch aai login + self.switchLoginBtn = self.findChild(QPushButton, "switchLoginBtn") + self.switchLoginBtn.clicked.connect(self.onSwitchLoginBtnClicked) + # log tab ## setup logging self.loghandler = QLogHandler(self) @@ -413,8 +460,25 @@ class MuddleWindow(QMainWindow): # TODO: open login dialog # TODO: test and maybe check if there is already a token # req = moodle.request_token(self.instance_url, user, password) + log.error("Token request is broken") pass + @pyqtSlot() + def onSwitchLoginBtnClicked(self): + # TODO: implement SWITCH login + # Resources: + # https://www.switch.ch/aai/demo/medium/ + # https://iam.harvard.edu/resources/saml-shibboleth-integration + # https://github.com/Bownairo/shibbolethpython + # https://stackoverflow.com/questions/16512965/logging-into-saml-shibboleth-authenticated-server-using-python/58598520#58598520 + log.error("SWITCH login is not implemented yet") + + dialog = SwitchLoginDialog(self, self.instanceUrl) + if dialog.exec(): + pass + + code.interact(local=dict(globals(), **locals())) + @pyqtSlot(str) def onSearchBarTextChanged(self, text): moodleTreeView = self.findChild(QTreeView, "moodleTree") diff --git a/poetry.lock b/poetry.lock index 54b529b..04b97dc 100644 --- a/poetry.lock +++ b/poetry.lock @@ -173,6 +173,27 @@ optional = false python-versions = ">=3.7" [[package]] +name = "pyqt6-webengine" +version = "6.4.0" +description = "Python bindings for the Qt WebEngine framework" +category = "main" +optional = false +python-versions = ">=3.7" + +[package.dependencies] +PyQt6 = ">=6.2.0" +PyQt6-sip = ">=13.4,<14" +PyQt6-WebEngine-Qt6 = ">=6.4.0" + +[[package]] +name = "pyqt6-webengine-qt6" +version = "6.4.0" +description = "The subset of a Qt installation needed by PyQt6-WebEngine." +category = "main" +optional = false +python-versions = "*" + +[[package]] name = "pytest" version = "6.2.5" description = "pytest: simple powerful testing with Python" @@ -256,7 +277,7 @@ testing = ["flake8 (<5)", "func-timeout", "jaraco.functools", "jaraco.itertools" [metadata] lock-version = "1.1" python-versions = "^3.7" -content-hash = "f0769984a7229dfc48d2ed7e72601ec4134370f2b0812ce289c3b57a5d310535" +content-hash = "f6348c72a45eadb6fb25490aeb4963f1e7a66eb056eb23c952ebe3addd81897b" [metadata.files] atomicwrites = [ @@ -344,6 +365,18 @@ pyqt6-sip = [ {file = "PyQt6_sip-13.4.0-cp39-cp39-win_amd64.whl", hash = "sha256:3486914137f5336cff6e10a5e9d52c1e60ff883473938b45f267f794daeacb2f"}, {file = "PyQt6_sip-13.4.0.tar.gz", hash = "sha256:6d87a3ee5872d7511b76957d68a32109352caf3b7a42a01d9ee20032b350d979"}, ] +pyqt6-webengine = [ + {file = "PyQt6_WebEngine-6.4.0-cp37-abi3-macosx_10_14_universal2.whl", hash = "sha256:9658919bc1c5279a6fae9e6990448dfe483e136e957e6fb14e8f6265f4e9d1da"}, + {file = "PyQt6_WebEngine-6.4.0-cp37-abi3-manylinux_2_28_x86_64.whl", hash = "sha256:3f17c7b41cceaf7bdeec69121b4ff211b43f62e4a7e89c7143124a4eb3fc9da2"}, + {file = "PyQt6_WebEngine-6.4.0-cp37-abi3-win_amd64.whl", hash = "sha256:7f6cde52b7b8c00ef2a1522ad92cde66f2bd3a3066646efe4ef96a4907b1b1cd"}, + {file = "PyQt6_WebEngine-6.4.0.tar.gz", hash = "sha256:4c71c130860abcd11e04cafb22e33983fa9a3aee8323c51909b15a1701828e21"}, +] +pyqt6-webengine-qt6 = [ + {file = "PyQt6_WebEngine_Qt6-6.4.0-py3-none-macosx_10_14_x86_64.whl", hash = "sha256:f13b3582c7f170017ecd52ec4c2e735c859316f05820e1bb4a2910c530611af4"}, + {file = "PyQt6_WebEngine_Qt6-6.4.0-py3-none-macosx_11_0_arm64.whl", hash = "sha256:572e7fee6de616191b98dd974ced8bd732e86dc1856c1ada7ad734402e37285c"}, + {file = "PyQt6_WebEngine_Qt6-6.4.0-py3-none-manylinux_2_28_x86_64.whl", hash = "sha256:971aedd051c77c17c59e724692636a4a0883c70dff3dbd172ae7cfb2fe7ddcc4"}, + {file = "PyQt6_WebEngine_Qt6-6.4.0-py3-none-win_amd64.whl", hash = "sha256:689127e483ab76744477762ab936de9541e7fc368ab4f4ee463a9099bf8bc5be"}, +] pytest = [ {file = "pytest-6.2.5-py3-none-any.whl", hash = "sha256:7310f8d27bc79ced999e760ca304d69f6ba6c6649c0b60fb0e04a4a77cacc134"}, {file = "pytest-6.2.5.tar.gz", hash = "sha256:131b36680866a76e6781d13f101efb86cf674ebb9762eb70d3082b6f29889e89"}, diff --git a/pyproject.toml b/pyproject.toml index 9f193dc..40ad145 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,6 +10,7 @@ python = "^3.7" colorlog = "^4.7.2" requests = "^2.25.1" pyqt6 = "^6.4.0" +pyqt6-webengine = "^6.4.0" [tool.poetry.dev-dependencies] # pyinstaller = "^4.2" |