2016-04-20 14:45:42 +03:00
|
|
|
"""Example business services module."""
|
2016-04-20 14:19:54 +03:00
|
|
|
|
|
|
|
|
|
|
|
class Users(object):
|
|
|
|
"""Users service."""
|
|
|
|
|
2016-10-06 22:48:43 +03:00
|
|
|
def __init__(self, logger, db):
|
2016-04-20 14:19:54 +03:00
|
|
|
"""Initializer."""
|
2016-10-06 22:48:43 +03:00
|
|
|
self.logger = logger
|
2016-04-20 14:19:54 +03:00
|
|
|
self.db = db
|
|
|
|
|
2016-10-06 22:48:43 +03:00
|
|
|
def get_user_by_id(self, uid):
|
2016-04-20 14:19:54 +03:00
|
|
|
"""Return user's information by login."""
|
2016-10-06 22:48:43 +03:00
|
|
|
self.logger.debug('User %s has been found in database', uid)
|
|
|
|
return {'uid': uid,
|
2016-04-20 14:19:54 +03:00
|
|
|
'password_hash': 'secret_hash'}
|
|
|
|
|
|
|
|
|
|
|
|
class Auth(object):
|
|
|
|
"""Auth service."""
|
|
|
|
|
2016-10-06 22:48:43 +03:00
|
|
|
def __init__(self, logger, db, token_ttl):
|
2016-04-20 14:19:54 +03:00
|
|
|
"""Initializer."""
|
2016-10-06 22:48:43 +03:00
|
|
|
self.logger = logger
|
2016-04-20 14:19:54 +03:00
|
|
|
self.db = db
|
|
|
|
self.token_ttl = token_ttl
|
|
|
|
|
|
|
|
def authenticate(self, user, password):
|
|
|
|
"""Authenticate user."""
|
|
|
|
assert user['password_hash'] == '_'.join((password, 'hash'))
|
2016-10-06 22:48:43 +03:00
|
|
|
self.logger.debug('User %s has been successfully authenticated',
|
|
|
|
user['uid'])
|
2016-04-20 14:19:54 +03:00
|
|
|
|
|
|
|
|
|
|
|
class Photos(object):
|
|
|
|
"""Photos service."""
|
|
|
|
|
2016-10-06 22:48:43 +03:00
|
|
|
def __init__(self, logger, db, s3):
|
2016-04-20 14:19:54 +03:00
|
|
|
"""Initializer."""
|
2016-10-06 22:48:43 +03:00
|
|
|
self.logger = logger
|
2016-04-20 14:19:54 +03:00
|
|
|
self.db = db
|
|
|
|
self.s3 = s3
|
|
|
|
|
2016-10-06 22:48:43 +03:00
|
|
|
def upload_photo(self, uid, photo_path):
|
2016-04-20 14:19:54 +03:00
|
|
|
"""Upload user photo."""
|
2016-10-06 22:48:43 +03:00
|
|
|
self.logger.debug('Photo %s has been successfully uploaded by user %s',
|
|
|
|
photo_path, uid)
|