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
@@ -403,10 +405,6 @@ class UserAddEmail(UserMixin, FormView):
403405 form_class = AddEmailForm
404406
405407 def form_valid (self , form ):
406- from osf .exceptions import BlockedEmailError
407- from django .core .exceptions import ValidationError as DjangoValidationError
408- from framework .auth .views import send_confirm_email_async
409- from django .utils import timezone
410408
411409 user = self .get_object ()
412410 address = form .cleaned_data ['new_email' ].strip ().lower ()
@@ -430,7 +428,7 @@ def form_valid(self, form):
430428 user .email_last_sent = timezone .now ()
431429 user .save ()
432430 messages .success (self .request , f'Added unconfirmed email { address } and sent confirmation email.' )
433- except (DjangoValidationError , ValueError ) as e :
431+ except (ValidationError , ValueError ) as e :
434432 messages .error (self .request , f'Invalid email: { getattr (e , "message" , str (e ))} ' )
435433 except BlockedEmailError :
436434 messages .error (self .request , 'This email address domain is blocked.' )
0 commit comments