Created
July 24, 2020 05:15
-
-
Save Allwin12/12121b7032f87ffd6a368fa706210be5 to your computer and use it in GitHub Desktop.
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
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