annotate gpp/accounts/views.py @ 431:0d91176cf9b3

More work on #211. The compose view now returns the tab fragment HTML so errors can be displayed correctly.
author Brian Neal <bgneal@gmail.com>
date Fri, 06 May 2011 00:02:55 +0000
parents 69d0306a6fe7
children 7c3816d76c6c
rev   line source
gremmie@1 1 """views for the accounts application"""
gremmie@1 2
gremmie@1 3 import datetime
bgneal@74 4 import logging
bgneal@74 5
gremmie@1 6 from django.shortcuts import render_to_response
gremmie@1 7 from django.template import RequestContext
bgneal@259 8 from django.contrib.auth.models import User
gremmie@1 9 from django.http import HttpResponseRedirect
gremmie@1 10 from django.core.urlresolvers import reverse
bgneal@6 11 from django.conf import settings
gremmie@1 12
gremmie@1 13 from accounts.models import PendingUser
gremmie@1 14 from accounts.forms import RegisterForm
bgneal@347 15 from accounts import create_new_user
gremmie@1 16
gremmie@1 17
gremmie@1 18 #######################################################################
gremmie@1 19
gremmie@1 20 def register(request):
bgneal@74 21 if request.user.is_authenticated():
bgneal@74 22 return HttpResponseRedirect(settings.LOGIN_REDIRECT_URL)
gremmie@1 23
bgneal@74 24 if request.method == 'POST':
bgneal@74 25 form = RegisterForm(request.POST, ip=request.META.get('REMOTE_ADDR', '?'))
bgneal@74 26 if form.is_valid():
bgneal@74 27 form.save()
bgneal@74 28 return HttpResponseRedirect(reverse('accounts.views.register_thanks'))
bgneal@74 29 else:
bgneal@74 30 form = RegisterForm()
gremmie@1 31
bgneal@74 32 return render_to_response('accounts/register.html', {
bgneal@74 33 'form': form,
bgneal@74 34 },
bgneal@74 35 context_instance = RequestContext(request))
gremmie@1 36
gremmie@1 37 #######################################################################
gremmie@1 38
gremmie@1 39 def register_thanks(request):
bgneal@74 40 if request.user.is_authenticated():
bgneal@74 41 return HttpResponseRedirect(settings.LOGIN_REDIRECT_URL)
gremmie@1 42
bgneal@74 43 return render_to_response('accounts/register_thanks.html',
bgneal@74 44 context_instance = RequestContext(request))
gremmie@1 45
gremmie@1 46 #######################################################################
gremmie@1 47
gremmie@1 48 def register_confirm(request, username, key):
bgneal@74 49 if request.user.is_authenticated():
bgneal@74 50 return HttpResponseRedirect(settings.LOGIN_REDIRECT_URL)
bgneal@316 51
bgneal@74 52 # purge expired users
gremmie@1 53
bgneal@74 54 PendingUser.objects.purge_expired()
gremmie@1 55
bgneal@74 56 ip = request.META.get('REMOTE_ADDR', '?')
bgneal@74 57 try:
bgneal@74 58 pending_user = PendingUser.objects.get(username = username)
bgneal@74 59 except PendingUser.DoesNotExist:
bgneal@316 60 logging.error('Accounts register_confirm [%s]: user does not exist: %s', ip, username)
bgneal@74 61 return render_to_response('accounts/register_failure.html', {
bgneal@74 62 'username': username,
bgneal@74 63 },
bgneal@74 64 context_instance = RequestContext(request))
gremmie@1 65
bgneal@74 66 if pending_user.key != key:
bgneal@316 67 logging.error('Accounts register_confirm [%s]: key error: %s', ip, username)
bgneal@74 68 return render_to_response('accounts/register_failure.html', {
bgneal@74 69 'username': username,
bgneal@74 70 },
bgneal@74 71 context_instance = RequestContext(request))
gremmie@1 72
bgneal@347 73 create_new_user(pending_user, ip)
gremmie@1 74
bgneal@74 75 return render_to_response('accounts/register_success.html', {
bgneal@74 76 'username': username,
bgneal@74 77 },
bgneal@74 78 context_instance = RequestContext(request))