# -*- encoding: utf-8 -*- from aiohttp.web import HTTPBadRequest, HTTPOk from phi.async_ldap.client import AsyncClient async def login(request): log = request.app["log"] log.debug("login") store = request.app["store"] config = request.app["config"] body = await request.json() tag = body.get("tag", "uid") ou = body.get("ou") if ou is not None: config["ldap"]["ou"] = ou try: user = body["user"] password = body["password"] except KeyError as e: text = f"Missing key: {e}" log.warn(text) raise HTTPBadRequest(text=text) client = AsyncClient( attribute_id=tag, username=user, password=password, **config.get("ldap") ) log.debug(f"Client: {client}") await store.set_client(request, client) raise HTTPOk