Exemple #1
0
def seed_admin(admin_file):
    try:
        with open(admin_file, 'r') as file:
            admins = yaml.load(file)
            for admin in admins:
                User.create(username=admin['username'], password=admin['password'], is_admin=True, active=True)
    except IntegrityError:
        print("Some of those credentials already exist.")
        exit(0)
Exemple #2
0
def register():
    form = RegisterForm(request.form, csrf_enabled=False)
    if form.validate_on_submit():
        game = create_game()
        User.create(username=form.username.data,
                    password=form.password.data,
                    active=True,
                    game_id=game.id)
        flash("Thank you for registering. You can now log in.", 'success')
        return redirect(url_for('public.home'))
    else:
        flash_errors(form)
    return render_template('public/register.html', form=form)
Exemple #3
0
def promote_to_admin(id):
    if not current_user.is_admin:
        raise InvalidUsage("Forbidden", 403)
    user = User.get_by_id(id)
    user.is_admin = True
    user.save()
    return redirect(url_for('user.settings'))
Exemple #4
0
def manage_data(user_id):
    user = current_user
    if user_id != user.id:
        if not current_user.is_admin:
            raise InvalidUsage("Forbidden", 403)
        user = User.get_by_id(user_id)
    return render_template(
        "user/managedata.html",
        scores=[
            SCORESCHEMA.dump(score).data
            for score in Score.query.filter(Score.game == user.game)
        ])
Exemple #5
0
def delete_user(id):
    if id == current_user.id:
        user = User.get_by_id(id)
        logout_user()
        user.delete()
        flash('Your account was successfully deleted.', 'info')
        return redirect(url_for('public.home'))
    if not current_user.is_admin:
        raise InvalidUsage('Forbidden', status_code=403)
    if id == current_user.id:
        raise InvalidUsage("You can't delete yourself!")
    user = User.query.filter(User.id == id).first()
    if user.is_admin:
        raise InvalidUsage("You can't delete an admin!")
    user.delete()
    return redirect(url_for('user.settings'))
Exemple #6
0
def load_user(id):
    return User.get_by_id(int(id))