From b6263a4969f9f17b8085c469657f5a4f6dd679db Mon Sep 17 00:00:00 2001 From: Andrew Redden Date: Wed, 4 Sep 2019 15:18:59 +0200 Subject: [PATCH] Fix for GWE-282-0 (#5126) * addressing GWE-282-0 * fix isort --- app/marketing/views.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/marketing/views.py b/app/marketing/views.py index e97390c5bc4..08bd4410b12 100644 --- a/app/marketing/views.py +++ b/app/marketing/views.py @@ -25,6 +25,7 @@ from django.conf import settings from django.contrib import messages from django.contrib.admin.views.decorators import staff_member_required +from django.contrib.auth.models import User from django.core.validators import validate_email from django.db.models import Max from django.http import Http404, HttpResponse @@ -275,6 +276,10 @@ def email_settings(request, key): preferred_language = request.POST.get('preferred_language') validation_passed = True try: + email_in_use = User.objects.filter(email=email) | User.objects.filter(profile__email=email) + email_used_marketing = EmailSubscriber.objects.filter(email=email).select_related('profile') + if (email_in_use or email_used_marketing) and (request.user.email != email or request.user.profile.email != email): + raise ValueError(f'{request.user} attempting to use an email which is already in use on the platform') validate_email(email) except Exception as e: print(e)