Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- data = json.loads(request.body)
- user_id = data['user_id']
- password = data['password']
- account_exists_id = Account.objects.filter(user_id = data['user_id'])
- if account_exists_id.exists() and bcrypt.checkpw(password.encode('UTF-8'), account_exists_id.get().password.encode("UTF-8")):
- user_id = account_exists_id.get().user_id
- payload = {
- 'user_id': user_id,
- 'exp' : datetime.utcnow() + timedelta(seconds = 60 * 60 * 24)
- }
- token = jwt.encode(payload, 'SECRET_KEY')
- return JsonResponse({"access_token" : token.decode('UTF-8')})
- else:
- return JsonResponse(status = 401)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement