comparison accounts/views.py @ 909:90632d090bbc

Merge with upstream.
author Brian Neal <bgneal@gmail.com>
date Mon, 16 Mar 2015 21:03:37 -0500
parents be233ba7ca31
children 6dd1f0065859
comparison
equal deleted inserted replaced
902:4dee923a2f6d 909:90632d090bbc
1 """ 1 """
2 Views for the accounts application. 2 Views for the accounts application.
3 3
4 """ 4 """
5 import json
5 import logging 6 import logging
6 7
8 from django.http import HttpResponse
7 from django.shortcuts import render, redirect 9 from django.shortcuts import render, redirect
8 from django.conf import settings 10 from django.conf import settings
9 11
10 from accounts.models import PendingUser 12 from accounts.models import PendingUser
11 from accounts.forms import RegisterForm, ForgotUsernameForm 13 from accounts.forms import RegisterForm
14 from accounts.forms import RegisterCodeForm
15 from accounts.forms import ForgotUsernameForm
12 from accounts import create_new_user 16 from accounts import create_new_user
13 from antispam.decorators import log_auth_failures 17 from antispam.decorators import log_auth_failures
14 18
15 19
16 logger = logging.getLogger('auth') 20 logger = logging.getLogger('auth')
23 return redirect(settings.LOGIN_REDIRECT_URL) 27 return redirect(settings.LOGIN_REDIRECT_URL)
24 28
25 if request.method == 'POST': 29 if request.method == 'POST':
26 form = RegisterForm(request.POST, ip=request.META.get('REMOTE_ADDR', '?')) 30 form = RegisterForm(request.POST, ip=request.META.get('REMOTE_ADDR', '?'))
27 if form.is_valid(): 31 if form.is_valid():
28 form.save() 32 form.save(request)
29 return redirect('accounts.views.register_thanks') 33 return redirect('accounts-register1')
30 else: 34 else:
31 form = RegisterForm() 35 form = RegisterForm()
32 36
33 return render(request, 'accounts/register.html', {'form': form}) 37 return render(request, 'accounts/register.html', {'form': form})
38
39 #######################################################################
40
41 def register1(request):
42 """Displays the registration code."""
43 if request.user.is_authenticated():
44 return redirect(settings.LOGIN_REDIRECT_URL)
45
46 return render(request, 'accounts/register1.html')
47
48 #######################################################################
49
50 @log_auth_failures('Register')
51 def register2(request):
52 """Processes the registration code and creates the user."""
53 if request.user.is_authenticated():
54 return redirect(settings.LOGIN_REDIRECT_URL)
55
56 if request.method == 'POST':
57 form = RegisterCodeForm(request.POST,
58 session=request.session,
59 ip=request.META.get('REMOTE_ADDR', '?'))
60 if form.is_valid():
61 form.save()
62 return redirect('accounts-register_thanks')
63 else:
64 form = RegisterCodeForm()
65
66 return render(request, 'accounts/register2.html', {'form': form})
67
68 #######################################################################
69
70 def get_code(request):
71 code = {'code': 'FAIL-123'}
72 reg_info = request.session.get('reg_info')
73 if reg_info:
74 code['code'] = reg_info.get('code', code['code'])
75
76 return HttpResponse(json.dumps(code), content_type='application/json')
34 77
35 ####################################################################### 78 #######################################################################
36 79
37 def register_thanks(request): 80 def register_thanks(request):
38 if request.user.is_authenticated(): 81 if request.user.is_authenticated():