Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. data = json.loads(request.body)
  2. user_id = data['user_id']
  3. password = data['password']
  4.  
  5. account_exists_id = Account.objects.filter(user_id = data['user_id'])
  6.  
  7. if account_exists_id.exists() and bcrypt.checkpw(password.encode('UTF-8'), account_exists_id.get().password.encode("UTF-8")):
  8. user_id = account_exists_id.get().user_id
  9. payload = {
  10. 'user_id': user_id,
  11. 'exp' : datetime.utcnow() + timedelta(seconds = 60 * 60 * 24)
  12. }
  13. token = jwt.encode(payload, 'SECRET_KEY')
  14.  
  15. return JsonResponse({"access_token" : token.decode('UTF-8')})
  16.  
  17. else:
  18. return JsonResponse(status = 401)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement