mirror of
https://github.com/nixietab/picodulce.git
synced 2025-04-10 10:28:56 +01:00
added the auth function
This commit is contained in:
parent
d7d6b3de4a
commit
d9b3b976d7
76
picodulce.py
76
picodulce.py
@ -226,7 +226,7 @@ class PicomcVersionSelector(QWidget):
|
|||||||
def manage_accounts(self):
|
def manage_accounts(self):
|
||||||
dialog = QDialog(self)
|
dialog = QDialog(self)
|
||||||
dialog.setWindowTitle('Manage Accounts')
|
dialog.setWindowTitle('Manage Accounts')
|
||||||
dialog.setFixedSize(300, 200)
|
dialog.setFixedSize(400, 250)
|
||||||
|
|
||||||
# Create title label
|
# Create title label
|
||||||
title_label = QLabel('Manage Accounts')
|
title_label = QLabel('Manage Accounts')
|
||||||
@ -240,33 +240,68 @@ class PicomcVersionSelector(QWidget):
|
|||||||
select_button = QPushButton('Select')
|
select_button = QPushButton('Select')
|
||||||
select_button.clicked.connect(lambda: self.set_default_account(dialog, account_combo.currentText()))
|
select_button.clicked.connect(lambda: self.set_default_account(dialog, account_combo.currentText()))
|
||||||
|
|
||||||
# Set layout
|
# Create input field for account name
|
||||||
layout = QVBoxLayout()
|
account_input = QLineEdit()
|
||||||
layout.addWidget(title_label)
|
account_input.setPlaceholderText('Xx_PussySlayer_xX')
|
||||||
layout.addWidget(account_combo)
|
|
||||||
layout.addWidget(select_button)
|
|
||||||
|
|
||||||
# Create a separate section for creating a new account
|
# Create button to create new account
|
||||||
create_account_layout = QHBoxLayout()
|
|
||||||
new_account_input = QLineEdit()
|
|
||||||
create_account_button = QPushButton('Create')
|
create_account_button = QPushButton('Create')
|
||||||
create_account_button.clicked.connect(lambda: self.create_account(dialog, new_account_input.text()))
|
create_account_button.clicked.connect(lambda: self.create_account(dialog, account_input.text(), microsoft_checkbox.isChecked()))
|
||||||
create_account_layout.addWidget(new_account_input)
|
|
||||||
create_account_layout.addWidget(create_account_button)
|
|
||||||
|
|
||||||
layout.addLayout(create_account_layout)
|
# Create checkbox for Microsoft account
|
||||||
|
microsoft_checkbox = QCheckBox('Microsoft Account')
|
||||||
|
|
||||||
# Create a separate section for removing an account
|
# Create button to authenticate
|
||||||
remove_account_layout = QHBoxLayout()
|
authenticate_button = QPushButton('Authenticate')
|
||||||
|
authenticate_button.clicked.connect(lambda: self.authenticate_account(dialog, account_combo.currentText()))
|
||||||
|
|
||||||
|
# Create button to remove account
|
||||||
remove_account_button = QPushButton('Remove Account')
|
remove_account_button = QPushButton('Remove Account')
|
||||||
remove_account_button.clicked.connect(lambda: self.remove_account(dialog, account_combo.currentText()))
|
remove_account_button.clicked.connect(lambda: self.remove_account(dialog, account_combo.currentText()))
|
||||||
|
|
||||||
|
# Create layout for account selection
|
||||||
|
account_selection_layout = QVBoxLayout()
|
||||||
|
account_selection_layout.addWidget(title_label)
|
||||||
|
account_selection_layout.addWidget(account_combo)
|
||||||
|
account_selection_layout.addWidget(select_button)
|
||||||
|
|
||||||
|
# Create layout for account creation
|
||||||
|
create_account_layout = QHBoxLayout()
|
||||||
|
create_account_layout.addWidget(account_input)
|
||||||
|
create_account_layout.addWidget(create_account_button)
|
||||||
|
|
||||||
|
# Create layout for Microsoft account checkbox and authenticate button
|
||||||
|
microsoft_layout = QVBoxLayout()
|
||||||
|
microsoft_layout.addWidget(microsoft_checkbox)
|
||||||
|
microsoft_layout.addWidget(authenticate_button)
|
||||||
|
|
||||||
|
# Create layout for remove account button
|
||||||
|
remove_account_layout = QVBoxLayout()
|
||||||
remove_account_layout.addWidget(remove_account_button)
|
remove_account_layout.addWidget(remove_account_button)
|
||||||
|
|
||||||
layout.addLayout(remove_account_layout)
|
# Create main layout
|
||||||
|
main_layout = QVBoxLayout()
|
||||||
|
main_layout.addLayout(account_selection_layout)
|
||||||
|
main_layout.addLayout(create_account_layout)
|
||||||
|
main_layout.addLayout(microsoft_layout)
|
||||||
|
# main_layout.addStretch(1)
|
||||||
|
main_layout.addLayout(remove_account_layout)
|
||||||
|
|
||||||
dialog.setLayout(layout)
|
dialog.setLayout(main_layout)
|
||||||
dialog.exec_()
|
dialog.exec_()
|
||||||
|
|
||||||
|
def authenticate_account(self, dialog, account_name):
|
||||||
|
# Remove leading " * " from the account name
|
||||||
|
account_name = account_name.strip().lstrip(" * ")
|
||||||
|
try:
|
||||||
|
subprocess.run(['picomc', 'account', 'authenticate', account_name], check=True)
|
||||||
|
QMessageBox.information(self, "Success", f"Account '{account_name}' authenticated successfully!")
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
error_message = f"Error authenticating account '{account_name}': {e.stderr.decode()}"
|
||||||
|
logging.error(error_message)
|
||||||
|
QMessageBox.critical(self, "Error", error_message)
|
||||||
|
|
||||||
|
|
||||||
def populate_accounts(self, account_combo):
|
def populate_accounts(self, account_combo):
|
||||||
# Run the command and get the output
|
# Run the command and get the output
|
||||||
try:
|
try:
|
||||||
@ -289,12 +324,15 @@ class PicomcVersionSelector(QWidget):
|
|||||||
account_combo.clear()
|
account_combo.clear()
|
||||||
account_combo.addItems(accounts)
|
account_combo.addItems(accounts)
|
||||||
|
|
||||||
def create_account(self, dialog, username):
|
def create_account(self, dialog, username, is_microsoft):
|
||||||
if username.strip() == '':
|
if username.strip() == '':
|
||||||
QMessageBox.warning(dialog, "Warning", "Username cannot be blank.")
|
QMessageBox.warning(dialog, "Warning", "Username cannot be blank.")
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
subprocess.run(['picomc', 'account', 'create', username], check=True)
|
if is_microsoft:
|
||||||
|
subprocess.run(['picomc', 'account', 'create', username, '--ms'], check=True)
|
||||||
|
else:
|
||||||
|
subprocess.run(['picomc', 'account', 'create', username], check=True)
|
||||||
QMessageBox.information(self, "Success", f"Account {username} created successfully!")
|
QMessageBox.information(self, "Success", f"Account {username} created successfully!")
|
||||||
self.populate_accounts(dialog.findChild(QComboBox))
|
self.populate_accounts(dialog.findChild(QComboBox))
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
|
Loading…
Reference in New Issue
Block a user