new repository for authentication logic

pull/39/head
Chris Veilleux 2019-02-01 00:32:52 -06:00
parent 753c522833
commit b733f68d7f
1 changed files with 31 additions and 0 deletions

View File

@ -0,0 +1,31 @@
from os import path
from selene.util.db import DatabaseRequest, Cursor
from ..entity.account import Account
SQL_DIR = path.join(path.dirname(__file__), 'sql')
class AuthenticationRepository(object):
def __init__(self, db):
self.db = db
def get_account_from_credentials(
self, email: str, password: str
) -> Account:
"""
Validate email/password combination against the database
:param email: the user provided email address
:param password: the user provided password
:return: the matching account record, if one is found
"""
query = DatabaseRequest(
file_path=path.join(SQL_DIR, 'get_account_from_credentials.sql'),
args=dict(email_address=email, password=password),
)
cursor = Cursor(self.db)
sql_results = cursor.select_one(query)
if sql_results is not None:
return Account(**sql_results)