Newer
Older
from os import environ
from hydra_client import HydraAdmin
from flask_login import UserMixin
from graphqlclient import GraphQLClient
GRAPHQL_URL = environ['GRAPHQL_URL']
graphql_client = GraphQLClient(GRAPHQL_URL)
class User(UserMixin):
def __init__(self, username):
self.id = username
self.username = username
self.active = False
try:
self._load_remote_user_info()
except urllib.error.HTTPError as error:
raise BackendConnectionError(
error.code,
error.headers,
("Error during retrieval of userdata - " + error.reason))
if "data" in result and result["data"]["getUser"] is not None:
self.active = result["data"]["getUser"]["active"]
self.email = result["data"]["getUser"]["email"]
which verifies the password by hashing it and comparing it to a stored password
hash.
Args:
password: cleartext password
Returns:
Boolean result of password verification
"""
querystring = '''{{
verifyPassword(
username: "{0}",
password: "{1}")
verified = False
if "data" in result:
verified = result["data"]["verifyPassword"]
return verified
def authenticate(self, password):
return self.active and self._verify_password(password)
class BackendConnectionError(Exception):
"""Raised when requests to the backend server fail
Attributes:
code -- http response code
headers -- http response headers
reason -- reson for the error
"""
def __init__(self, code, headers, reason):
self.code = code
self.headers = headers
self.reason = reason