1 # this somehow is not used anymore - should it not be ?
2 from django.views.generic import View
3 from django.core.context_processors import csrf
4 from django.http import HttpResponseRedirect
5 from django.contrib.auth import authenticate, login, logout
6 from django.template import RequestContext
7 from django.shortcuts import render_to_response
9 from myslice.viewutils import topmenu_items, the_user
10 from myslice.config import Config
12 class HomeView (View):
14 def default_env (self):
16 'manifold_url':Config.manifold_url,
19 def post (self,request):
20 env = self.default_env()
21 username = request.POST.get('username')
22 password = request.POST.get('password')
24 # pass request within the token, so manifold session key can be attached to the request session.
25 token = {'username': username, 'password': password, 'request': request}
27 user = authenticate(token=token)
32 return HttpResponseRedirect ('/login-ok')
34 env['state'] = "Your account is not active, please contact the site admin."
35 return render_to_response('home-view.html',env, context_instance=RequestContext(request))
37 env['state'] = "Your username and/or password were incorrect."
38 return render_to_response('home-view.html',env, context_instance=RequestContext(request))
40 # login-ok sets state="Welcome to MySlice" in urls.py
41 def get (self, request, state=None):
42 env = self.default_env()
43 env['username']=the_user(request)
44 env['topmenu_items'] = topmenu_items('', request)
45 if state: env['state'] = state
46 elif not env['username']: env['state'] = "Please sign in"
47 return render_to_response('home-view.html',env, context_instance=RequestContext(request))