zero_shubham1

Code_snip1

Feb 18th, 2020
620
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.81 KB | None | 0 0
  1. from starlette.responses import JSONResponse
  2.  
  3. async def resolve_login(_, info, email, password):
  4.    checked_user = await UserInDB.check_password(
  5.        email,
  6.        password
  7.    )
  8.    if checked_user:
  9.        now = datetime.datetime.now()
  10.        expires = now + datetime.timedelta(days=3)
  11.        payload = {
  12.            "id": checked_user.id,
  13.            "expire": expires.timestamp()
  14.        }
  15.        access_token = jwt.encode(payload, "secret", algorithm='HS256')
  16.        expires_in_seconds = expires.timestamp() - now.timestamp()
  17.     resp = JSONResponse({"user": checked_user})
  18.     if checked_user:
  19.         resp.set_cookie(
  20.                 key="Authorization",
  21.                 value=access_token.decode("utf-8"),
  22.                 expires=int(expires_in_seconds),
  23.                 httponly=True
  24.             )
  25.     return resp
Add Comment
Please, Sign In to add comment