|
1 | 1 | import jwt
|
2 | 2 | from django.conf import settings
|
3 | 3 | from django.contrib.auth import logout
|
4 |
| -from django.core.exceptions import ValidationError |
| 4 | +from django.core.exceptions import ValidationError,PermissionDenied |
5 | 5 | from rest_framework import status
|
6 | 6 | from rest_framework.response import Response
|
7 | 7 | from crum import get_current_user
|
@@ -44,19 +44,21 @@ def __call__(self, request):
|
44 | 44 | return self.get_response(request)
|
45 | 45 |
|
46 | 46 | def process_request(self, request):
|
47 |
| - |
48 |
| - request.profile = None |
49 |
| - user_id = None |
50 |
| - # here I am getting the the jwt token passing in header |
51 |
| - if request.headers.get("Authorization"): |
52 |
| - token1 = request.headers.get("Authorization") |
53 |
| - token = token1.split(" ")[1] # getting the token value |
54 |
| - decoded = jwt.decode(token, (settings.SECRET_KEY), algorithms=[settings.JWT_ALGO]) |
55 |
| - user_id = decoded['user_id'] |
56 |
| - if user_id is not None: |
57 |
| - if request.headers.get("org"): |
58 |
| - profile = Profile.objects.get( |
59 |
| - user_id=user_id, org=request.headers.get("org"), is_active=True |
60 |
| - ) |
61 |
| - if profile: |
62 |
| - request.profile = profile |
| 47 | + try : |
| 48 | + request.profile = None |
| 49 | + user_id = None |
| 50 | + # here I am getting the the jwt token passing in header |
| 51 | + if request.headers.get("Authorization"): |
| 52 | + token1 = request.headers.get("Authorization") |
| 53 | + token = token1.split(" ")[1] # getting the token value |
| 54 | + decoded = jwt.decode(token, (settings.SECRET_KEY), algorithms=[settings.JWT_ALGO]) |
| 55 | + user_id = decoded['user_id'] |
| 56 | + if user_id is not None: |
| 57 | + if request.headers.get("org"): |
| 58 | + profile = Profile.objects.get( |
| 59 | + user_id=user_id, org=request.headers.get("org"), is_active=True |
| 60 | + ) |
| 61 | + if profile: |
| 62 | + request.profile = profile |
| 63 | + except : |
| 64 | + raise PermissionDenied() |
0 commit comments