1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2008 Lincoln de Sousa <lincoln@minaslivre.org>
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License as
6 # published by the Free Software Foundation; either version 2 of the
7 # License, or (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # General Public License for more details.
14 # You should have received a copy of the GNU General Public
15 # License along with this program; if not, write to the
16 # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 # Boston, MA 02111-1307, USA.
18 from django.http import HttpResponseRedirect
19 from django.contrib import auth
20 from django.contrib.auth.forms import AuthenticationForm
23 """This is a function that will be used as a front-end to the
24 django's login system. It receives username and password fields
25 from a POST request and tries to login the user.
27 If login is successful, user will be redirected to the referer
28 address, otherwise will be redirected to /?login_failed.
31 manipulator = AuthenticationForm(request)
33 errors = manipulator.get_validation_errors(request.POST)
34 got_user = manipulator.get_user()
36 auth.login(request, got_user)
38 request.session.delete_test_cookie()
41 return HttpResponseRedirect('/')
43 return HttpResponseRedirect('/?login_failed')
45 request.session.set_test_cookie()
46 return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))
49 """Simple front-end to django's logout stuff. This function should
50 be mapped to an url and simply called without any parameter.
53 return HttpResponseRedirect('/login')