add tracing info in googlemaps plugin
[myslice.git] / portal / homeview.py
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
8
9 from myslice.viewutils import topmenu_items, the_user
10 from myslice.config import Config
11
12 class HomeView (View):
13
14     def default_env (self):
15         return { 
16                  'manifold_url':Config.manifold_url,
17                  }
18
19     def post (self,request):
20         env = self.default_env()
21         username = request.POST.get('username')
22         password = request.POST.get('password')
23         
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}    
26
27         user = authenticate(token=token)
28         if user is not None:
29             if user.is_active:
30                 print "LOGGING IN"
31                 login(request, user)
32                 return HttpResponseRedirect ('/login-ok')
33             else:
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))
36         else:
37             env['state'] = "Your username and/or password were incorrect."
38             return render_to_response('home-view.html',env, context_instance=RequestContext(request))
39
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))
48