From 21daa46778426ab0478d8641d3220fa341694c95 Mon Sep 17 00:00:00 2001
From: Dan Braghis <dan.braghis@torchbox.com>
Date: Thu, 25 Jan 2018 19:53:41 +0000
Subject: [PATCH] Fix repeat anonymous submission

---
 opentech/apply/funds/models.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/opentech/apply/funds/models.py b/opentech/apply/funds/models.py
index 0e9c76394..64feda913 100644
--- a/opentech/apply/funds/models.py
+++ b/opentech/apply/funds/models.py
@@ -73,6 +73,7 @@ class SubmittableStreamForm(AbstractStreamForm):
             full_name = cleaned_data.get('full_name')
 
             try:
+                # Cannot use get_or_create because we treat email as canonical, but username is not retired yet
                 user_data = {
                     'username': full_name if full_name else email,
                     'email': email,
@@ -90,7 +91,11 @@ class SubmittableStreamForm(AbstractStreamForm):
                     send_activation_email(user)
 
             except IntegrityError:
-                pass
+                email_field = getattr(User, 'EMAIL_FIELD', 'email')
+                try:
+                    user = User.objects.get(**{email_field: email})
+                except User.DoesNotExist:
+                    user = None
 
         self.send_confirmation_email(form, cleaned_data)
 
-- 
GitLab