2 Copyright (C) 2007 Lincoln de Sousa <lincoln@archlinux-br.org>
3 Copyright (C) 2007 Douglas Andrade <douglas@archlinux-br.org>
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public
16 License along with this program; if not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * Lincoln de Sousa (22 Jul 2007) adding is_login_form here.
25 from django.contrib.auth.forms import AuthenticationForm
26 from django.contrib.auth import login
27 from django.http import HttpResponseRedirect
30 return 'submitting_login_form' in d
32 def enable_login_form(func):
33 def _login(request, *args, **kwargs):
35 manipulator = AuthenticationForm(request)
36 # hammer test to make sure that the *login* form is being sent
37 if request.POST and is_login_form(request.POST):
38 errors = manipulator.get_validation_errors(request.POST)
39 got_user = manipulator.get_user()
41 login(request, got_user)
43 request.session.delete_test_cookie()
46 return HttpResponseRedirect('/')
48 return HttpResponseRedirect('/?login_failed')
50 request.session.set_test_cookie()
51 return func(request, *args, **kwargs)