コード例 #1
0
    async def post(self) -> Union[web.json_response, web.HTTPException]:
        """
        Take user credentials and check if user exist.
        If exist - return his profile in JSON. Else -> HTTPException
        Returns: User profile or Exception

        """
        request_data = await self.request.json()

        result = await self.find_user(request_data)

        if not result:
            raise web.HTTPNotFound(text="User not found")

        profile = Profile(**clean_data(result))

        if profile.check_password(request_data['password']):
            await profile.fetch_contacts(self.request.app['db'])

            return web.json_response(profile.to_dict(), status=200)

        raise web.HTTPNotAcceptable(text="Wrong password")