Première version : mise en route du suivi.
[auf_roa_authentification_backend.git] / exemple-client / client / views.py
1 from django.http import HttpResponseRedirect
2 from django.contrib.auth.decorators import login_required
3 from django.contrib.auth import authenticate, login
4 from django.contrib.auth.views import logout
5 from django.shortcuts import render_to_response
6 from django.template import Context, RequestContext
7
8 @login_required
9 def index (request):
10 return render_to_response ("index.html", \
11 Context ({"user": request.user}), \
12 context_instance = RequestContext(request))
13
14 def login_view (request):
15 error = None
16
17 # Identification envoyee
18 if request.method == "POST":
19 try:
20 username = request.POST['email']
21 password = request.POST['pass']
22 except:
23 error = ""
24
25 user = authenticate (username=username, password=password)
26 if user is not None:
27 login(request, user)
28 return HttpResponseRedirect (request.GET['next'])
29 else:
30 error = "Compte invalide."
31
32 return render_to_response ("login.html", \
33 Context ({"error": error}), \
34 context_instance = RequestContext(request))
35
36 def logout_view (request):
37 return logout (request, "/")