2022-02-03 00:46:45 +01:00
|
|
|
# -*- encoding: utf-8 -*-
|
|
|
|
from aiohttp.web import middleware, HTTPFound
|
|
|
|
|
|
|
|
from phi import app
|
2022-02-03 12:16:34 +01:00
|
|
|
from phi.async_ldap.model import Hackers, Robots, Roles
|
2022-02-03 00:46:45 +01:00
|
|
|
|
|
|
|
|
|
|
|
@middleware
|
|
|
|
async def authenticated(request, handler):
|
|
|
|
try:
|
|
|
|
store = request.app["store"]
|
|
|
|
except KeyError:
|
|
|
|
raise HTTPFound(app.LOGIN_ROUTE)
|
|
|
|
|
|
|
|
client = await store.get_client(request)
|
|
|
|
|
|
|
|
request.app["ldap_client"] = client
|
|
|
|
request.app["users"] = Hackers(client)
|
|
|
|
request.app["services"] = Robots(client)
|
2022-02-03 12:16:34 +01:00
|
|
|
request.app["groups"] = Roles(client)
|
2022-02-03 00:46:45 +01:00
|
|
|
resp = await handler(request)
|
|
|
|
|
|
|
|
return resp
|