Esempio n. 1
0
 def remove_from_role(self, role_name=None, role_id=None):
     if role_id is None:
         role = Role.find_byname(role_name)
         if role is None:
             raise ValueError(
                 'There is no role by the name of {role}'.format(
                     role=role_name))
         role_id = role.id
     settings.sql.user_remove_from_role(user_id=self.id, role_id=role_id)
Esempio n. 2
0
def add_role():
    form = AddRoleForm()
    if form.validate_on_submit():
        if not current_user.check_password(form.current_password.data):
            form.current_password.errors.append('Your password is incorrect')
        else:
            role = Role.find_byname(form.role_name.data)
            if role is not None:
                form.role_name.errors.append('this role already exists')
            else:
                Role.add(form.role_name.data)
    return render_template('accounts/addrole.html', form=form)
Esempio n. 3
0
def add_to_role():
    form = AddUserToRoleForm()
    if form.validate_on_submit():
        if not current_user.check_password(form.current_password.data):
            form.current_password.errors.append('Your password is incorrect')
        else:
            user = User.find_byname(form.target_username.data)
            if user is None:
                form.target_username.errors.append(
                    'Specified username does not exist')
            role = Role.find_byname(form.role_name.data)
            if role is None:
                form.role_name.errors.append('Specified role does not exist')
            if user is not None and role is not None:
                if not form.remove_instead.data:
                    user.add_to_role(role_name=form.role_name.data)
                else:
                    user.remove_from_role(role_name=form.role_name.data)
    return render_template('accounts/addusertorole.html', form=form)