Mercurial > agora
comparison views.py @ 160:a5547f079190
Fix bug in registration
django-registration's RegistrationForm isn't a ModelForm, it's just a
Form, so there's no save method. Have to create the account manually.
author | dellsystem <ilostwaldo@gmail.com> |
---|---|
date | Mon, 15 Oct 2012 02:24:01 -0400 |
parents | c7be7def8b57 |
children | c494e6ecff58 |
comparison
equal
deleted
inserted
replaced
159:aa9a594334c7 | 160:a5547f079190 |
---|---|
1 from django.contrib.auth import login, authenticate | 1 from django.contrib.auth import login, authenticate |
2 from django.contrib.auth.models import User | |
2 from django.contrib.auth.forms import AuthenticationForm | 3 from django.contrib.auth.forms import AuthenticationForm |
3 from django.shortcuts import render, redirect | 4 from django.shortcuts import render, redirect |
4 from django.core.urlresolvers import reverse | 5 from django.core.urlresolvers import reverse |
5 from registration.forms import RegistrationForm | 6 from registration.forms import RegistrationForm |
6 | 7 |
43 } | 44 } |
44 elif action == 'register': | 45 elif action == 'register': |
45 form = RegistrationForm(request.POST) | 46 form = RegistrationForm(request.POST) |
46 | 47 |
47 if form.is_valid(): | 48 if form.is_valid(): |
48 user = form.save() | 49 username = form.cleaned_data['username'] |
50 email = form.cleaned_data['email'] | |
51 password = form.cleaned_data['password1'] | |
52 | |
53 User.objects.create_user(username, email, password) | |
54 user = authenticate(username=username, password=password) | |
49 login(request, user) | 55 login(request, user) |
50 return redirect(next_url) | 56 return redirect(next_url) |
51 else: | 57 else: |
52 # The action is not set. Malicious submission? | 58 # The action is not set. Malicious submission? |
53 pass | 59 pass |