Mercurial > public > sg101
comparison gpp/accounts/views.py @ 1:dbd703f7d63a
Initial import of sg101 stuff from private repository.
author | gremmie |
---|---|
date | Mon, 06 Apr 2009 02:43:12 +0000 |
parents | |
children | b6263ac72052 |
comparison
equal
deleted
inserted
replaced
0:900ba3c7b765 | 1:dbd703f7d63a |
---|---|
1 """views for the accounts application""" | |
2 | |
3 import datetime | |
4 import settings | |
5 from django.shortcuts import render_to_response | |
6 from django.template import RequestContext | |
7 from django.contrib import auth | |
8 from django.http import HttpResponseRedirect | |
9 from django.core.urlresolvers import reverse | |
10 | |
11 from accounts.models import PendingUser | |
12 from accounts.forms import RegisterForm | |
13 | |
14 | |
15 ####################################################################### | |
16 | |
17 def register(request): | |
18 if request.user.is_authenticated(): | |
19 return HttpResponseRedirect(settings.LOGIN_REDIRECT_URL) | |
20 | |
21 if request.method == 'POST': | |
22 form = RegisterForm(request.POST) | |
23 if form.is_valid(): | |
24 form.save() | |
25 return HttpResponseRedirect(reverse('accounts.views.register_thanks')) | |
26 else: | |
27 form = RegisterForm() | |
28 | |
29 return render_to_response('accounts/register.html', { | |
30 'form': form, | |
31 }, | |
32 context_instance = RequestContext(request)) | |
33 | |
34 ####################################################################### | |
35 | |
36 def register_thanks(request): | |
37 if request.user.is_authenticated(): | |
38 return HttpResponseRedirect(settings.LOGIN_REDIRECT_URL) | |
39 | |
40 return render_to_response('accounts/register_thanks.html', | |
41 context_instance = RequestContext(request)) | |
42 | |
43 ####################################################################### | |
44 | |
45 def register_confirm(request, username, key): | |
46 if request.user.is_authenticated(): | |
47 return HttpResponseRedirect(settings.LOGIN_REDIRECT_URL) | |
48 | |
49 # purge expired users | |
50 | |
51 PendingUser.objects.purge_expired() | |
52 | |
53 try: | |
54 pending_user = PendingUser.objects.get(username = username) | |
55 except PendingUser.DoesNotExist: | |
56 return render_to_response('accounts/register_failure.html', { | |
57 'username': username, | |
58 }, | |
59 context_instance = RequestContext(request)) | |
60 | |
61 if pending_user.key != key: | |
62 return render_to_response('accounts/register_failure.html', { | |
63 'username': username, | |
64 }, | |
65 context_instance = RequestContext(request)) | |
66 | |
67 new_user = auth.models.User() | |
68 | |
69 new_user.username = pending_user.username | |
70 new_user.first_name = '' | |
71 new_user.last_name = '' | |
72 new_user.email = pending_user.email | |
73 new_user.password = pending_user.password # already been hashed | |
74 new_user.is_staff = False | |
75 new_user.is_active = True | |
76 new_user.is_superuser = False | |
77 new_user.last_login = datetime.datetime.now() | |
78 new_user.date_joined = new_user.last_login | |
79 | |
80 new_user.save() | |
81 pending_user.delete() | |
82 | |
83 return render_to_response('accounts/register_success.html', { | |
84 'username': username, | |
85 }, | |
86 context_instance = RequestContext(request)) |