summaryrefslogtreecommitdiffstats
path: root/apps/patchwork
diff options
context:
space:
mode:
authorJeremy Kerr <jk@ozlabs.org>2008-08-22 10:41:25 +0800
committerJeremy Kerr <jk@ozlabs.org>2008-08-22 10:41:25 +0800
commitf1e089f7736ac8f7b9af784461350c4c169211ad (patch)
treee45453e0d1fe5695b5227249040a668bff2610c1 /apps/patchwork
parent6a2a96299d4802cb4fb82891daf6f81ff33ba4e0 (diff)
downloadpatchwork-f1e089f7736ac8f7b9af784461350c4c169211ad.tar.bz2
patchwork-f1e089f7736ac8f7b9af784461350c4c169211ad.tar.xz
Use django-registration infrastructure
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Diffstat (limited to 'apps/patchwork')
-rw-r--r--apps/patchwork/forms.py69
-rw-r--r--apps/patchwork/models.py37
-rw-r--r--apps/patchwork/urls.py8
-rw-r--r--apps/patchwork/utils.py7
-rw-r--r--apps/patchwork/views/base.py4
-rw-r--r--apps/patchwork/views/patch.py4
-rw-r--r--apps/patchwork/views/user.py81
7 files changed, 41 insertions, 169 deletions
diff --git a/apps/patchwork/forms.py b/apps/patchwork/forms.py
index a758d46..7adc8c0 100644
--- a/apps/patchwork/forms.py
+++ b/apps/patchwork/forms.py
@@ -21,48 +21,33 @@
from django.contrib.auth.models import User
from django import forms
-from patchwork.models import RegistrationRequest, Patch, State, Bundle, \
- UserProfile
-
-class RegisterForm(forms.ModelForm):
- password = forms.CharField(widget = forms.PasswordInput)
- email = forms.EmailField(max_length = 200)
-
- class Meta:
- model = RegistrationRequest
- exclude = ['key', 'active', 'date']
-
- def clean_email(self):
- value = self.cleaned_data['email']
- try:
- User.objects.get(email = value)
- raise forms.ValidationError(('The email address %s has ' +
- 'has already been registered') % value)
- except User.DoesNotExist:
- pass
- try:
- RegistrationRequest.objects.get(email = value)
- raise forms.ValidationError(('The email address %s has ' +
- 'has already been registered') % value)
- except RegistrationRequest.DoesNotExist:
- pass
- return value
-
- def clean_username(self):
- value = self.cleaned_data['username']
- try:
- User.objects.get(username = value)
- raise forms.ValidationError(('The username %s has ' +
- 'has already been registered') % value)
- except User.DoesNotExist:
- pass
- try:
- RegistrationRequest.objects.get(username = value)
- raise forms.ValidationError(('The username %s has ' +
- 'has already been registered') % value)
- except RegistrationRequest.DoesNotExist:
- pass
- return value
+from patchwork.models import Patch, State, Bundle, UserProfile
+from registration.forms import RegistrationFormUniqueEmail
+from registration.models import RegistrationProfile
+
+class RegistrationForm(RegistrationFormUniqueEmail):
+ first_name = forms.CharField(max_length = 30, required = False)
+ last_name = forms.CharField(max_length = 30, required = False)
+ username = forms.CharField(max_length=30, label=u'Username')
+ email = forms.EmailField(max_length=100, label=u'Email address')
+ password = forms.CharField(widget=forms.PasswordInput(),
+ label='Password')
+ password1 = forms.BooleanField(required = False)
+ password2 = forms.BooleanField(required = False)
+
+ def save(self, profile_callback = None):
+ user = RegistrationProfile.objects.create_inactive_user( \
+ username = self.cleaned_data['username'],
+ password = self.cleaned_data['password'],
+ email = self.cleaned_data['email'],
+ profile_callback = profile_callback)
+ user.first_name = self.cleaned_data.get('first_name', '')
+ user.last_name = self.cleaned_data.get('last_name', '')
+ user.save()
+ return user
+
+ def clean(self):
+ return self.cleaned_data
class LoginForm(forms.Form):
username = forms.CharField(max_length = 30)
diff --git a/apps/patchwork/models.py b/apps/patchwork/models.py
index e3fc9c7..a40931a 100644
--- a/apps/patchwork/models.py
+++ b/apps/patchwork/models.py
@@ -129,43 +129,6 @@ def _confirm_key():
str += random.choice(allowedchars)
return str;
-class RegistrationRequest(models.Model):
- username = models.CharField(max_length = 30, unique = True)
- first_name = models.CharField(max_length = 50)
- last_name = models.CharField(max_length = 50)
- email = models.CharField(max_length = 200, unique = True)
- password = models.CharField(max_length = 200)
- key = models.CharField(max_length = 32, default = _confirm_key)
- date = models.DateTimeField(default=datetime.datetime.now)
- active = models.BooleanField(default = True)
-
- def create_user(self):
- if not self.active:
- return
- user = User.objects.create_user(self.username,
- self.email, self.password)
- user.first_name = self.first_name
- user.last_name = self.last_name
- user.save()
- profile = UserProfile(user = user)
- profile.save()
- self.active = False
- self.save()
-
- # link a person to this user. if none exists, create.
- person = None
- try:
- person = Person.objects.get(email = user.email)
- except Exception:
- pass
- if not person:
- person = Person(email = user.email)
-
- person.link_to_user(user)
- person.save()
-
- return user
-
class UserPersonConfirmation(models.Model):
user = models.ForeignKey(User)
email = models.CharField(max_length = 200)
diff --git a/apps/patchwork/urls.py b/apps/patchwork/urls.py
index 4a7ccb1..f475e74 100644
--- a/apps/patchwork/urls.py
+++ b/apps/patchwork/urls.py
@@ -30,14 +30,6 @@ urlpatterns = patterns('',
(r'^patch/(?P<patch_id>\d+)/raw/$', 'patchwork.views.patch.content'),
(r'^patch/(?P<patch_id>\d+)/mbox/$', 'patchwork.views.patch.mbox'),
- # registration process
- (r'^register/$', 'patchwork.views.user.register'),
- (r'^register/confirm/(?P<key>[^/]+)/$',
- 'patchwork.views.user.register_confirm'),
-
- (r'^login/$', 'patchwork.views.user.login'),
- (r'^logout/$', 'patchwork.views.user.logout'),
-
# logged-in user stuff
(r'^user/$', 'patchwork.views.user.profile'),
(r'^user/todo/$', 'patchwork.views.user.todo_lists'),
diff --git a/apps/patchwork/utils.py b/apps/patchwork/utils.py
index cecf512..dfe1c92 100644
--- a/apps/patchwork/utils.py
+++ b/apps/patchwork/utils.py
@@ -19,7 +19,7 @@
from patchwork.forms import MultiplePatchForm
-from patchwork.models import Bundle, Project, State
+from patchwork.models import Bundle, Project, State, UserProfile
from django.conf import settings
from django.shortcuts import render_to_response, get_object_or_404
@@ -191,3 +191,8 @@ def set_patches(user, project, action, data, patches, context):
context.add_message(str)
return (errors, form)
+
+def userprofile_register_callback(user):
+ profile = UserProfile(user = user)
+ profile.save()
+
diff --git a/apps/patchwork/views/base.py b/apps/patchwork/views/base.py
index 16fa5db..85014af 100644
--- a/apps/patchwork/views/base.py
+++ b/apps/patchwork/views/base.py
@@ -18,9 +18,9 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-from patchwork.models import Patch, Project, Person, RegistrationRequest
+from patchwork.models import Patch, Project, Person
from patchwork.filters import Filters
-from patchwork.forms import RegisterForm, LoginForm, PatchForm
+from patchwork.forms import LoginForm, PatchForm
from django.shortcuts import render_to_response, get_object_or_404
from django.http import HttpResponse, HttpResponseRedirect
from django.db import transaction
diff --git a/apps/patchwork/views/patch.py b/apps/patchwork/views/patch.py
index f20f25d..c0960c1 100644
--- a/apps/patchwork/views/patch.py
+++ b/apps/patchwork/views/patch.py
@@ -18,9 +18,9 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-from patchwork.models import Patch, Project, Person, RegistrationRequest, Bundle
+from patchwork.models import Patch, Project, Person, Bundle
from patchwork.filters import Filters
-from patchwork.forms import RegisterForm, LoginForm, PatchForm, MultiplePatchForm, CreateBundleForm
+from patchwork.forms import PatchForm, MultiplePatchForm, CreateBundleForm
from patchwork.utils import get_patch_ids, set_patches, Order
from patchwork.requestcontext import PatchworkRequestContext
from django.shortcuts import render_to_response, get_object_or_404
diff --git a/apps/patchwork/views/user.py b/apps/patchwork/views/user.py
index 0e14549..4a34414 100644
--- a/apps/patchwork/views/user.py
+++ b/apps/patchwork/views/user.py
@@ -23,10 +23,10 @@ from patchwork.requestcontext import PatchworkRequestContext
from django.shortcuts import render_to_response, get_object_or_404
from django.contrib import auth
from django.http import HttpResponse, HttpResponseRedirect
-from patchwork.models import Project, Patch, Bundle, Person, \
- RegistrationRequest, UserProfile, UserPersonConfirmation, State
-from patchwork.forms import RegisterForm, LoginForm, MultiplePatchForm, \
- UserProfileForm, UserPersonLinkForm
+from patchwork.models import Project, Patch, Bundle, Person, UserProfile, \
+ UserPersonConfirmation, State
+from patchwork.forms import MultiplePatchForm, UserProfileForm, \
+ UserPersonLinkForm
from patchwork.utils import Order, get_patch_ids
from patchwork.filters import DelegateFilter
from patchwork.paginator import Paginator
@@ -37,79 +37,6 @@ from django.conf import settings
from django.core.mail import send_mail
import django.core.urlresolvers
-def register(request):
- context = PatchworkRequestContext(request)
- template = 'patchwork/register.html'
-
- if request.method != 'POST':
- form = RegisterForm()
- context['form'] = form
- return render_to_response(template, context)
-
- reg_req = RegistrationRequest()
- form = RegisterForm(instance = reg_req, data = request.POST)
-
- if form.is_valid():
- form.save()
- try:
- context['request'] = reg_req
- send_mail('Patchwork account confirmation',
- render_to_string('patchwork/register.mail', context),
- settings.PATCHWORK_FROM_EMAIL,
- [form.cleaned_data['email']])
-
- except Exception, ex:
- context['request'] = None
- context['error'] = 'An error occurred during registration. ' + \
- 'Please try again later'
-
- context['form'] = form
-
- return render_to_response(template, context)
-
-def register_confirm(request, key):
- context = PatchworkRequestContext(request)
- req = get_object_or_404(RegistrationRequest, key = key)
- req.create_user()
- user = auth.authenticate(username = req.username, password = req.password)
- auth.login(request, user)
-
- return render_to_response('patchwork/register-confirm.html', context)
-
-def login(request):
- context = PatchworkRequestContext(request)
- template = 'patchwork/login.html'
- error = None
-
- if request.method == 'POST':
- form = LoginForm(request.POST)
- context['form'] = form
-
- if not form.is_valid():
- return render_to_response(template, context)
-
- data = form.cleaned_data
- user = auth.authenticate(username = data['username'],
- password = data['password'])
-
- if user is not None and user.is_active:
- auth.login(request, user)
- url = request.POST.get('next', None) or \
- django.core.urlresolvers.reverse( \
- 'patchwork.views.user.profile')
- return HttpResponseRedirect(url)
-
- context['error'] = 'Invalid username or password'
-
- else:
- context['form'] = LoginForm()
-
- return render_to_response(template, context)
-
-def logout(request):
- auth.logout(request)
- return render_to_response('patchwork/logout.html')
-
@login_required
def profile(request):
context = PatchworkRequestContext(request)