Make sure (at form verification level) that email addresses that are already in the persons table cannot be linked again.
Signed-off-by: martin f. krafft <[email protected]> --- apps/patchwork/views/user.py | 34 ++++++++++++++++++++-------------- 1 files changed, 20 insertions(+), 14 deletions(-) diff --git a/apps/patchwork/views/user.py b/apps/patchwork/views/user.py index 359c786..6b36e0e 100644 --- a/apps/patchwork/views/user.py +++ b/apps/patchwork/views/user.py @@ -67,21 +67,27 @@ def link(request): if request.method == 'POST': form = UserPersonLinkForm(request.POST) 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.DEFAULT_FROM_EMAIL, - [form.cleaned_data['email']]) - except Exception, ex: - context['confirmation'] = None - context['error'] = 'An error occurred during confirmation. ' + \ - 'Please try again later' + email = form.cleaned_data['email'] + + if Person.objects.filter(email__iexact = email): + context['error'] = 'This email address is already linked ' + \ + 'to a user.' + + else: + conf = UserPersonConfirmation(user = request.user, + email = email) + conf.save() + context['confirmation'] = conf + + try: + send_mail('Patchwork email address confirmation', + render_to_string('patchwork/user-link.mail', + context), + settings.DEFAULT_FROM_EMAIL, [email]) + 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) -- 1.5.6.5 _______________________________________________ Patchwork mailing list [email protected] https://lists.ozlabs.org/listinfo/patchwork
