Advertisement
Guest User

Untitled

a guest
Jan 7th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.64 KB | None | 0 0
  1. def login_user(request):
  2.     if request.method == 'POST':
  3.         form = LoginForm(request.POST)
  4.         username = request.POST['username']
  5.         password = request.POST['password']
  6.  
  7.         user = authenticate(username=username, password=password)
  8.         if user is not None:
  9.             if user.is_active:
  10.                 login(request, user)
  11.  
  12.                 return redirect('home')
  13.     else:
  14.         form = LoginForm()
  15.  
  16.         if request.user.is_authenticated:
  17.             return redirect('profile')
  18.  
  19.     return render(request, 'registration/login.html', {'form': form})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement