Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- "detail": "Authentication credentials were not provided."
- }
- REST_FRAMEWORK = {
- 'DEFAULT_PERMISSION_CLASSES': (
- 'rest_framework.permissions.IsAuthenticated',
- ),
- 'DEFAULT_AUTHENTICATION_CLASSES': (
- 'rest_framework.authentication.SessionAuthentication',
- 'rest_framework.authentication.BasicAuthentication',
- ),
- }
- JWT_AUTH = {
- 'JWT_ALLOW_REFRESH': True,
- 'JWT_EXPIRATION_DELTA': datetime.timedelta(hours=1),
- 'JWT_REFRESH_EXPIRATION_DELTA': datetime.timedelta(days=7),
- }
- def post(self, request, format=None):
- if not request.data:
- return Response({'Error': "Please provide username/password"}, status=status.HTTP_400_BAD_REQUEST)
- username = request.data['username']
- password = request.data['password']
- try:
- user = User.objects.get(email=username, password=password)
- except User.DoesNotExist:
- return Response({'Error': "Invalid username/password"}, status=status.HTTP_400_BAD_REQUEST)
- if user:
- payload = {
- 'id': user.id,
- 'email': user.email,
- 'first_name': user.first_name
- }
- jwt_token = jwt.encode(payload, "SECRET_KEY") # to be changed
- return Response({'token': jwt_token}, status=status.HTTP_200_OK)
- authentication_class = (JSONWebTokenAuthentication,)
- permission_classes = (IsAuthenticated,)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement