mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-08-12 16:28:59 +08:00
Fixed some styling and typing issues
Some boyscouting. Contributes to: CURA-8539
This commit is contained in:
parent
70504f1b04
commit
0a43366ffc
@ -94,12 +94,12 @@ class AuthorizationHelpers:
|
|||||||
return
|
return
|
||||||
|
|
||||||
callback(AuthenticationResponse(success = True,
|
callback(AuthenticationResponse(success = True,
|
||||||
token_type = token_data["token_type"],
|
token_type = token_data["token_type"],
|
||||||
access_token = token_data["access_token"],
|
access_token = token_data["access_token"],
|
||||||
refresh_token = token_data["refresh_token"],
|
refresh_token = token_data["refresh_token"],
|
||||||
expires_in = token_data["expires_in"],
|
expires_in = token_data["expires_in"],
|
||||||
scope = token_data["scope"],
|
scope = token_data["scope"],
|
||||||
received_at = datetime.now().strftime(TOKEN_TIMESTAMP_FORMAT)))
|
received_at = datetime.now().strftime(TOKEN_TIMESTAMP_FORMAT)))
|
||||||
return
|
return
|
||||||
|
|
||||||
def checkToken(self, access_token: str, success_callback: Optional[Callable[[UserProfile], None]] = None, failed_callback: Optional[Callable[[], None]] = None) -> None:
|
def checkToken(self, access_token: str, success_callback: Optional[Callable[[UserProfile], None]] = None, failed_callback: Optional[Callable[[], None]] = None) -> None:
|
||||||
|
@ -15,6 +15,7 @@ if TYPE_CHECKING:
|
|||||||
|
|
||||||
catalog = i18nCatalog("cura")
|
catalog = i18nCatalog("cura")
|
||||||
|
|
||||||
|
|
||||||
class AuthorizationRequestHandler(BaseHTTPRequestHandler):
|
class AuthorizationRequestHandler(BaseHTTPRequestHandler):
|
||||||
"""This handler handles all HTTP requests on the local web server.
|
"""This handler handles all HTTP requests on the local web server.
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@ if TYPE_CHECKING:
|
|||||||
|
|
||||||
MYCLOUD_LOGOFF_URL = "https://account.ultimaker.com/logoff?utm_source=cura&utm_medium=software&utm_campaign=change-account-before-adding-printers"
|
MYCLOUD_LOGOFF_URL = "https://account.ultimaker.com/logoff?utm_source=cura&utm_medium=software&utm_campaign=change-account-before-adding-printers"
|
||||||
|
|
||||||
|
|
||||||
class AuthorizationService:
|
class AuthorizationService:
|
||||||
"""The authorization service is responsible for handling the login flow, storing user credentials and providing
|
"""The authorization service is responsible for handling the login flow, storing user credentials and providing
|
||||||
account information.
|
account information.
|
||||||
@ -62,7 +63,7 @@ class AuthorizationService:
|
|||||||
if self._preferences:
|
if self._preferences:
|
||||||
self._preferences.addPreference(self._settings.AUTH_DATA_PREFERENCE_KEY, "{}")
|
self._preferences.addPreference(self._settings.AUTH_DATA_PREFERENCE_KEY, "{}")
|
||||||
|
|
||||||
def getUserProfile(self, callback: Callable[[Optional["UserProfile"]], None] = None) -> None:
|
def getUserProfile(self, callback: Optional[Callable[[Optional["UserProfile"]], None]] = None) -> None:
|
||||||
"""
|
"""
|
||||||
Get the user profile as obtained from the JWT (JSON Web Token).
|
Get the user profile as obtained from the JWT (JSON Web Token).
|
||||||
|
|
||||||
@ -79,7 +80,7 @@ class AuthorizationService:
|
|||||||
return
|
return
|
||||||
|
|
||||||
# If no user profile was stored locally, we try to get it from JWT.
|
# If no user profile was stored locally, we try to get it from JWT.
|
||||||
def store_profile(profile: Optional["UserProfile"]):
|
def store_profile(profile: Optional["UserProfile"]) -> None:
|
||||||
if profile is not None:
|
if profile is not None:
|
||||||
self._user_profile = profile
|
self._user_profile = profile
|
||||||
if callback is not None:
|
if callback is not None:
|
||||||
@ -110,7 +111,7 @@ class AuthorizationService:
|
|||||||
return
|
return
|
||||||
|
|
||||||
# When we checked the token we may get a user profile. This callback checks if that is a valid one and tries to refresh the token if it's not.
|
# When we checked the token we may get a user profile. This callback checks if that is a valid one and tries to refresh the token if it's not.
|
||||||
def check_user_profile(user_profile):
|
def check_user_profile(user_profile: Optional["UserProfile"]) -> None:
|
||||||
if user_profile:
|
if user_profile:
|
||||||
# If the profile was found, we call it back immediately.
|
# If the profile was found, we call it back immediately.
|
||||||
callback(user_profile)
|
callback(user_profile)
|
||||||
@ -121,7 +122,7 @@ class AuthorizationService:
|
|||||||
callback(None)
|
callback(None)
|
||||||
return
|
return
|
||||||
|
|
||||||
def process_auth_data(auth_data: AuthenticationResponse):
|
def process_auth_data(auth_data: AuthenticationResponse) -> None:
|
||||||
if auth_data.access_token is None:
|
if auth_data.access_token is None:
|
||||||
Logger.warning("Unable to use the refresh token to get a new access token.")
|
Logger.warning("Unable to use the refresh token to get a new access token.")
|
||||||
callback(None)
|
callback(None)
|
||||||
@ -161,7 +162,7 @@ class AuthorizationService:
|
|||||||
Logger.log("w", "Unable to refresh access token, since there is no refresh token.")
|
Logger.log("w", "Unable to refresh access token, since there is no refresh token.")
|
||||||
return
|
return
|
||||||
|
|
||||||
def process_auth_data(response: AuthenticationResponse):
|
def process_auth_data(response: AuthenticationResponse) -> None:
|
||||||
if response.success:
|
if response.success:
|
||||||
self._storeAuthData(response)
|
self._storeAuthData(response)
|
||||||
self.onAuthStateChanged.emit(logged_in = True)
|
self.onAuthStateChanged.emit(logged_in = True)
|
||||||
@ -264,7 +265,7 @@ class AuthorizationService:
|
|||||||
self._auth_data = AuthenticationResponse(**preferences_data)
|
self._auth_data = AuthenticationResponse(**preferences_data)
|
||||||
|
|
||||||
# Also check if we can actually get the user profile information.
|
# Also check if we can actually get the user profile information.
|
||||||
def callback(profile: Optional["UserProfile"]):
|
def callback(profile: Optional["UserProfile"]) -> None:
|
||||||
if profile is not None:
|
if profile is not None:
|
||||||
self.onAuthStateChanged.emit(logged_in = True)
|
self.onAuthStateChanged.emit(logged_in = True)
|
||||||
Logger.debug("Auth data was successfully loaded")
|
Logger.debug("Auth data was successfully loaded")
|
||||||
@ -272,7 +273,8 @@ class AuthorizationService:
|
|||||||
if self._unable_to_get_data_message is not None:
|
if self._unable_to_get_data_message is not None:
|
||||||
self._unable_to_get_data_message.show()
|
self._unable_to_get_data_message.show()
|
||||||
else:
|
else:
|
||||||
self._unable_to_get_data_message = Message(i18n_catalog.i18nc("@info", "Unable to reach the Ultimaker account server."),
|
self._unable_to_get_data_message = Message(i18n_catalog.i18nc("@info",
|
||||||
|
"Unable to reach the Ultimaker account server."),
|
||||||
title = i18n_catalog.i18nc("@info:title", "Log-in failed"),
|
title = i18n_catalog.i18nc("@info:title", "Log-in failed"),
|
||||||
message_type = Message.MessageType.ERROR)
|
message_type = Message.MessageType.ERROR)
|
||||||
Logger.warning("Unable to get user profile using auth data from preferences.")
|
Logger.warning("Unable to get user profile using auth data from preferences.")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user