Mercurial > public > sg101
comparison accounts/views.py @ 783:004b3a90de66
Update our code that expected LOGIN_REDIRECT_URL to be a url.
It is now a view name.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Tue, 13 May 2014 20:23:30 -0500 |
parents | 4a49d4ac319f |
children | be233ba7ca31 |
comparison
equal
deleted
inserted
replaced
782:9133b4626a4b | 783:004b3a90de66 |
---|---|
2 Views for the accounts application. | 2 Views for the accounts application. |
3 | 3 |
4 """ | 4 """ |
5 import logging | 5 import logging |
6 | 6 |
7 from django.shortcuts import render | 7 from django.shortcuts import render, redirect |
8 from django.http import HttpResponseRedirect | |
9 from django.core.urlresolvers import reverse | |
10 from django.conf import settings | 8 from django.conf import settings |
11 | 9 |
12 from accounts.models import PendingUser | 10 from accounts.models import PendingUser |
13 from accounts.forms import RegisterForm, ForgotUsernameForm | 11 from accounts.forms import RegisterForm, ForgotUsernameForm |
14 from accounts import create_new_user | 12 from accounts import create_new_user |
20 ####################################################################### | 18 ####################################################################### |
21 | 19 |
22 @log_auth_failures('Register') | 20 @log_auth_failures('Register') |
23 def register(request): | 21 def register(request): |
24 if request.user.is_authenticated(): | 22 if request.user.is_authenticated(): |
25 return HttpResponseRedirect(settings.LOGIN_REDIRECT_URL) | 23 return redirect(settings.LOGIN_REDIRECT_URL) |
26 | 24 |
27 if request.method == 'POST': | 25 if request.method == 'POST': |
28 form = RegisterForm(request.POST, ip=request.META.get('REMOTE_ADDR', '?')) | 26 form = RegisterForm(request.POST, ip=request.META.get('REMOTE_ADDR', '?')) |
29 if form.is_valid(): | 27 if form.is_valid(): |
30 form.save() | 28 form.save() |
31 return HttpResponseRedirect(reverse('accounts.views.register_thanks')) | 29 return redirect('accounts.views.register_thanks') |
32 else: | 30 else: |
33 form = RegisterForm() | 31 form = RegisterForm() |
34 | 32 |
35 return render(request, 'accounts/register.html', {'form': form}) | 33 return render(request, 'accounts/register.html', {'form': form}) |
36 | 34 |
37 ####################################################################### | 35 ####################################################################### |
38 | 36 |
39 def register_thanks(request): | 37 def register_thanks(request): |
40 if request.user.is_authenticated(): | 38 if request.user.is_authenticated(): |
41 return HttpResponseRedirect(settings.LOGIN_REDIRECT_URL) | 39 return redirect(settings.LOGIN_REDIRECT_URL) |
42 | 40 |
43 return render(request, 'accounts/register_thanks.html') | 41 return render(request, 'accounts/register_thanks.html') |
44 | 42 |
45 ####################################################################### | 43 ####################################################################### |
46 | 44 |
47 def register_confirm(request, username, key): | 45 def register_confirm(request, username, key): |
48 if request.user.is_authenticated(): | 46 if request.user.is_authenticated(): |
49 return HttpResponseRedirect(settings.LOGIN_REDIRECT_URL) | 47 return redirect(settings.LOGIN_REDIRECT_URL) |
50 | 48 |
51 # purge expired users | 49 # purge expired users |
52 | 50 |
53 PendingUser.objects.purge_expired() | 51 PendingUser.objects.purge_expired() |
54 | 52 |
76 ####################################################################### | 74 ####################################################################### |
77 | 75 |
78 def username_query(request): | 76 def username_query(request): |
79 """This view handles forgotten username queries.""" | 77 """This view handles forgotten username queries.""" |
80 if request.user.is_authenticated(): | 78 if request.user.is_authenticated(): |
81 return HttpResponseRedirect(settings.LOGIN_REDIRECT_URL) | 79 return redirect(settings.LOGIN_REDIRECT_URL) |
82 | 80 |
83 if request.method == 'POST': | 81 if request.method == 'POST': |
84 form = ForgotUsernameForm(data=request.POST) | 82 form = ForgotUsernameForm(data=request.POST) |
85 if form.is_valid(): | 83 if form.is_valid(): |
86 form.save() | 84 form.save() |
87 return HttpResponseRedirect(reverse('accounts-username_sent')) | 85 return redirect('accounts-username_sent') |
88 else: | 86 else: |
89 form = ForgotUsernameForm() | 87 form = ForgotUsernameForm() |
90 | 88 |
91 return render(request, 'accounts/username_query.html', {'form': form}) | 89 return render(request, 'accounts/username_query.html', {'form': form}) |