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 myslice.viewutils import topmenu_items, the_user
9 from myslice.config import Config
11 def login_user(request):
12 state = "Please log in below..."
13 username = password = ''
15 'manifold_url':Config.manifold_url,
19 username = request.POST.get('username')
20 password = request.POST.get('password')
22 # pass request within the token, so manifold session key could be attached to the request session.
23 token = {'username': username, 'password': password, 'request': request}
25 user = authenticate(token=token)
29 #state = "You're successfully logged in!"
30 return HttpResponseRedirect ('/portal/dashboard')
31 #return HttpResponseRedirect ('/login-ok')
33 env['state'] = "Your account is not active, please contact the site admin."
34 return render_to_response('view-login.html',env, context_instance=RequestContext(request))
36 env['state'] = "Your username and/or password were incorrect."
37 return render_to_response('view-login.html',env, context_instance=RequestContext(request))
39 state='' #Welcome to MySlice'
41 env['username']=the_user(request)
42 env['topmenu_items'] = topmenu_items('', 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 ('/')