Skip to content

Commit 5e5484b

Browse files
committed
add email check
1 parent 08c5239 commit 5e5484b

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

admin/users/views.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
from osf.exceptions import UserStateError
2020
from osf.models.base import Guid
21-
from osf.models.user import OSFUser
21+
from osf.models.user import OSFUser, Email
2222
from osf.models.spam import SpamStatus
2323
from framework.auth import get_user
2424
from framework.auth.core import generate_verification_key
@@ -410,6 +410,19 @@ def form_valid(self, form):
410410

411411
user = self.get_object()
412412
address = form.cleaned_data['new_email'].strip().lower()
413+
414+
existing_email = Email.objects.filter(address=address).first()
415+
if existing_email:
416+
if existing_email.user == user:
417+
messages.error(self.request, f'Email {address} is already confirmed for this user.')
418+
else:
419+
messages.error(self.request, f'Email {address} already exists in the system and is associated with another user.')
420+
return super().form_valid(form)
421+
422+
if address in user.unconfirmed_emails:
423+
messages.error(self.request, f'Email {address} is already pending confirmation for this user.')
424+
return super().form_valid(form)
425+
413426
try:
414427
user.add_unconfirmed_email(address)
415428

0 commit comments

Comments
 (0)