Skip to content

Instantly share code, notes, and snippets.

@Allwin12
Created July 24, 2020 05:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Allwin12/12121b7032f87ffd6a368fa706210be5 to your computer and use it in GitHub Desktop.
Save Allwin12/12121b7032f87ffd6a368fa706210be5 to your computer and use it in GitHub Desktop.
from rest_framework.response import Response
from rest_framework.views import APIView
class AuthTest(APIView):
def get(self, request):
try:
username = "User@123"
password = "htd61m12;!@"
auth_header = request.META.get('HTTP_AUTHORIZATION', '')
token_type, _, credentials = auth_header.partition(' ')
user, passw = base64.b64decode(credentials).decode().split(':')
if user == username and passw == password:
return Response({"success": "login successful!"}, status=200)
else:
return Response({"error": "unauthorised"}, status=401)
except Exception as e:
return Response({"error": "something went wrong!", status=400)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment