add comments for gatewaylogin

This commit is contained in:
hongwei1 2019-08-10 23:42:18 +02:00
parent 954d60164d
commit 7b9f490b89
2 changed files with 9 additions and 4 deletions

View File

@ -45,7 +45,7 @@ class GatewayLoginForm(forms.Form):
cleaned_data = super(GatewayLoginForm, self).clean()
authenticator = GatewayLoginAuthenticator()
try:
authenticator.login_to_api(cleaned_data)
authenticator.prepare_gateway_login_token(cleaned_data)
cleaned_data['authenticator'] = authenticator
except AuthenticatorError as err:
raise forms.ValidationError(err)

View File

@ -45,7 +45,7 @@ class GatewayLoginAuthenticator(Authenticator):
self.token = token.decode('utf-8')
return self.token
def login_to_api(self, data):
def prepare_gateway_login_token(self, data):
token = self.create_jwt(data)
# Make a test call to see if the token works
url = '{}{}'.format(settings.API_ROOT, '/users/current')
@ -53,9 +53,14 @@ class GatewayLoginAuthenticator(Authenticator):
try:
response = api.get(url)
except requests.exceptions.ConnectionError as err:
raise AuthenticatorError(err)
raise AuthenticatorError(Exception("OBP-API server is not running or do not response properly. "
"Please check OBP-API server. "
"Details: " + str(err)))
except BaseException as err:
raise AuthenticatorError(Exception("Unknown Error. Details:" + str(err)))
# this will show the obp errors
if response.status_code != 200:
raise AuthenticatorError(response.json()['error'])
raise AuthenticatorError(response.json()['message'])
else:
return token