1
0
Fork 0
mirror of synced 2024-06-25 17:50:45 +12:00

Remove login successful page and auto parse sid

This commit is contained in:
Dummerle 2021-10-07 21:58:50 +02:00
parent 4afff97893
commit 6ba445158d
4 changed files with 26 additions and 42 deletions

View file

@ -17,12 +17,11 @@ class LoginPages:
landing: int
browser: int
import_egl: int
success: int
class LoginDialog(QDialog, Ui_LoginDialog):
logged_in: bool = False
pages = LoginPages(landing=0, browser=1, import_egl=2, success=3)
pages = LoginPages(landing=0, browser=1, import_egl=2)
def __init__(self, core: LegendaryCore, parent=None):
super(LoginDialog, self).__init__(parent=parent)
@ -36,7 +35,7 @@ class LoginDialog(QDialog, Ui_LoginDialog):
self.login_stack.insertWidget(self.pages.browser, self.browser_page)
self.browser_page.success.connect(self.login_successful)
self.browser_page.changed.connect(
lambda: self.next_button.setEnabled(self.browser_page.is_valid())
self.next_button.setEnabled
)
self.import_page = ImportLogin(self.core, self.login_stack)
self.login_stack.insertWidget(self.pages.import_egl, self.import_page)
@ -88,12 +87,7 @@ class LoginDialog(QDialog, Ui_LoginDialog):
try:
if self.core.login():
self.logged_in = True
self.welcome_label.setText(
self.welcome_label.text().replace("</h1>", f", {self.core.lgd.userdata['displayName']}</h1>")
)
self.exit_button.setVisible(False)
self.back_button.setVisible(False)
self.login_stack.setCurrentIndex(self.pages.success)
self.close()
else:
raise ValueError("Login failed.")
except ValueError as e:

View file

@ -13,7 +13,7 @@ logger = getLogger("BrowserLogin")
class BrowserLogin(QWidget, Ui_BrowserLogin):
success = pyqtSignal()
changed = pyqtSignal()
changed = pyqtSignal(bool)
login_url = "https://www.epicgames.com/id/login?redirectUrl=https%3A%2F%2Fwww.epicgames.com%2Fid%2Fapi%2Fredirect"
def __init__(self, core: LegendaryCore, parent=None):
@ -23,10 +23,26 @@ class BrowserLogin(QWidget, Ui_BrowserLogin):
self.core = core
self.open_button.clicked.connect(self.open_browser)
self.sid_edit.textChanged.connect(self.changed.emit)
self.sid_edit.textChanged.connect(self.text_changed)
def is_valid(self):
return len(self.sid_edit.text()) == 32
def is_valid(self, text: str):
if text:
return len(text) == 32
else:
return len(self.sid_edit.text()) == 32
def text_changed(self, text):
if not self.is_valid(text):
try:
sid = json.loads(text).get("sid")
if sid and self.is_valid(sid):
self.sid_edit.setText(sid)
self.status_label.setText(self.tr("Parsed sid from pasted text"))
except json.JSONDecodeError:
self.changed.emit(False)
else:
self.changed.emit(True)
def do_login(self):
self.status_label.setText(self.tr("Logging in..."))

View file

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'login_dialog.ui'
# Form implementation generated from reading ui file 'rare/ui/components/dialogs/login/login_dialog.ui'
#
# Created by: PyQt5 UI code generator 5.15.4
#
@ -78,14 +78,6 @@ class Ui_LoginDialog(object):
spacerItem2 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.login_page_layout.addItem(spacerItem2, 1, 2, 2, 1)
self.login_stack.addWidget(self.login_page)
self.success_page = QtWidgets.QWidget()
self.success_page.setObjectName("success_page")
self.success_page_layout = QtWidgets.QHBoxLayout(self.success_page)
self.success_page_layout.setObjectName("success_page_layout")
self.success_label = QtWidgets.QLabel(self.success_page)
self.success_label.setObjectName("success_label")
self.success_page_layout.addWidget(self.success_label)
self.login_stack.addWidget(self.success_page)
self.dialog_layout.addWidget(self.login_stack)
self.button_layout = QtWidgets.QHBoxLayout()
self.button_layout.setObjectName("button_layout")
@ -103,7 +95,7 @@ class Ui_LoginDialog(object):
self.dialog_layout.addLayout(self.button_layout)
self.retranslateUi(LoginDialog)
self.login_stack.setCurrentIndex(1)
self.login_stack.setCurrentIndex(0)
QtCore.QMetaObject.connectSlotsByName(LoginDialog)
def retranslateUi(self, LoginDialog):
@ -115,8 +107,6 @@ class Ui_LoginDialog(object):
self.login_import_label.setText(_translate("LoginDialog", "Import from Epic Games Launcher"))
self.login_import_radio.setText(_translate("LoginDialog", "Import"))
self.login_browser_radio.setText(_translate("LoginDialog", "Browser"))
self.success_label.setText(_translate("LoginDialog",
"<html><head/><body><h2 style=\" margin-top:16px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:x-large; font-weight:600;\">Login Successful!</span></h2></body></html>"))
self.exit_button.setText(_translate("LoginDialog", "Exit"))
self.back_button.setText(_translate("LoginDialog", "Back"))
self.next_button.setText(_translate("LoginDialog", "Next"))
@ -124,7 +114,6 @@ class Ui_LoginDialog(object):
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
LoginDialog = QtWidgets.QDialog()
ui = Ui_LoginDialog()

View file

@ -77,7 +77,7 @@
<enum>QFrame::Raised</enum>
</property>
<property name="currentIndex">
<number>1</number>
<number>0</number>
</property>
<widget class="QWidget" name="login_page">
<property name="enabled">
@ -162,21 +162,6 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="success_page">
<layout class="QHBoxLayout" name="success_page_layout">
<item>
<widget class="QLabel" name="success_label">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;h2 style=&quot;
margin-top:16px; margin-bottom:12px; margin-left:0px; margin-right:0px;
-qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot;
font-size:x-large; font-weight:600;&quot;&gt;Login Successful!&lt;/span&gt;&lt;/h2&gt;&lt;/body&gt;&lt;/html&gt;
</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
<item>