def user_loader(name): repository = UsersRepository() response = repository.list(filters=dict(name=name)) if not response: return None user = response[0] user.is_active = True user.is_authenticated = True user.is_anonymous = False user.get_id = lambda _: user.name return user
def request_loader(request): name = request.form.get('name') repository = UsersRepository() response = repository.list(filters=dict(name=name)) if not response: return None user = response[0] user.is_authenticated = repository.check_password(user, request.form['password']) user.is_active = True user.is_anonymous = False user.get_id = lambda _: user.name return user
import json from sqlalchemy import event from sqlalchemy.engine import Engine from collections import namedtuple from taskplus.apps.rest.repositories import UsersRepository from taskplus.apps.rest.routes import authorization_manager from taskplus.apps.rest.database import Base, db_session, engine users_repository = UsersRepository() User = namedtuple('User', ['id', 'name', 'roles']) Role = namedtuple('Role', ['id', 'name']) user = User(id=1, name='super', roles=[ Role(id=1, name='creator'), Role(id=2, name='doer'), Role(id=3, name='admin'), ]) user2 = User(id=2, name='abc', roles=[ Role(id=1, name='creator'), Role(id=2, name='doer'), Role(id=3, name='admin'), ])