Advertisement
Guest User

Untitled

a guest
Sep 15th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.76 KB | None | 0 0
  1. class DjangoAuthentication(Authentication):
  2.     def is_authenticated(self, request, **kwargs):
  3.         if request.user.is_authenticated():
  4.             return True
  5.         elif 'HTTP_AUTHORIZATION' in request.META:
  6.             import base64
  7.             auth = request.META['HTTP_AUTHORIZATION'].split()
  8.             if len(auth) == 2:
  9.                 if auth[0].lower() == "basic":
  10.                     uname, passwd = base64.b64decode(auth[1]).split(':')
  11.                     user = authenticate(username=uname, password=passwd)
  12.                     if user is not None:
  13.                         if user.is_active:
  14.                             login(request, user)
  15.                             request.user = user
  16.                             return True
  17.         return False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement