Work on demo
This commit is contained in:
parent
77d9f70a3d
commit
7bf9b02b08
|
@ -0,0 +1,35 @@
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
metadata = sa.Metadata()
|
||||||
|
|
||||||
|
|
||||||
|
users = sa.Table(
|
||||||
|
'users', metadata,
|
||||||
|
sa.Column('id', sa.Integer, nullable=False),
|
||||||
|
sa.Column('login', sa.String(256), nullable=False),
|
||||||
|
sa.Column('passwd', sa.String(256), nullable=False),
|
||||||
|
sa.Column('salt', sa.String(256), nullable=False),
|
||||||
|
sa.Column('is_superuser', sa.Boolean, nullable=False,
|
||||||
|
server_default='FALSE'),
|
||||||
|
sa.Column('disabled', sa.Boolean, nullable=False,
|
||||||
|
server_default='FALSE'),
|
||||||
|
|
||||||
|
# indices
|
||||||
|
sa.PrimaryKeyConstraint('id', name='user_pkey'),
|
||||||
|
sa.UniqueConstraint('login', name='user_login_key'),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
permissions = sa.Table(
|
||||||
|
'permissions', metadata,
|
||||||
|
sa.Column('id', sa.Integer, nullable=False),
|
||||||
|
sa.Column('user_id', sa.Integer, nullable=False),
|
||||||
|
sa.Column('perm_name', sa.String(64), nullable=False),
|
||||||
|
|
||||||
|
# indices
|
||||||
|
sa.PrimaryKeyConstraint('id', name='permission_pkey'),
|
||||||
|
sa.ForeignKeyConstraint(['user_id'], [users.c.id],
|
||||||
|
name='user_permission_fkey',
|
||||||
|
ondelete='CASCADE'),
|
||||||
|
)
|
|
@ -3,9 +3,9 @@ import asyncio
|
||||||
from aiohttp_security.authorization import AbstractAuthorizationPolicy
|
from aiohttp_security.authorization import AbstractAuthorizationPolicy
|
||||||
|
|
||||||
|
|
||||||
class DictionaryAuthorizationPolicy(AbstractAuthorizationPolicy):
|
class DBAuthorizationPolicy(AbstractAuthorizationPolicy):
|
||||||
def __init__(self, data):
|
def __init__(self, db_pool):
|
||||||
self.data = data
|
self.db_pool = db_pool
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def permits(self, identity, permission, context=None):
|
def permits(self, identity, permission, context=None):
|
||||||
|
@ -18,4 +18,6 @@ class DictionaryAuthorizationPolicy(AbstractAuthorizationPolicy):
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def authorized_user_id(self, identity):
|
def authorized_user_id(self, identity):
|
||||||
|
with (yield from self.db_pool) as conn:
|
||||||
|
conn
|
||||||
return identity if identity in self.data else None
|
return identity if identity in self.data else None
|
|
@ -7,3 +7,4 @@ sphinx
|
||||||
alabaster>=0.6.2
|
alabaster>=0.6.2
|
||||||
pep257
|
pep257
|
||||||
aiohttp_session
|
aiohttp_session
|
||||||
|
aiopg[sa]
|
||||||
|
|
Loading…
Reference in New Issue