annotate gpp/accounts/views.py @ 6:b6263ac72052

Use DRY principle to manage third party javascript libraries. Created script_tags template tags to generate the correct link and script tags for 3rd party libraries. The settings.py file is the only place where the full path name is specified.
author Brian Neal <bgneal@gmail.com>
date Sat, 11 Apr 2009 22:50:56 +0000
parents dbd703f7d63a
children df56795771a6
rev   line source
gremmie@1 1 """views for the accounts application"""
gremmie@1 2
gremmie@1 3 import datetime
gremmie@1 4 from django.shortcuts import render_to_response
gremmie@1 5 from django.template import RequestContext
gremmie@1 6 from django.contrib import auth
gremmie@1 7 from django.http import HttpResponseRedirect
gremmie@1 8 from django.core.urlresolvers import reverse
bgneal@6 9 from django.conf import settings
gremmie@1 10
gremmie@1 11 from accounts.models import PendingUser
gremmie@1 12 from accounts.forms import RegisterForm
gremmie@1 13
gremmie@1 14
gremmie@1 15 #######################################################################
gremmie@1 16
gremmie@1 17 def register(request):
gremmie@1 18 if request.user.is_authenticated():
gremmie@1 19 return HttpResponseRedirect(settings.LOGIN_REDIRECT_URL)
gremmie@1 20
gremmie@1 21 if request.method == 'POST':
gremmie@1 22 form = RegisterForm(request.POST)
gremmie@1 23 if form.is_valid():
gremmie@1 24 form.save()
gremmie@1 25 return HttpResponseRedirect(reverse('accounts.views.register_thanks'))
gremmie@1 26 else:
gremmie@1 27 form = RegisterForm()
gremmie@1 28
gremmie@1 29 return render_to_response('accounts/register.html', {
gremmie@1 30 'form': form,
gremmie@1 31 },
gremmie@1 32 context_instance = RequestContext(request))
gremmie@1 33
gremmie@1 34 #######################################################################
gremmie@1 35
gremmie@1 36 def register_thanks(request):
gremmie@1 37 if request.user.is_authenticated():
gremmie@1 38 return HttpResponseRedirect(settings.LOGIN_REDIRECT_URL)
gremmie@1 39
gremmie@1 40 return render_to_response('accounts/register_thanks.html',
gremmie@1 41 context_instance = RequestContext(request))
gremmie@1 42
gremmie@1 43 #######################################################################
gremmie@1 44
gremmie@1 45 def register_confirm(request, username, key):
gremmie@1 46 if request.user.is_authenticated():
gremmie@1 47 return HttpResponseRedirect(settings.LOGIN_REDIRECT_URL)
gremmie@1 48
gremmie@1 49 # purge expired users
gremmie@1 50
gremmie@1 51 PendingUser.objects.purge_expired()
gremmie@1 52
gremmie@1 53 try:
gremmie@1 54 pending_user = PendingUser.objects.get(username = username)
gremmie@1 55 except PendingUser.DoesNotExist:
gremmie@1 56 return render_to_response('accounts/register_failure.html', {
gremmie@1 57 'username': username,
gremmie@1 58 },
gremmie@1 59 context_instance = RequestContext(request))
gremmie@1 60
gremmie@1 61 if pending_user.key != key:
gremmie@1 62 return render_to_response('accounts/register_failure.html', {
gremmie@1 63 'username': username,
gremmie@1 64 },
gremmie@1 65 context_instance = RequestContext(request))
gremmie@1 66
gremmie@1 67 new_user = auth.models.User()
gremmie@1 68
gremmie@1 69 new_user.username = pending_user.username
gremmie@1 70 new_user.first_name = ''
gremmie@1 71 new_user.last_name = ''
gremmie@1 72 new_user.email = pending_user.email
gremmie@1 73 new_user.password = pending_user.password # already been hashed
gremmie@1 74 new_user.is_staff = False
gremmie@1 75 new_user.is_active = True
gremmie@1 76 new_user.is_superuser = False
gremmie@1 77 new_user.last_login = datetime.datetime.now()
gremmie@1 78 new_user.date_joined = new_user.last_login
gremmie@1 79
gremmie@1 80 new_user.save()
gremmie@1 81 pending_user.delete()
gremmie@1 82
gremmie@1 83 return render_to_response('accounts/register_success.html', {
gremmie@1 84 'username': username,
gremmie@1 85 },
gremmie@1 86 context_instance = RequestContext(request))