""" Copyright (C) 2007 Lincoln de Sousa Copyright (C) 2007 Douglas Andrade This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Lincoln de Sousa (22 Jul 2007) adding is_login_form here. """ from django.contrib.auth.forms import AuthenticationForm from django.contrib.auth import login from django.http import HttpResponseRedirect def is_login_form(d): return 'submitting_login_form' in d def enable_login_form(func): def _login(request, *args, **kwargs): errors = {} manipulator = AuthenticationForm(request) # hammer test to make sure that the *login* form is being sent if request.POST and is_login_form(request.POST): errors = manipulator.get_validation_errors(request.POST) got_user = manipulator.get_user() if got_user: login(request, got_user) try: request.session.delete_test_cookie() except KeyError: pass else: # TODO: Notify the user that data sent is wrong. msg = _('User name and Password doesn\'t match') request.error_message = msg request.session.set_test_cookie() return func(request, *args, **kwargs) return _login