Skip to content

Instantly share code, notes, and snippets.

@Allwin12

Allwin12/views.py

Created Jul 24, 2020
Embed
What would you like to do?
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
You can’t perform that action at this time.