forked from platformio/platformio-core
Rename "authenticating" to "authorizing" wording for PIO Account
This commit is contained in:
@ -43,13 +43,24 @@ class AccountClient(object):
|
|||||||
adapter = requests.adapters.HTTPAdapter(max_retries=retry)
|
adapter = requests.adapters.HTTPAdapter(max_retries=retry)
|
||||||
self._session.mount(api_base_url, adapter)
|
self._session.mount(api_base_url, adapter)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_refresh_token():
|
||||||
|
try:
|
||||||
|
return app.get_state_item("account").get("auth").get("refresh_token")
|
||||||
|
except: # pylint:disable=bare-except
|
||||||
|
raise exception.AccountNotAuthorized()
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def delete_local_session():
|
||||||
|
app.delete_state_item("account")
|
||||||
|
|
||||||
def login(self, username, password):
|
def login(self, username, password):
|
||||||
try:
|
try:
|
||||||
self.fetch_authentication_token()
|
self.fetch_authentication_token()
|
||||||
except: # pylint:disable=bare-except
|
except: # pylint:disable=bare-except
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
raise exception.AccountAlreadyAuthenticated(
|
raise exception.AccountAlreadyAuthorized(
|
||||||
app.get_state_item("account", {}).get("email", "")
|
app.get_state_item("account", {}).get("email", "")
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -67,7 +78,7 @@ class AccountClient(object):
|
|||||||
except: # pylint:disable=bare-except
|
except: # pylint:disable=bare-except
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
raise exception.AccountAlreadyAuthenticated(
|
raise exception.AccountAlreadyAuthorized(
|
||||||
app.get_state_item("account", {}).get("email", "")
|
app.get_state_item("account", {}).get("email", "")
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -83,7 +94,8 @@ class AccountClient(object):
|
|||||||
try:
|
try:
|
||||||
refresh_token = self.get_refresh_token()
|
refresh_token = self.get_refresh_token()
|
||||||
except: # pylint:disable=bare-except
|
except: # pylint:disable=bare-except
|
||||||
raise exception.AccountNotAuthenticated()
|
raise exception.AccountNotAuthorized()
|
||||||
|
self.delete_local_session()
|
||||||
response = requests.post(
|
response = requests.post(
|
||||||
self.api_base_url + "/v1/logout", data={"refresh_token": refresh_token},
|
self.api_base_url + "/v1/logout", data={"refresh_token": refresh_token},
|
||||||
)
|
)
|
||||||
@ -91,14 +103,13 @@ class AccountClient(object):
|
|||||||
self.raise_error_from_response(response)
|
self.raise_error_from_response(response)
|
||||||
except exception.AccountError:
|
except exception.AccountError:
|
||||||
pass
|
pass
|
||||||
app.delete_state_item("account")
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def change_password(self, old_password, new_password):
|
def change_password(self, old_password, new_password):
|
||||||
try:
|
try:
|
||||||
token = self.fetch_authentication_token()
|
token = self.fetch_authentication_token()
|
||||||
except: # pylint:disable=bare-except
|
except: # pylint:disable=bare-except
|
||||||
raise exception.AccountNotAuthenticated()
|
raise exception.AccountNotAuthorized()
|
||||||
response = self._session.post(
|
response = self._session.post(
|
||||||
self.api_base_url + "/v1/password",
|
self.api_base_url + "/v1/password",
|
||||||
headers={"Authorization": "Bearer %s" % token},
|
headers={"Authorization": "Bearer %s" % token},
|
||||||
@ -115,7 +126,7 @@ class AccountClient(object):
|
|||||||
except: # pylint:disable=bare-except
|
except: # pylint:disable=bare-except
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
raise exception.AccountAlreadyAuthenticated(
|
raise exception.AccountAlreadyAuthorized(
|
||||||
app.get_state_item("account", {}).get("email", "")
|
app.get_state_item("account", {}).get("email", "")
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -135,7 +146,7 @@ class AccountClient(object):
|
|||||||
try:
|
try:
|
||||||
token = self.fetch_authentication_token()
|
token = self.fetch_authentication_token()
|
||||||
except: # pylint:disable=bare-except
|
except: # pylint:disable=bare-except
|
||||||
raise exception.AccountNotAuthenticated()
|
raise exception.AccountNotAuthorized()
|
||||||
response = self._session.post(
|
response = self._session.post(
|
||||||
self.api_base_url + "/v1/token",
|
self.api_base_url + "/v1/token",
|
||||||
headers={"Authorization": "Bearer %s" % token},
|
headers={"Authorization": "Bearer %s" % token},
|
||||||
@ -153,7 +164,7 @@ class AccountClient(object):
|
|||||||
try:
|
try:
|
||||||
token = self.fetch_authentication_token()
|
token = self.fetch_authentication_token()
|
||||||
except: # pylint:disable=bare-except
|
except: # pylint:disable=bare-except
|
||||||
raise exception.AccountNotAuthenticated()
|
raise exception.AccountNotAuthorized()
|
||||||
response = self._session.get(
|
response = self._session.get(
|
||||||
self.api_base_url + "/v1/profile",
|
self.api_base_url + "/v1/profile",
|
||||||
headers={"Authorization": "Bearer %s" % token},
|
headers={"Authorization": "Bearer %s" % token},
|
||||||
@ -164,7 +175,7 @@ class AccountClient(object):
|
|||||||
try:
|
try:
|
||||||
token = self.fetch_authentication_token()
|
token = self.fetch_authentication_token()
|
||||||
except: # pylint:disable=bare-except
|
except: # pylint:disable=bare-except
|
||||||
raise exception.AccountNotAuthenticated()
|
raise exception.AccountNotAuthorized()
|
||||||
profile["current_password"] = current_password
|
profile["current_password"] = current_password
|
||||||
response = self._session.put(
|
response = self._session.put(
|
||||||
self.api_base_url + "/v1/profile",
|
self.api_base_url + "/v1/profile",
|
||||||
@ -177,7 +188,7 @@ class AccountClient(object):
|
|||||||
if offline:
|
if offline:
|
||||||
account = app.get_state_item("account")
|
account = app.get_state_item("account")
|
||||||
if not account:
|
if not account:
|
||||||
raise exception.AccountNotAuthenticated()
|
raise exception.AccountNotAuthorized()
|
||||||
return {
|
return {
|
||||||
"profile": {
|
"profile": {
|
||||||
"email": account.get("email"),
|
"email": account.get("email"),
|
||||||
@ -187,7 +198,7 @@ class AccountClient(object):
|
|||||||
try:
|
try:
|
||||||
token = self.fetch_authentication_token()
|
token = self.fetch_authentication_token()
|
||||||
except: # pylint:disable=bare-except
|
except: # pylint:disable=bare-except
|
||||||
raise exception.AccountNotAuthenticated()
|
raise exception.AccountNotAuthorized()
|
||||||
response = self._session.get(
|
response = self._session.get(
|
||||||
self.api_base_url + "/v1/summary",
|
self.api_base_url + "/v1/summary",
|
||||||
headers={"Authorization": "Bearer %s" % token},
|
headers={"Authorization": "Bearer %s" % token},
|
||||||
@ -211,19 +222,10 @@ class AccountClient(object):
|
|||||||
app.set_state_item("account", result)
|
app.set_state_item("account", result)
|
||||||
return result.get("auth").get("access_token")
|
return result.get("auth").get("access_token")
|
||||||
except exception.AccountError:
|
except exception.AccountError:
|
||||||
app.delete_state_item("account")
|
self.delete_local_session()
|
||||||
raise exception.AccountNotAuthenticated()
|
raise exception.AccountNotAuthorized()
|
||||||
|
|
||||||
@staticmethod
|
def raise_error_from_response(self, response, expected_codes=(200, 201, 202)):
|
||||||
def get_refresh_token():
|
|
||||||
try:
|
|
||||||
auth = app.get_state_item("account").get("auth").get("refresh_token")
|
|
||||||
return auth
|
|
||||||
except: # pylint:disable=bare-except
|
|
||||||
raise exception.AccountNotAuthenticated()
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def raise_error_from_response(response, expected_codes=(200, 201, 202)):
|
|
||||||
if response.status_code in expected_codes:
|
if response.status_code in expected_codes:
|
||||||
try:
|
try:
|
||||||
return response.json()
|
return response.json()
|
||||||
@ -234,5 +236,5 @@ class AccountClient(object):
|
|||||||
except (KeyError, ValueError):
|
except (KeyError, ValueError):
|
||||||
message = response.text
|
message = response.text
|
||||||
if "Authorization session has been expired" in message:
|
if "Authorization session has been expired" in message:
|
||||||
app.delete_state_item("account")
|
self.delete_local_session()
|
||||||
raise exception.AccountError(message)
|
raise exception.AccountError(message)
|
||||||
|
@ -167,7 +167,7 @@ def account_update(current_password, **kwargs):
|
|||||||
return None
|
return None
|
||||||
try:
|
try:
|
||||||
client.logout()
|
client.logout()
|
||||||
except exception.AccountNotAuthenticated:
|
except exception.AccountNotAuthorized:
|
||||||
pass
|
pass
|
||||||
if email_changed:
|
if email_changed:
|
||||||
return click.secho(
|
return click.secho(
|
||||||
|
@ -20,11 +20,11 @@ class AccountError(PlatformioException):
|
|||||||
MESSAGE = "{0}"
|
MESSAGE = "{0}"
|
||||||
|
|
||||||
|
|
||||||
class AccountNotAuthenticated(AccountError):
|
class AccountNotAuthorized(AccountError):
|
||||||
|
|
||||||
MESSAGE = "You are not authenticated! Please login to PIO Account."
|
MESSAGE = "You are not authorized! Please log in to PIO Account."
|
||||||
|
|
||||||
|
|
||||||
class AccountAlreadyAuthenticated(AccountError):
|
class AccountAlreadyAuthorized(AccountError):
|
||||||
|
|
||||||
MESSAGE = "You are already authenticated with {0} account."
|
MESSAGE = "You are already authorized with {0} account."
|
||||||
|
@ -24,7 +24,7 @@ from platformio.proc import get_pythonexe_path
|
|||||||
from platformio.project.config import ProjectConfig
|
from platformio.project.config import ProjectConfig
|
||||||
|
|
||||||
CORE_PACKAGES = {
|
CORE_PACKAGES = {
|
||||||
"contrib-piohome": "~3.2.0",
|
"contrib-piohome": "~3.2.1",
|
||||||
"contrib-pysite": "~2.%d%d.0" % (sys.version_info.major, sys.version_info.minor),
|
"contrib-pysite": "~2.%d%d.0" % (sys.version_info.major, sys.version_info.minor),
|
||||||
"tool-unity": "~1.20500.0",
|
"tool-unity": "~1.20500.0",
|
||||||
"tool-scons": "~2.20501.7" if PY2 else "~3.30102.0",
|
"tool-scons": "~2.20501.7" if PY2 else "~3.30102.0",
|
||||||
|
Reference in New Issue
Block a user