daily pastebin goal
63%
SHARE
TWEET

Untitled

a guest Dec 10th, 2018 106 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. AUTHENTICATION_BACKENDS = [
  2.  
  3.     'auth.auth_backend.UserAuthentication',
  4. ]
  5.    
  6. def login_user(request):
  7.     username = request.POST['username']
  8.     password = request.POST['password']
  9.     print(username,password)
  10.     user = authenticate(request, username=username,
  11.     password=password)
  12.     print(user)
  13.     if user is not None:
  14.         print('User not none')
  15.         login(request, user)
  16.         print('Login successful')
  17.         return redirect(request.POST['next'] or '/')
  18.     else:
  19.         print('Login failed')
  20.         return redirect('/login?error=auth')
  21.  
  22.  
  23. def login_view(request):
  24.     if request.method == "POST":
  25.         return login_user(request)
  26.     else:
  27.         return render(request, 'Profile/login.html')
  28.    
  29. class UserAuthentication:
  30.  
  31.     def authenticate(self, request, username=None,
  32.     password=None, domain="domain"):
  33.         # TODO add error handling when uid and or pwd is not
  34.     passed
  35.         # Check the username/password and return a user. If
  36. not valid, it should return None.
  37.         user = domain + username
  38.         server = Server('server', get_info=ALL)
  39.         conn = Connection(server, user=user,
  40. password=password, authentication=NTLM)
  41.         valid_user = conn.bind()
  42.         if valid_user:
  43.             try:
  44.                 user = User.objects.get(username=username)
  45.                 if settings.DEBUG:
  46.                     print("YouRockAuth.authenticate: found
  47.  user %s" % user.username)
  48.             except User.DoesNotExist:
  49.                pass
  50.         else:
  51.             user = None
  52.         return user
  53.  
  54.     def get_user(self, user_id):
  55.  
  56.         try:
  57.             user = User.objects.get(pk=user_id)
  58.             return user
  59.         except User.DoesNotExist:
  60.             return None
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top