def reset_password_notification(self, user: User, do_save: bool = False) -> str: """ Reset password notification :param user: The user for which the password is reset :param do_save: should we save the update? :return: reset_password_token """ self._check_user_auth_validity(user) self._check_password_modification_allowed(user) if not user.email: raise MissingEmailCantResetPassword( "Can't reset password without an email address") if not self._config.EMAIL__NOTIFICATION__ACTIVATED: raise NotificationDisabledCantResetPassword( "Can't reset password with notification disabled") token = user.generate_reset_password_token() try: email_manager = get_email_manager(self._config, self._session) email_manager.notify_reset_password(user, token) except SMTPException as exc: raise NotificationSendingFailed( "SMTP error, can't send notification") from exc except EmailTemplateError as exc: raise exc if do_save: self.save(user) return token
def reset_password_notification(self, user: User, do_save: bool = False) -> str: # nopep8 """ Reset password notification :param user: User who want is password resetted :param do_save: save update ? :return: reset_password_token """ self._check_user_auth_validity(user) self._check_password_modification_allowed(user) if not self._config.EMAIL_NOTIFICATION_ACTIVATED: raise NotificationDisabledCantResetPassword( "cant reset password with notification disabled") # nopep8 token = user.generate_reset_password_token() try: email_manager = get_email_manager(self._config, self._session) email_manager.notify_reset_password(user, token) except SMTPException as exc: raise NotificationSendingFailed( "SMTP error, can't send notification") from exc except EmailTemplateError as exc: raise exc if do_save: self.save(user) return token
def reset_password_notification(self, user: User, do_save: bool=False) -> str: # nopep8 """ Reset password notification :param user: User who want is password resetted :param do_save: save update ? :return: reset_password_token """ self._check_user_auth_validity(user) self._check_password_modification_allowed(user) if not self._config.EMAIL_NOTIFICATION_ACTIVATED: raise NotificationDisabledCantResetPassword("cant reset password with notification disabled") # nopep8 token = user.generate_reset_password_token() try: email_manager = get_email_manager(self._config, self._session) email_manager.notify_reset_password(user, token) except SMTPException as exc: raise NotificationSendingFailed("SMTP error, can't send notification") from exc except EmailTemplateError as exc: raise exc if do_save: self.save(user) return token