adicionando logo svg do luquinhas =)
[cascardo/eventmanager.git] / decorators.py
1 """
2 Copyright (C) 2007 Lincoln de Sousa <lincoln@archlinux-br.org>
3 Copyright (C) 2007 Douglas Andrade <douglas@archlinux-br.org>
4
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.
9
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.
14
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.
19
20     * Lincoln de Sousa (22 Jul 2007) adding is_login_form here.
21 """
22 from django.contrib.auth.forms import AuthenticationForm
23 from django.contrib.auth import login
24 from django.http import HttpResponseRedirect
25
26 def is_login_form(d):
27     return 'submitting_login_form' in d
28
29 def enable_login_form(func):
30     def _login(request, *args, **kwargs):
31         errors = {}
32         manipulator = AuthenticationForm(request)
33         # hammer test to make sure that the *login* form is being sent
34         if request.POST and is_login_form(request.POST):
35             errors = manipulator.get_validation_errors(request.POST)
36             got_user = manipulator.get_user()
37             if got_user:
38                 login(request, got_user)
39                 try:
40                     request.session.delete_test_cookie()
41                 except KeyError:
42                     pass
43             else:
44                 # TODO: Notify the user that data sent is wrong.
45                 msg = _('User name and Password doesn\'t match')
46                 request.error_message = msg
47
48         request.session.set_test_cookie()
49         return func(request, *args, **kwargs)
50     return _login