def login(request): error = '' redirect_to = settings.LOGIN_REDIRECT_URL if 'next' in request.REQUEST: redirect_to = request.REQUEST['next'] if request.POST: form = LoginForm(request.POST) if form.is_valid(): username = form.cleaned_data['username'] password = form.cleaned_data['password'] from django.contrib.auth import login, authenticate user = authenticate(username=username, password=password) if user is not None: if user.is_active: login(request, user) return HttpResponseRedirect(redirect_to) else: error = 'User account is locked' else: error = 'Username or passord was incorrect' else: form = LoginForm() return render_to_response('registration/login.html', { 'form': form, 'next': redirect_to, 'error': error, }, context_instance=RequestContext(request))
def login(request, username=None): error = '' redirect_to = reverse('index') if 'next' in request.REQUEST: redirect_to = request.REQUEST['next'] if request.POST: form = LoginForm(request.POST) if form.is_valid(): username = form.cleaned_data['username'] password = form.cleaned_data['password'] from django.contrib.auth import login person = Person.objects.authenticate(username=username, password=password) if person is not None: if person.is_active and not person.is_locked(): login(request, person.user) return HttpResponseRedirect(redirect_to) else: error = 'User account is inactive or locked' else: error = 'Username or password was incorrect' else: form = LoginForm(initial = {'username': username}) return render_to_response('people/login.html', { 'form': form, 'next': redirect_to, 'error': error, }, context_instance=RequestContext(request))