Last active
September 24, 2021 09:42
-
-
Save yeazin/9f51314fcdb23c5908bb4a34af5d40d8 to your computer and use it in GitHub Desktop.
Django REST Framework Custom Decorators
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Resources | |
Simple JWT Token bearer authentication : https://gist.github.com/ridvanaltun/6e3a7513519f998bd3f770c117e18f07 | |
custom Decorators : https://docs.djangoproject.com/en/2.2/topics/class-based-views/intro/#decorating-the-class | |
''' | |
from django.http import response | |
from functools import wraps | |
## is authenticated | |
def IsLogin(func): | |
@wraps(func) | |
def wrapper(request,*args,**kwargs): | |
''' | |
Checking the auth if user has bearer token or not | |
''' | |
if not 'Authorization' in request.headers: | |
return response.JsonResponse({'Error':'Sorry Your Not loged IN'}) | |
else: | |
return func(request,*args,**kwargs) | |
return wrapper |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Do you have any Query?
join me then
Linkedin : yeazin
facebook : yeazin
email : naz.yeasin@gmail.com