source: mauRepo/dj_security/trunk/dj_security/views/my_profile.py @ 8665

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/mauRepo/dj_security/trunk/dj_security/views/my_profile.py@8665
Revision 8665, 1.4 KB checked in by mnagni, 7 years ago (diff)

Small refactoring and fix the name of context_processor module

  • Property svn:mime-type set to text/plain
Line 
1'''
2Created on 29 Oct 2012
3
4@author: mnagni
5'''
6from dj_security.views.my_view import errorHandle
7from dj_security.models import UserProfile
8from django.shortcuts import render_to_response
9from paste.auth.auth_tkt import BadTicket
10from paste.auth import auth_tkt
11from django.conf import settings
12
13def get_user_profile(request):
14    # this creates user profile and attaches it to an user
15    # if one is not found already
16    try:
17        user_profile = request.user.get_profile()
18    except:
19        user_profile = UserProfile(user=request.user)
20        user_profile.save()
21
22    return user_profile
23
24# route from your urls.py to this view function! rename if needed
25def frontpage(request):
26    context = {}
27    if request.COOKIES.has_key('auth_tkt'):
28        try: 
29            timestamp, userid, tokens, user_data = \
30                auth_tkt.parse_ticket(
31                        getattr(settings, 'SHARED_SECRET', 'sharedsecret'),
32                        request.COOKIES['auth_tkt'],
33                        request.META['REMOTE_ADDR'])
34
35            context['timestamp'] = timestamp
36            context['username'] = userid
37            context['tokens'] = tokens                       
38            context['user_data'] = user_data
39            return render_to_response('logged_in.html', context)
40        except BadTicket:
41            pass
42       
43    return errorHandle(request, context)
Note: See TracBrowser for help on using the repository browser.