18 from typing
import Optional
20 from .network_response
import NetworkResponse
21 from .network_manager_base
import NetworkManagerBase
22 from ..configuration
import UserConfiguration
28 Subclass of NetworkManagerBase intended to be used
29 by a normal user. Contains functionality related to user
30 and authenticating as a normal user.
33 def __init__(self) -> None:
38 self.
_username_username: Optional[str] =
None
39 self.
_password_password: Optional[str] =
None
42 userConfig = UserConfiguration.load()
45 self.
_username_username = userConfig.username
46 self.
_password_password = userConfig.password
51 def _apiToken(self) -> Optional[str]:
55 def _apiToken(self, value: Optional[str]) ->
None:
59 def _refreshToken(self) -> Optional[str]:
63 def _refreshToken(self, value: Optional[str]) ->
None:
67 def hasStoredCredentials(self) -> bool:
70 def authenticate(self, username: str, password: str, storeCredentials: bool =
True) -> NetworkResponse:
72 Authenticates user with provided credentials
80 storeCredentials : bool
81 If true credentials will be stored in User object for reuse
85 NetworkResponse -> NetworkResponse object containing the full response info
89 >>> from coretex.networking import networkManager
91 >>> response = networkManager.authenticate(username = "dummy@coretex.ai", password = "123456")
92 >>> if response.hasFailed():
93 print("Failed to authenticate")
101 return super().
authenticate(username, password, storeCredentials)
105 Authenticates user with credentials stored inside User object
109 NetworkResponse -> NetworkResponse object containing the full response info
113 ValueError -> if credentials are not found
117 raise ValueError(
">> [Coretex] Credentials not stored")
NetworkResponse authenticateWithStoredCredentials(self)
NetworkResponse authenticate(self, str username, str password, bool storeCredentials=True)