MCPcopy Create free account
hub / github.com/AstroPrint/AstroBox / getAccessKeys

Method getAccessKeys

src/astroprint/plugin/services/auth.py:23–71  ·  view source on GitHub ↗
(self, data, sendResponse)

Source from the content-addressed store, hash-verified

21 #REQUESTS
22
23 def getAccessKeys(self, data, sendResponse):
24 publicKey = email = accessKey = None
25
26 if 'email' in data:
27 email = data['email']
28
29 if 'accessKey' in data:
30 accessKey = data['accessKey']
31
32 userLogged = settings().get(["cloudSlicer", "loggedUser"])
33 ####
34 # - nobody logged: None
35 # - any log: email
36
37 if email and accessKey:#somebody is logged in the remote client
38 if userLogged:#Somebody logged in Astrobox
39 if userLogged == email:#I am the user logged
40 online = networkManager().isOnline()
41
42 if online:
43 publicKey = astroprintCloud().get_public_key(email, accessKey)
44
45 if not publicKey:
46 self._logger.error('error getting public key', exc_info = True)
47 sendResponse('error_getting_public_key',True)
48 return
49
50 else:
51 user = userManager.findUser(email)
52 if user.get_private_key() != accessKey:
53 self._logger.error('incorrect logged user', exc_info = True)
54 sendResponse('incorrect_logged_user',True)
55 return
56
57 else:#I am NOT the logged user
58 self._logger.error('incorrect logged user', exc_info = True)
59 sendResponse('incorrect_logged_user',True)
60 return
61
62 else:#nodody is logged in the remote client
63 if userLogged:
64 self._logger.error('any user logged', exc_info = True)
65 sendResponse('no_user_logged',True)
66 return
67
68 sendResponse({
69 'api_key': UI_API_KEY,
70 'ws_token': create_ws_token(publicKey)
71 })

Callers

nothing calls this directly

Calls 10

settingsFunction · 0.90
networkManagerFunction · 0.90
astroprintCloudFunction · 0.90
create_ws_tokenFunction · 0.90
get_public_keyMethod · 0.80
getMethod · 0.45
isOnlineMethod · 0.45
errorMethod · 0.45
findUserMethod · 0.45
get_private_keyMethod · 0.45

Tested by

no test coverage detected