Commit eb6db921 authored by Jeremy Kerr's avatar Jeremy Kerr
Browse files

Implement confirmation emails.



To do this, we need to allow sucessive requests for the same
confirmation URL.
Signed-off-by: default avatarJeremy Kerr <jk@ozlabs.org>
parent ecea8781
......@@ -30,7 +30,7 @@ class RegisterForm(forms.ModelForm):
class Meta:
model = RegistrationRequest
exclude = ['key']
exclude = ['key', 'active', 'date']
def clean_email(self):
value = self.cleaned_data['email']
......
......@@ -145,8 +145,12 @@ class RegistrationRequest(models.Model):
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
......@@ -154,7 +158,8 @@ class RegistrationRequest(models.Model):
user.save()
profile = UserProfile(user = user)
profile.save()
self.delete()
self.active = False
self.save()
# link a person to this user. if none exists, create.
person = None
......@@ -176,10 +181,13 @@ class RegistrationRequest(models.Model):
class UserPersonConfirmation(models.Model):
user = models.ForeignKey(User)
email = models.CharField(max_length = 200)
date = models.DateTimeField(default=datetime.datetime.now)
key = models.CharField(max_length = 32, default = _confirm_key)
date = models.DateTimeField(default=datetime.datetime.now)
active = models.BooleanField(default = True)
def confirm(self):
if not self.active:
return
person = None
try:
person = Person.objects.get(email = self.email)
......@@ -190,6 +198,7 @@ class UserPersonConfirmation(models.Model):
person.link_to_user(self.user)
person.save()
self.active = False
class Admin:
......
......@@ -19,6 +19,7 @@
from django.template import RequestContext
from django.utils.html import escape
from django.contrib.sites.models import Site
from patchwork.filters import Filters
from patchwork.models import Bundle, Project
......@@ -65,6 +66,7 @@ class PatchworkRequestContext(RequestContext):
self.update({
'project': self.project,
'site': Site.objects.get_current(),
'other_projects': len(self.projects) > 1
})
......
......@@ -31,6 +31,10 @@ from patchwork.utils import Order, get_patch_ids, set_patches
from patchwork.filters import DelegateFilter
from patchwork.paginator import Paginator
from patchwork.views import generic_list
from django.template.loader import render_to_string
from django.template import Context
from django.conf import settings
from django.core.mail import send_mail
import django.core.urlresolvers
def register(request):
......@@ -47,9 +51,19 @@ def register(request):
if form.is_valid():
form.save()
context['request'] = reg_req
else:
context['form'] = form
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)
......@@ -128,9 +142,19 @@ def link(request):
if form.is_valid():
conf = UserPersonConfirmation(user = request.user,
email = form.cleaned_data['email'])
conf.save()
context['confirmation'] = conf
try:
send_mail('Patchwork email address confirmation',
render_to_string('patchwork/user-link.mail',
context),
settings.PATCHWORK_FROM_EMAIL,
[form.cleaned_data['email']])
conf.save()
except Exception, ex:
context['confirmation'] = None
context['error'] = 'An error occurred during confirmation. ' + \
'Please try again later'
context['linkform'] = form
return render_to_response('patchwork/user-link.html', context)
......@@ -146,8 +170,6 @@ def link_confirm(request, key):
else:
context['person'] = Person.objects.get(email = confirmation.email)
confirmation.delete()
return render_to_response('patchwork/user-link-confirm.html', context)
@login_required
......
......@@ -92,3 +92,4 @@ INSTALLED_APPS = (
)
DEFAULT_PATCHES_PER_PAGE = 100
PATCHWORK_FROM_EMAIL = 'Patchwork <patchwork@patchwork.example.com>'
......@@ -6,13 +6,12 @@
{% block body %}
{% if request %}
{% if request and not error %}
<p>Registration successful!</p>
<p>email sent to {{ request.email }}</p>
<p>Beta note: While we're testing, the confirmation email has been replaced
by a single link:
<a href="{% url patchwork.views.user.register_confirm key=request.key %}"
>{% url patchwork.views.user.register_confirm key=request.key %}</a>
<p>A confirmation email has been sent to {{ request.email }}. You'll
need to visit the link provided in that email to confirm your
registration.</p>
<pre>{{email}}</pre>
</p>
{% else %}
<p>By creating a patchwork account, you can:<p>
......
Hi,
This email is to confirm your account on the patchwork patch-tracking
system. You can activate your account by visiting the url:
http://{{site.domain}}{% url patchwork.views.user.register_confirm key=request.key %}
If you didn't request a user account on patchwork, then you can ignore
this mail.
Happy patchworking.
......@@ -6,7 +6,7 @@
{% block body %}
{% if confirmation %}
{% if confirmation and not error %}
<p>A confirmation email has been sent to {{ confirmation.email }}.</p>
<p>beta link: <a
......@@ -19,6 +19,9 @@
<p>There was an error submitting your link request.</p>
{{ form.non_field_errors }}
{% endif %}
{% if error %}
<ul class="errorlist"><li>{{error}}</li></ul>
{% endif %}
<form action="{% url patchwork.views.user.link %}" method="post">
{{linkform.email.errors}}
......
Hi,
This email is to confirm that you own the email address:
{{ confirmation.email }}
So that you can add it to your patchwork profile. You can confirm this
email address by visiting the url:
http://{{site.domain}}{% url patchwork.views.user.link_confirm key=confirmation.key %}
Happy patchworking.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment