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: """ 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 create_user( self, email, password: str = None, name: str = None, timezone: str = '', lang: str= None, auth_type: AuthType = AuthType.UNKNOWN, groups=[], do_save: bool=True, do_notify: bool=True, ) -> User: if do_notify and not self._config.EMAIL_NOTIFICATION_ACTIVATED: raise NotificationDisabledCantCreateUserWithInvitation( "Can't create user with invitation mail because " "notification are disabled." ) new_user = self.create_minimal_user(email, groups, save_now=False) self.update( user=new_user, name=name, email=email, auth_type=auth_type, password=password, timezone=timezone, lang=lang, do_save=False, ) if do_notify: try: email_manager = get_email_manager(self._config, self._session) email_manager.notify_created_account( new_user, password=password ) # FIXME - G.M - 2018-11-02 - hack: accept bad recipient user creation # this should be fixed to find a solution to allow "fake" email but # also have clear error case for valid mail. except SMTPRecipientsRefused as exc: logger.warning( self, "Account created for {email} but SMTP server refuse to send notification".format( # nopep8 email=email ) ) except SMTPException as exc: raise NotificationSendingFailed( "Notification for new created account can't be send " "(SMTP error), new account creation aborted" ) from exc if do_save: self.save(new_user) return new_user
def create_user( self, email, password: str = None, name: str = None, timezone: str = "", lang: str = None, auth_type: AuthType = AuthType.UNKNOWN, profile: typing.Optional[Profile] = None, allowed_space: typing.Optional[int] = None, do_save: bool = True, do_notify: bool = True, ) -> User: if do_notify and not self._config.EMAIL__NOTIFICATION__ACTIVATED: raise NotificationDisabledCantCreateUserWithInvitation( "Can't create user with invitation mail because " "notification are disabled.") new_user = self.create_minimal_user(email, profile, save_now=False) if allowed_space is None: allowed_space = self._config.LIMITATION__USER_DEFAULT_ALLOWED_SPACE self.update( user=new_user, name=name, email=email, auth_type=auth_type, password=password, timezone=timezone, allowed_space=allowed_space, lang=lang, do_save=False, ) if do_notify: try: email_manager = get_email_manager(self._config, self._session) email_manager.notify_created_account(new_user, password=password, origin_user=self._user) # FIXME - G.M - 2018-11-02 - hack: accept bad recipient user creation # this should be fixed to find a solution to allow "fake" email but # also have clear error case for valid mail. except SMTPRecipientsRefused: logger.warning( self, "Account created for {email} but SMTP server refuse to send notification" .format(email=email), ) except SMTPException as exc: raise NotificationSendingFailed( "Notification for new created account can't be send " "(SMTP error), new account creation aborted") from exc if do_save: self.save(new_user) return new_user
def create_user( self, email, password: str = None, name: str = None, timezone: str = '', lang: str = None, groups=[], do_save: bool = True, do_notify: bool = True, ) -> User: if do_notify and not self._config.EMAIL_NOTIFICATION_ACTIVATED: raise NotificationDisabledCantCreateUserWithInvitation( "Can't create user with invitation mail because " "notification are disabled.") new_user = self.create_minimal_user(email, groups, save_now=False) self.update( user=new_user, name=name, email=email, password=password, timezone=timezone, lang=lang, do_save=False, ) if do_notify: try: email_manager = get_email_manager(self._config, self._session) email_manager.notify_created_account(new_user, password=password) # FIXME - G.M - 2018-11-02 - hack: accept bad recipient user creation # this should be fixed to find a solution to allow "fake" email but # also have clear error case for valid mail. except SMTPRecipientsRefused as exc: logger.warning( self, "Account created for {email} but SMTP server refuse to send notification" .format( # nopep8 email=email)) except SMTPException as exc: raise NotificationSendingFailed( "Notification for new created account can't be send " "(SMTP error), new account creation aborted") from exc if do_save: self.save(new_user) return new_user
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