Beispiel #1
0
def user_activate(account_id):

    if not current_user.admin:
        return "Access denied"
    user = User.query.get(account_id)

    user.inactive = 0

    db.session().commit()

    app.jinja_env.globals.update(inactive_users=User.countInactives())
    return redirect(url_for("accounts_index"))
Beispiel #2
0
def account_create():
    form = NewAccountForm(request.form)

    departments = Dept.query.all()
    form.departments.choices = [(department.departmentID, department.name)
                                for department in departments]
    # This is needed to validate the form correctly
    value = dict(form.departments.choices).get(form.departments.data)

    # Check if user is in the list of existing user and prevent creation
    users = User.query.all()
    existing_usersIDs = [user.userID for user in users]
    if form.username.data in existing_usersIDs:
        return render_template("auth/new.html",
                               form=form,
                               id_error="User already exists")

    if not form.validate():
        return render_template("auth/new.html", form=form)
    if form.admin.data == False:
        form.admin.data = 0
    else:
        form.admin.data = 1

    user = User(form.username.data, form.firstname.data, form.lastname.data,
                sha256_crypt.hash(form.password.data), form.departments.data,
                form.admin.data)

    if not current_user.is_authenticated:
        user.inactive = 1
        return_url = "index"

    else:
        user.inactive = 0
        return_url = "accounts_index"
    db.session().add(user)
    db.session().commit()

    # Pass inactive users to the management badge
    # This is currently causing trouble in heroku and not yet fully functional locally either
    app.jinja_env.globals.update(inactive_users=User.countInactives())

    return redirect(url_for(return_url))