Exemplo n.º 1
0
def admin():
    if not current_user.is_admin():
        # No permission
        flash("Permission denied", 'danger')
        return redirect(url_for("index"))

    form = UserForm()

    if form.is_submitted() and BaseForm.validate(
            form, extra_validators={'password': [validators.Required()]}):
        user = db.User()
        form.populate_obj(user)
        user.save()
        User.update(username=user.username, password=form.password.data)

        flash("Account for '%s' created" % user.username, 'success')
        return redirect(url_for("admin"))

    users = db.User.find()

    deployment_counts_raw = db.User.get_deployment_count_by_user()
    deployment_counts = {m['_id']: m['count'] for m in deployment_counts_raw}

    return render_template('admin.html',
                           form=form,
                           users=users,
                           deployment_counts=deployment_counts)
Exemplo n.º 2
0
 def authenticate(cls, username, password):
     if cls._check_login(username, password):
         # Return the ID of the user
         usr = db.User.find_one({'username': username})
         if usr is None:
             usr = db.User()
             usr.username = username
             usr.save()
         return usr
     return None