Exemplo n.º 1
0
def add_user():
    form = UserCreateForm()
    orgs = Organization.query.all()
    form.organizations.choices = [(org.id, org.name) for org in orgs]

    if form.validate_on_submit():
        user = User(
            username=form.username.data,
            email=form.email.data,
            is_admin=form.is_admin.data,
        )
        user.set_password(form.password.data)
        orgs = []

        for org_id in form.organizations.data:
            org = Organization.query.filter_by(id=org_id).first()
            orgs.append(org)

        user.organizations = orgs
        session_add(user)
        session_commit()

        return redirect(url_for("admin.show_panel"))

    return render_template('admin_panel/create_user.html', form=form)
Exemplo n.º 2
0
def change_email(user_id):
    form = EmailForm()
    user = User.query.filter_by(id=user_id).first()

    if form.validate_on_submit():
        user.email = form.email.data
        session_commit()

        return redirect(url_for("admin.show_panel"))

    return render_template("admin_panel/change_email.html",
                           form=form,
                           user=user)
Exemplo n.º 3
0
def change_password(user_id):
    form = PasswordForm()
    user = User.query.filter_by(id=user_id).first()

    if form.validate_on_submit():
        user.set_password(form.password.data)
        session_commit()

        return redirect(url_for("admin.show_panel"))

    return render_template("admin_panel/change_password.html",
                           form=form,
                           user=user)
Exemplo n.º 4
0
def add_organization():
    form = OrgCreateForm()
    users = User.query.all()
    # empty_choice = [(0, " " * 10)]
    form.users.choices = [(user.id, user.email) for user in users]

    if form.validate_on_submit():
        org = Organization(name=form.name.data, data_dir=form.data_dir.data)
        users = []

        for user_id in form.users.data:
            user = User.query.filter_by(id=user_id).first()
            users.append(user)

        org.users = users
        session_add(org)
        session_commit()

        return redirect(url_for("admin.add_organization"))

    return render_template("admin_panel/create_organization.html", form=form)
Exemplo n.º 5
0
def change_userinfo(user_id):
    form = UserInfoForm()
    user = User.query.filter_by(id=user_id).first()
    orgs = Organization.query.all()
    form.organizations.choices = [(org.id, org.name) for org in orgs]

    if form.validate_on_submit():
        user.username = form.username.data
        user.is_admin = form.is_admin.data
        orgs = []

        for org_id in form.organizations.data:
            org = Organization.query.filter_by(id=org_id).first()
            orgs.append(org)

        user.organizations = orgs
        session_commit()

        return redirect(url_for("admin.show_panel"))

    return render_template("admin_panel/change_userinfo.html",
                           form=form,
                           user=user)
Exemplo n.º 6
0
def edit_organization(org_id):
    form = OrgInfoForm()
    users = User.query.all()
    form.users.choices = [(user.id, user.email) for user in users]
    org = Organization.query.filter_by(id=org_id).first()

    if form.validate_on_submit():
        org.name = form.name.data
        org.data_dir = form.data_dir.data
        users = []

        for user_id in form.users.data:
            user = User.query.filter_by(id=user_id).first()
            users.append(user)

        org.users = users
        session_commit()

        return redirect(url_for("admin.list_organizations"))

    return render_template("admin_panel/edit_organization.html",
                           form=form,
                           org=org)
Exemplo n.º 7
0
def create_admin():
    user = User(username="******", email="*****@*****.**", is_admin=True)
    user.set_password("12345")
    session_add(user)
    session_commit()
Exemplo n.º 8
0
def delete_organization(org_id):
    org = Organization.query.filter_by(id=org_id).first()
    session_delete(org)
    session_commit()

    return redirect(url_for("admin.list_organizations"))
Exemplo n.º 9
0
def delete_user(user_id):
    user = User.query.filter_by(id=user_id).first()
    session_delete(user)
    session_commit()

    return redirect(url_for("admin.show_panel"))