1 # Create your views here.
2 from django.core.context_processors import csrf
3 from django.template import RequestContext
4 from django.shortcuts import render_to_response
5 from django.contrib.auth import authenticate, login, logout
6 from django.http import HttpResponseRedirect
8 from auth.backend import MyCustomBackend
10 from myslice.viewutils import the_user
11 from myslice.config import Config
13 def login_user(request):
14 state = "Please log in below..."
15 username = password = ''
16 env={'hard_wired_users':MyCustomBackend.hard_wired_users,
17 'manifold_url':Config.manifold_url,
21 username = request.POST.get('username')
22 password = request.POST.get('password')
24 # pass request within the token, so manifold session key could be attached to the request session.
25 token = {'username': username, 'password': password, 'request': request}
27 user = authenticate(token=token)
31 #state = "You're successfully logged in!"
32 return HttpResponseRedirect ('/login-ok')
34 env['state'] = "Your account is not active, please contact the site admin."
35 return render_to_response('view-login.html',env, context_instance=RequestContext(request))
37 env['state'] = "Your username and/or password were incorrect."
38 return render_to_response('view-login.html',env, context_instance=RequestContext(request))
40 state='Welcome to MySlice'
42 env['username']=the_user(request)
43 return render_to_response('view-login.html',env, context_instance=RequestContext(request))
45 # hard question : where should we redirect requests to logout if user is not logged in ?
46 def logout_user (request):
47 # check that we're indeed logged in
48 if not request.user.is_authenticated():
49 return HttpResponseRedirect ('/')
51 return HttpResponseRedirect ('/')