-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- error window with error description - updated user schemas
- Loading branch information
Showing
78 changed files
with
1,259 additions
and
1,154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,33 @@ | ||
from public_api.api import UsersAPI | ||
from public_api.shared_schemas import ( | ||
UserCreate, UserUpdate, UserSanitizedWithRole, Token, Message, User | ||
UserCreate, UserUpdate, UserSanitized, Token, Message | ||
) | ||
|
||
|
||
class AuthenticationService: | ||
def __init__(self, users_api: UsersAPI): | ||
self.users_api = users_api | ||
|
||
def login(self, email: str, password: str) -> Token: | ||
return self.users_api.login(email, password) | ||
def login(self, username: str, password: str) -> Token: | ||
return self.users_api.login(username, password) | ||
|
||
def login_2fa(self, email: str, password: str, two_factor_code: str) -> Token: | ||
return self.users_api.login_2fa(email, password, two_factor_code) | ||
def login_2fa(self, username: str, password: str, two_factor_code: str) -> Token: | ||
return self.users_api.login_2fa(username, password, two_factor_code) | ||
|
||
def register(self, user_data: UserCreate) -> User: | ||
def register(self, user_data: UserCreate) -> UserSanitized: | ||
return self.users_api.register(user_data) | ||
|
||
def reset_password(self, email: str) -> Message: | ||
return self.users_api.reset_password(email) | ||
|
||
def get_current_user(self) -> UserSanitizedWithRole: | ||
def refresh_token(self) -> Token: | ||
return self.users_api.refresh_token() | ||
|
||
def get_current_user(self) -> UserSanitized: | ||
return self.users_api.get_current_user() | ||
|
||
def update_current_user(self, user_data: UserUpdate) -> User: | ||
return self.users_api.update_current_user(user_data) | ||
def update_current_user(self, user_data: UserUpdate) -> UserSanitized: | ||
return self.users_api.update_current_user(user_data) | ||
|
||
def change_password(self, current_password: str, new_password: str) -> Message: | ||
return self.users_api.change_password(current_password, new_password) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,72 @@ | ||
import json | ||
|
||
from PySide6.QtCore import Qt | ||
from PySide6.QtWidgets import QDialog, QVBoxLayout, QLabel, QPushButton | ||
from PySide6.QtWidgets import (QDialog, QPushButton, QVBoxLayout, QTextEdit, | ||
QLabel, QDialogButtonBox, QApplication) | ||
from requests.exceptions import HTTPError | ||
|
||
|
||
class ErrorDialog(QDialog): | ||
def __init__(self, error_message, parent=None): | ||
super().__init__(parent) | ||
class DetailedErrorDialog(QDialog): | ||
def __init__(self, exctype, value, traceback, app_context): | ||
super().__init__() | ||
self.app_context = app_context | ||
self.setWindowTitle("Error") | ||
self.setFixedSize(300, 150) | ||
self.setMinimumSize(400, 300) | ||
self.setWindowFlags(self.windowFlags() | Qt.WindowMaximizeButtonHint | Qt.WindowMinimizeButtonHint) | ||
|
||
layout = QVBoxLayout(self) | ||
|
||
self.error_label = QLabel(error_message) | ||
self.error_label.setWordWrap(True) # Wrap long error messages | ||
layout.addWidget(self.error_label) | ||
error_label = QLabel("An error has occurred.") | ||
error_label.setStyleSheet("font-weight: bold; color: red;") | ||
layout.addWidget(error_label) | ||
|
||
detailed_text = f"Error Type: {exctype.__name__}\n" | ||
detailed_text += f"Error Message: {str(value)}\n\n" | ||
|
||
if isinstance(value, HTTPError): | ||
response = value.response | ||
detailed_text += f"Status Code: {response.status_code}\n" | ||
detailed_text += f"URL: {response.url}\n" | ||
detailed_text += "Response Headers:\n" | ||
for key, value in response.headers.items(): | ||
detailed_text += f" {key}: {value}\n" | ||
detailed_text += "\nResponse Content:\n" | ||
try: | ||
content = json.loads(response.content) | ||
detailed_text += json.dumps(content, indent=2) | ||
except json.JSONDecodeError: | ||
detailed_text += response.text | ||
|
||
text_edit = QTextEdit() | ||
text_edit.setPlainText(detailed_text) | ||
text_edit.setReadOnly(True) | ||
layout.addWidget(text_edit) | ||
|
||
button_box = QDialogButtonBox(QDialogButtonBox.Ok) | ||
button_box.accepted.connect(self.accept) | ||
layout.addWidget(button_box) | ||
|
||
relogin_button = QPushButton("Re-login") | ||
relogin_button.clicked.connect(self.relogin) | ||
button_box.addButton(relogin_button, QDialogButtonBox.ActionRole) | ||
|
||
def relogin(self): | ||
self.accept() | ||
main_window = QApplication.activeWindow() | ||
if main_window: | ||
main_window.close() | ||
|
||
from desktop_app.src.ui import LoginDialog | ||
login_dialog = LoginDialog(self.app_context.auth_service) | ||
if login_dialog.exec() == LoginDialog.Accepted: | ||
self.app_context.create_and_show_main_window() | ||
else: | ||
QApplication.quit() | ||
|
||
|
||
def global_exception_handler(app_context): | ||
def handler(exctype, value, traceback): | ||
error_dialog = DetailedErrorDialog(exctype, value, traceback, app_context) | ||
error_dialog.exec() | ||
|
||
self.ok_button = QPushButton("OK") | ||
self.ok_button.clicked.connect(self.accept) | ||
layout.addWidget(self.ok_button, alignment=Qt.AlignCenter) | ||
return handler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.