2021-02-18 01:58:29 +13:00
|
|
|
import json
|
|
|
|
from logging import getLogger
|
|
|
|
|
|
|
|
from PyQt5.QtCore import pyqtSignal
|
|
|
|
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QPushButton, QLabel, QLineEdit
|
2021-03-19 00:45:59 +13:00
|
|
|
|
2021-03-17 03:12:37 +13:00
|
|
|
from custom_legendary.core import LegendaryCore
|
2021-02-18 01:58:29 +13:00
|
|
|
|
|
|
|
logger = getLogger("BrowserLogin")
|
|
|
|
|
2021-02-18 22:22:15 +13:00
|
|
|
|
|
|
|
class BrowserLogin(QWidget):
|
2021-02-18 01:58:29 +13:00
|
|
|
success = pyqtSignal()
|
|
|
|
url: str = "https://www.epicgames.com/id/login?redirectUrl=https%3A%2F%2Fwww.epicgames.com%2Fid%2Fapi%2Fredirect"
|
2021-02-18 22:22:15 +13:00
|
|
|
|
2021-02-18 01:58:29 +13:00
|
|
|
def __init__(self, core: LegendaryCore):
|
|
|
|
super(BrowserLogin, self).__init__()
|
|
|
|
self.layout = QVBoxLayout()
|
|
|
|
self.core = core
|
|
|
|
|
2021-02-18 22:22:15 +13:00
|
|
|
self.back = QPushButton("Back") # TODO Icon
|
2021-02-18 01:58:29 +13:00
|
|
|
self.layout.addWidget(self.back)
|
|
|
|
|
2021-03-12 00:56:38 +13:00
|
|
|
self.info_text = QLabel(self.tr(
|
2021-03-19 00:45:59 +13:00
|
|
|
"Opens a browser. You login and copy the json code in the field below. Click <a href='{}'>here</a> to open Browser").format(
|
|
|
|
self.url))
|
2021-02-18 01:58:29 +13:00
|
|
|
self.info_text.setWordWrap(True)
|
|
|
|
self.info_text.setOpenExternalLinks(True)
|
|
|
|
self.layout.addWidget(self.info_text)
|
|
|
|
|
|
|
|
self.input_field = QLineEdit()
|
2021-03-12 00:56:38 +13:00
|
|
|
self.input_field.setPlaceholderText(self.tr("Insert SID here"))
|
2021-02-18 01:58:29 +13:00
|
|
|
self.layout.addWidget(self.input_field)
|
|
|
|
|
|
|
|
self.mini_info = QLabel("")
|
|
|
|
|
2021-03-12 00:56:38 +13:00
|
|
|
self.login_btn = QPushButton(self.tr("Login"))
|
2021-02-18 01:58:29 +13:00
|
|
|
self.login_btn.clicked.connect(self.login)
|
|
|
|
self.layout.addWidget(self.login_btn)
|
|
|
|
|
|
|
|
self.setLayout(self.layout)
|
|
|
|
|
|
|
|
def login(self):
|
2021-03-12 00:56:38 +13:00
|
|
|
self.mini_info.setText(self.tr("Loading..."))
|
2021-02-18 01:58:29 +13:00
|
|
|
sid = self.input_field.text()
|
|
|
|
# when the text copied
|
|
|
|
if sid.startswith("{") and sid.endswith("}"):
|
|
|
|
sid = json.loads(sid)["sid"]
|
|
|
|
token = self.core.auth_sid(sid)
|
|
|
|
if self.core.auth_code(token):
|
|
|
|
logger.info(f"Successfully logged in as {self.core.lgd.userdata['displayName']}")
|
|
|
|
self.success.emit()
|
|
|
|
else:
|
2021-02-18 22:22:15 +13:00
|
|
|
self.mini_info.setText("Login failed")
|