1111from django .contrib import messages
1212from django .contrib .auth .mixins import PermissionRequiredMixin
1313from django .urls import reverse
14+ from django .utils import timezone
1415from django .core .exceptions import PermissionDenied
1516from django .shortcuts import redirect
1617from django .core .paginator import Paginator
1718from django .core .exceptions import ValidationError
1819
19- from osf .exceptions import UserStateError
20+ from osf .exceptions import UserStateError , BlockedEmailError
2021from osf .models .base import Guid
2122from osf .models .user import OSFUser , Email
2223from osf .models .spam import SpamStatus
2324from framework .auth import get_user
2425from framework .auth .core import generate_verification_key
26+ from framework .auth .views import send_confirm_email_async
2527
2628from website import search
2729from website .settings import EXTERNAL_IDENTITY_PROFILE
@@ -404,10 +406,6 @@ class UserAddEmail(UserMixin, FormView):
404406 form_class = AddEmailForm
405407
406408 def form_valid (self , form ):
407- from osf .exceptions import BlockedEmailError
408- from django .core .exceptions import ValidationError as DjangoValidationError
409- from framework .auth .views import send_confirm_email_async
410- from django .utils import timezone
411409
412410 user = self .get_object ()
413411 address = form .cleaned_data ['new_email' ].strip ().lower ()
@@ -431,7 +429,7 @@ def form_valid(self, form):
431429 user .email_last_sent = timezone .now ()
432430 user .save ()
433431 messages .success (self .request , f'Added unconfirmed email { address } and sent confirmation email.' )
434- except (DjangoValidationError , ValueError ) as e :
432+ except (ValidationError , ValueError ) as e :
435433 messages .error (self .request , f'Invalid email: { getattr (e , "message" , str (e ))} ' )
436434 except BlockedEmailError :
437435 messages .error (self .request , 'This email address domain is blocked.' )
0 commit comments