@@ -698,9 +698,36 @@ def post(self) -> Response:
698698 'ignore_auth' : True ,
699699 }
700700
701- user_objs : list [model .User ] = []
701+ user_objs : list [model .User ] = self . _get_user_objects ( id_ , context )
702702
703- # Usernames cannot contain '@' symbols
703+ for user_obj in user_objs :
704+ log .info ('Emailing reset link to user: %s' , user_obj .name )
705+ try :
706+ self ._send_notification (user_obj )
707+ signals .request_password_reset .send (
708+ user_obj .name , user = user_obj )
709+ except mailer .MailerException as e :
710+ # SMTP is not configured correctly or the server is
711+ # temporarily unavailable
712+ h .flash_error (_ (u'Error sending the email. Try again later '
713+ 'or contact an administrator for help' ))
714+ log .exception (e )
715+ return h .redirect_to (config .get (
716+ u'ckan.user_reset_landing_page' ))
717+
718+ # always tell the user it succeeded, because otherwise we reveal
719+ # which accounts exist or not
720+ h .flash_success (
721+ _ (u'A reset link has been emailed to you '
722+ '(unless the account specified does not exist)' ))
723+ return h .redirect_to (config .get (
724+ u'ckan.user_reset_landing_page' ))
725+
726+ def _get_user_objects (
727+ self , id_ : str ,
728+ context : Context
729+ ) -> list [model .User ]:
730+ user_objs : list [model .User ] = []
704731 if '@' in id_ :
705732 # Search by email address
706733 # (You can forget a user id, but you don't tend to forget your
@@ -732,31 +759,11 @@ def post(self) -> Response:
732759 pass
733760
734761 if not user_objs :
735- log .info ('User requested reset link for unknown user: %s' ,
736- repr_untrusted (id_ ))
737-
738- for user_obj in user_objs :
739- log .info ('Emailing reset link to user: %s' , user_obj .name )
740- try :
741- self ._send_notification (user_obj )
742- signals .request_password_reset .send (
743- user_obj .name , user = user_obj )
744- except mailer .MailerException as e :
745- # SMTP is not configured correctly or the server is
746- # temporarily unavailable
747- h .flash_error (_ (u'Error sending the email. Try again later '
748- 'or contact an administrator for help' ))
749- log .exception (e )
750- return h .redirect_to (config .get (
751- u'ckan.user_reset_landing_page' ))
752-
753- # always tell the user it succeeded, because otherwise we reveal
754- # which accounts exist or not
755- h .flash_success (
756- _ (u'A reset link has been emailed to you '
757- '(unless the account specified does not exist)' ))
758- return h .redirect_to (config .get (
759- u'ckan.user_reset_landing_page' ))
762+ log .info (
763+ 'User requested reset link for unknown user: %s' ,
764+ repr_untrusted (id_ )
765+ )
766+ return user_objs
760767
761768 def get (self ) -> str :
762769 self ._prepare ()
0 commit comments