def post(self, request, *args, **kwargs): form = AuthenticateAsForm(self.request.POST) if form.is_valid(): username = form.cleaned_data['username'] request.user = User.objects.get(username=username) # http://stackoverflow.com/a/2787747/835696 # This allows us to bypass the authenticate call request.user.backend = 'django.contrib.auth.backends.ModelBackend' login(request, request.user) return HttpResponseRedirect('/') return self.get(request, *args, **kwargs)
def post(self, request, *args, **kwargs): form = AuthenticateAsForm(self.request.POST) if form.is_valid(): request.user = User.objects.get(username=form.full_username) # http://stackoverflow.com/a/2787747/835696 # This allows us to bypass the authenticate call request.user.backend = 'django.contrib.auth.backends.ModelBackend' login(request, request.user) return HttpResponseRedirect('/') all_errors = form.errors.pop('__all__', None) if all_errors: messages.error(request, ','.join(all_errors)) if form.errors: messages.error(request, form.errors) return self.get(request, *args, **kwargs)
def page_context(self): return { 'hide_filters': True, 'form': AuthenticateAsForm(initial=self.request.POST), 'root_page_url': reverse('authenticate_as'), }
def page_context(self): return { 'hide_filters': True, 'form': AuthenticateAsForm(initial=self.kwargs) }