Exemplo n.º 1
0
def add_user(username, role):
    pswd = getpass.getpass('Password: '******'Repeat password: '******'User {} already exist'.format(username), err=True)
            db.session.rollback()
    else:
        click.echo('Password confirmation mismatch.', err=True)
Exemplo n.º 2
0
def add_user():
    form = AddUserForm(request.form)

    if form.validate_on_submit():
        username = form.username.data
        if form.password.data == form.passwordrep.data:
            try:
                user = User(username=username)
                user.set_database_passwd(form.password.data)
            except IntegrityError:
                flash('User {} already exist'.format(username), 'danger')
                db.session.rollback()
        else:
            flash('Password repeat invalid', 'danger')

    return redirect_back('users.index')
Exemplo n.º 3
0
def edit(client_id: int):
    client: Client = Client.query.filter_by(id=client_id).one()

    if not current_user.manages(client):
        abort(403)

    if request.form:
        form = ClientForm(request.form)
    else:
        form = ClientForm(**client.to_dict(),
                          managers=client.managers,
                          auditors=client.auditors,
                          templates=client.templates)

    form.managers.choices = User.get_choices(
        User.user_type.in_(valid_managers))
    form.auditors.choices = User.get_choices(
        User.user_type.in_(valid_auditors))
    form.templates.choices = Template.get_choices()

    change_owner_form = ClientChangeOwnerForm(owner=client.creator)
    change_owner_form.owner.choices = User.get_choices(
        User.user_type.in_(valid_managers))

    context = dict(form=form,
                   change_owner_form=change_owner_form,
                   client=client)
    if form.validate_on_submit():
        data = dict(form.data)
        data.pop('csrf_token', None)
        managers = data.pop('managers', [])
        auditors = data.pop('auditors', [])
        templates = data.pop('templates', [])

        client.set(**data)

        client.managers.clear()
        client.managers.extend(managers)

        client.auditors.clear()
        client.auditors.extend(auditors)

        client.templates.clear()
        client.templates.extend(templates)

        return redirect_back('.index')
    return render_template('clients/details.html', **context)
Exemplo n.º 4
0
def new():
    form = ClientForm(request.form)

    form.managers.choices = User.get_choices(
        User.user_type.in_(valid_managers))
    form.auditors.choices = User.get_choices(
        User.user_type.in_(valid_auditors))

    context = dict(form=form)
    if form.validate_on_submit():
        data = form.data
        data.pop('csrf_token')

        Client(creator=current_user, **data)
        return redirect_back('.index')

    return render_template('clients/new.html', **context)
Exemplo n.º 5
0
def change_owner(client_id: int):
    client: Client = Client.query.filter_by(id=client_id).one()

    if not current_user.owns(client):
        abort(403)

    form = ClientChangeOwnerForm()
    form.owner.choices = User.get_choices(User.user_type.in_(valid_managers))

    if form.validate_on_submit():
        client.creator = form.owner.data

    return redirect_back('.index')
Exemplo n.º 6
0
def add_assessment(client_id: int):
    client = Client.query.filter_by(id=client_id).one()

    if not current_user.audits(client):
        abort(403)

    form = AssessmentForm(request.form)
    form.auditors.choices = User.get_choices(
        User.user_type.in_(valid_auditors))
    context = dict(form=form, client=client)

    if form.validate_on_submit():
        data = dict(form.data)
        data.pop('csrf_token', None)

        Assessment(client=client, creator=current_user, **data)
        return redirect_back('.edit', client_id=client_id)
    return render_template('clients/add_assessment.html', **context)