Пример #1
0
    def post(
        self,
        name: str,
        email: str,
        password: str,
        is_tracim_manager: str = 'off',
        is_tracim_admin: str = 'off',
        send_email: str = 'off',
    ):
        is_tracim_manager = h.on_off_to_boolean(is_tracim_manager)
        is_tracim_admin = h.on_off_to_boolean(is_tracim_admin)
        send_email = h.on_off_to_boolean(send_email)
        current_user = tmpl_context.current_user

        if current_user.profile.id < Group.TIM_ADMIN:
            # A manager can't give large rights
            is_tracim_manager = False
            is_tracim_admin = False

        api = UserApi(current_user)

        if api.user_with_email_exists(email):
            tg.flash(
                _('A user with email address "{}" already exists.').format(
                    email), CST.STATUS_ERROR)
            tg.redirect(self.url())

        user = api.create_user()
        user.email = email
        user.display_name = name
        if password:
            user.password = password
        elif send_email:
            # Setup a random password to send email at user
            password = self.generate_password()
            user.password = password

        user.webdav_left_digest_response_hash = '%s:/:%s' % (email, password)

        api.save(user)

        # Now add the user to related groups
        group_api = GroupApi(current_user)
        user.groups.append(group_api.get_one(Group.TIM_USER))
        if is_tracim_manager:
            user.groups.append(group_api.get_one(Group.TIM_MANAGER))
            if is_tracim_admin:
                user.groups.append(group_api.get_one(Group.TIM_ADMIN))

        api.save(user)

        if send_email:
            email_manager = get_email_manager()
            email_manager.notify_created_account(user, password=password)

        api.execute_created_user_actions(user)
        tg.flash(
            _('User {} created.').format(user.get_display_name()),
            CST.STATUS_OK)
        tg.redirect(self.url())
Пример #2
0
    def _proceed_user(self, parsed_args):
        self._check_context(parsed_args)

        if self.action == self.ACTION_CREATE:
            try:
                user = self._create_user(login=parsed_args.login,
                                         password=parsed_args.password)
            except AlreadyExistError:
                raise CommandAbortedError(
                    "Error: User already exist (use `user update` command instead)"
                )
            if parsed_args.send_email:
                email_manager = get_email_manager()
                email_manager.notify_created_account(
                    user=user,
                    password=parsed_args.password,
                )

        else:
            if parsed_args.password:
                self._update_password_for_login(login=parsed_args.login,
                                                password=parsed_args.password)
            user = self._user_api.get_one_by_email(parsed_args.login)

        return user
Пример #3
0
    def post(
            self,
            name: str,
            email: str,
            password: str,
            is_tracim_manager: str='off',
            is_tracim_admin: str='off',
            send_email: str='off',
    ):
        is_tracim_manager = h.on_off_to_boolean(is_tracim_manager)
        is_tracim_admin = h.on_off_to_boolean(is_tracim_admin)
        send_email = h.on_off_to_boolean(send_email)
        current_user = tmpl_context.current_user

        if current_user.profile.id < Group.TIM_ADMIN:
            # A manager can't give large rights
            is_tracim_manager = False
            is_tracim_admin = False


        api = UserApi(current_user)

        if api.user_with_email_exists(email):
            tg.flash(_('A user with email address "{}" already exists.').format(email), CST.STATUS_ERROR)
            tg.redirect(self.url())

        user = api.create_user()
        user.email = email
        user.display_name = name
        if password:
            user.password = password
        elif send_email:
            # Setup a random password to send email at user
            password = str(uuid.uuid4())
            user.password = password

        user.webdav_left_digest_response_hash = '%s:/:%s' % (email, password)

        api.save(user)

        # Now add the user to related groups
        group_api = GroupApi(current_user)
        user.groups.append(group_api.get_one(Group.TIM_USER))
        if is_tracim_manager:
            user.groups.append(group_api.get_one(Group.TIM_MANAGER))
            if is_tracim_admin:
                user.groups.append(group_api.get_one(Group.TIM_ADMIN))

        api.save(user)

        if send_email:
            email_manager = get_email_manager()
            email_manager.notify_created_account(user, password=password)

        tg.flash(_('User {} created.').format(user.get_display_name()), CST.STATUS_OK)
        tg.redirect(self.url())
Пример #4
0
    def _proceed_user(self, parsed_args):
        self._check_context(parsed_args)

        if self.action == self.ACTION_CREATE:
            try:
                user = self._create_user(login=parsed_args.login, password=parsed_args.password)
            except AlreadyExistError:
                raise CommandAbortedError("Error: User already exist (use `user update` command instead)")
            if parsed_args.send_email:
                email_manager = get_email_manager()
                email_manager.notify_created_account(
                    user=user,
                    password=parsed_args.password,
                )

        else:
            if parsed_args.password:
                self._update_password_for_login(login=parsed_args.login, password=parsed_args.password)
            user = self._user_api.get_one_by_email(parsed_args.login)

        return user