diff options
author | Jeremy Kerr <jk@ozlabs.org> | 2010-08-12 12:15:48 +0800 |
---|---|---|
committer | Jeremy Kerr <jk@ozlabs.org> | 2011-04-14 16:44:53 +0800 |
commit | 56e2243f3be7e859666ce0e4e1a8b8b94444f8d4 (patch) | |
tree | 7d3cf84b990a1b732d0334c5520f3203a955df12 /apps/patchwork/views | |
parent | c3291f5d18445cd91b540342d31d76254b32376c (diff) | |
download | patchwork-56e2243f3be7e859666ce0e4e1a8b8b94444f8d4.tar.bz2 patchwork-56e2243f3be7e859666ce0e4e1a8b8b94444f8d4.tar.xz |
Use generic email confirmation object
Rather than having a UserPerson-specific confirmation, add an
EmailConfirmation object to allow multiple types of confirmations (eg,
opt-out requests in future).
To do this, we use a view (patchwork.views.confirm) that will call the
type-specific view with the confirmation object.
Also, add tests to check that the User/Person linkage system works.
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Diffstat (limited to 'apps/patchwork/views')
-rw-r--r-- | apps/patchwork/views/base.py | 24 | ||||
-rw-r--r-- | apps/patchwork/views/user.py | 24 |
2 files changed, 37 insertions, 11 deletions
diff --git a/apps/patchwork/views/base.py b/apps/patchwork/views/base.py index c0e68ed..1539472 100644 --- a/apps/patchwork/views/base.py +++ b/apps/patchwork/views/base.py @@ -18,7 +18,7 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -from patchwork.models import Patch, Project, Person +from patchwork.models import Patch, Project, Person, EmailConfirmation from django.shortcuts import render_to_response, get_object_or_404 from django.http import HttpResponse, HttpResponseRedirect, Http404 from patchwork.requestcontext import PatchworkRequestContext @@ -58,6 +58,28 @@ def pwclient(request): response.write(render_to_string('patchwork/pwclient', context)) return response +def confirm(request, key): + import patchwork.views.user + views = { + 'userperson': patchwork.views.user.link_confirm, + } + + conf = get_object_or_404(EmailConfirmation, key = key) + if conf.type not in views: + raise Http404 + + if conf.active and conf.is_valid(): + return views[conf.type](request, conf) + + context = PatchworkRequestContext(request) + context['conf'] = conf + if not conf.active: + context['error'] = 'inactive' + elif not conf.is_valid(): + context['error'] = 'expired' + + return render_to_response('patchwork/confirm-error.html', context) + def submitter_complete(request): search = request.GET.get('q', '') response = HttpResponse(mimetype = "text/plain") diff --git a/apps/patchwork/views/user.py b/apps/patchwork/views/user.py index 1ae3c2d..759a6e3 100644 --- a/apps/patchwork/views/user.py +++ b/apps/patchwork/views/user.py @@ -22,8 +22,7 @@ from django.contrib.auth.decorators import login_required from patchwork.requestcontext import PatchworkRequestContext from django.shortcuts import render_to_response, get_object_or_404 from django.http import HttpResponseRedirect -from patchwork.models import Project, Bundle, Person, UserPersonConfirmation, \ - State +from patchwork.models import Project, Bundle, Person, EmailConfirmation, State from patchwork.forms import UserProfileForm, UserPersonLinkForm from patchwork.filters import DelegateFilter from patchwork.views import generic_list @@ -61,7 +60,8 @@ def link(request): if request.method == 'POST': form = UserPersonLinkForm(request.POST) if form.is_valid(): - conf = UserPersonConfirmation(user = request.user, + conf = EmailConfirmation(type = 'userperson', + user = request.user, email = form.cleaned_data['email']) conf.save() context['confirmation'] = conf @@ -83,15 +83,19 @@ def link(request): return render_to_response('patchwork/user-link.html', context) @login_required -def link_confirm(request, key): +def link_confirm(request, conf): context = PatchworkRequestContext(request) - confirmation = get_object_or_404(UserPersonConfirmation, key = key) - errors = confirmation.confirm() - if errors: - context['errors'] = errors - else: - context['person'] = Person.objects.get(email = confirmation.email) + try: + person = Person.objects.get(email__iexact = conf.email) + except Person.DoesNotExist: + person = Person(email = conf.email) + + person.link_to_user(conf.user) + person.save() + conf.deactivate() + + context['person'] = person return render_to_response('patchwork/user-link-confirm.html', context) |