99
99
OSFUser ,
100
100
Email ,
101
101
Tag ,
102
+ NotificationType
102
103
)
103
104
from osf .utils .tokens import TokenHandler
104
105
from osf .utils .tokens .handlers import sanction_handler
@@ -822,7 +823,7 @@ def get(self, request, *args, **kwargs):
822
823
raise ValidationError ('Request must include email in query params.' )
823
824
824
825
institutional = bool (request .query_params .get ('institutional' , None ))
825
- mail_template = mails . FORGOT_PASSWORD if not institutional else mails . FORGOT_PASSWORD_INSTITUTION
826
+ mail_template = 'forgot_password' if not institutional else 'forgot_password_institution'
826
827
827
828
status_message = language .RESET_PASSWORD_SUCCESS_STATUS_MESSAGE .format (email = email )
828
829
kind = 'success'
@@ -842,12 +843,15 @@ def get(self, request, *args, **kwargs):
842
843
user_obj .email_last_sent = timezone .now ()
843
844
user_obj .save ()
844
845
reset_link = f'{ settings .RESET_PASSWORD_URL } { user_obj ._id } /{ user_obj .verification_key_v2 ['token' ]} /'
845
- mails .send_mail (
846
- to_addr = email ,
847
- mail = mail_template ,
848
- reset_link = reset_link ,
849
- can_change_preferences = False ,
850
- )
846
+
847
+ notification_type = NotificationType .objects .filter (name = mail_template )
848
+ if not notification_type .exists ():
849
+ raise NotificationType .DoesNotExist (
850
+ f'NotificationType with name { mail_template } does not exist.'
851
+ )
852
+ notification_type = notification_type .first ()
853
+ notification_type .emit (user = user_obj , event_context = {'can_change_preferences' : False , 'reset_link' : reset_link })
854
+
851
855
return Response (status = status .HTTP_200_OK , data = {'message' : status_message , 'kind' : kind , 'institutional' : institutional })
852
856
853
857
@method_decorator (csrf_protect )
@@ -1059,13 +1063,13 @@ def _process_external_identity(self, user, external_identity, service_url):
1059
1063
if external_status == 'CREATE' :
1060
1064
service_url += '&' + urlencode ({'new' : 'true' })
1061
1065
elif external_status == 'LINK' :
1062
- mails . send_mail (
1063
- user = user ,
1064
- to_addr = user . username ,
1065
- mail = mails . EXTERNAL_LOGIN_LINK_SUCCESS ,
1066
- external_id_provider = provider ,
1067
- can_change_preferences = False ,
1068
- )
1066
+ notification_type = NotificationType . objects . filter ( name = 'external_confirm_success' )
1067
+ if not notification_type . exists ():
1068
+ raise NotificationType . DoesNotExist (
1069
+ 'NotificationType with name external_confirm_success does not exist.'
1070
+ )
1071
+ notification_type = notification_type . first ()
1072
+ notification_type . emit ( user = user , event_context = { 'can_change_preferences' : False , 'external_id_provider' : provider } )
1069
1073
1070
1074
enqueue_task (update_affiliation_for_orcid_sso_users .s (user ._id , provider_id ))
1071
1075
@@ -1380,13 +1384,13 @@ def post(self, request, *args, **kwargs):
1380
1384
if external_status == 'CREATE' :
1381
1385
service_url += '&{}' .format (urlencode ({'new' : 'true' }))
1382
1386
elif external_status == 'LINK' :
1383
- mails . send_mail (
1384
- user = user ,
1385
- to_addr = user . username ,
1386
- mail = mails . EXTERNAL_LOGIN_LINK_SUCCESS ,
1387
- external_id_provider = provider ,
1388
- can_change_preferences = False ,
1389
- )
1387
+ notification_type = NotificationType . objects . filter ( name = 'external_confirm_success' )
1388
+ if not notification_type . exists ():
1389
+ raise NotificationType . DoesNotExist (
1390
+ 'NotificationType with name external_confirm_success does not exist.'
1391
+ )
1392
+ notification_type = notification_type . first ()
1393
+ notification_type . emit ( user = user , event_context = { 'can_change_preferences' : False , 'external_id_provider' : provider } )
1390
1394
1391
1395
enqueue_task (update_affiliation_for_orcid_sso_users .s (user ._id , provider_id ))
1392
1396
0 commit comments