Example #1
0
def user_edit(username):
    """Allows admin to edit user information"""
    check_permissions()
    user = User.query.filter_by(username=username).first_or_404()
    form = EditProfileForm(user.username, user.email)
    if form.validate_on_submit():
        user.name = form.name.data
        user.organisation = form.organisation.data
        user.username = form.username.data
        user.email = form.email.data
        user.admin = form.admin.data
        user.reviewer = form.reviewer.data
        db.session.commit()
        flash('Updated successfully')
        return redirect(url_for('admin.user_management'))
    elif request.method == 'GET':
        form.name.data = user.name
        form.organisation.data = user.organisation
        form.username.data = user.username
        form.email.data = user.email
        form.admin.data = user.admin
        form.reviewer.data = user.reviewer
    return render_template('admin/edit_profile.html',
                           title='Edit Profile',
                           form=form,
                           username=username)
Example #2
0
def user_pwreset(username):
    """Allows admin to reset password"""
    check_permissions()
    user = User.query.filter_by(username=username).first_or_404()
    form = ChangePasswordForm()
    del form.currentpassword
    if form.validate_on_submit():
        user.set_password(form.password.data)
        user.revoke_token()
        db.session.commit()
        flash('Password reset successfully')
        return redirect(url_for('admin.user_management'))
    return render_template('auth/change_password.html',
                           title='Reset Password',
                           form=form)
Example #3
0
def category_create(comp_id):
    """Create categories"""
    check_permissions()
    form = CategoryForm()
    if form.validate_on_submit():
        category = Category(name=form.name.data,
                            body=form.body.data,
                            comp_id=comp_id)
        db.session.add(category)
        db.session.commit()
        flash('Category created successfully')
        return redirect(
            url_for('competition.submissions_overview',
                    comp_id=comp_id,
                    cat_id=category.id))
    return render_template('competition/categoryCreate.html',
                           title='Create Category',
                           form=form)
Example #4
0
def register():
    """Registration page"""
    check_permissions()
    form = RegistrationForm()
    del form.recaptcha
    if form.validate_on_submit():
        user = User(username=form.username.data,
                    email=form.email.data,
                    name=form.name.data,
                    organisation=form.organisation.data,
                    admin=bool(form.admin.data),
                    reviewer=bool(form.reviewer.data))
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('User registed successfully')
        return redirect(url_for('admin.admin'))
    return render_template('auth/register.html', title='Register', form=form)
Example #5
0
def category_edit(comp_id, cat_id):
    """Edits a submission"""
    category = Category.query.filter_by(id=cat_id).filter_by(
        comp_id=comp_id).first_or_404()
    form = CategoryForm()
    check_permissions()
    if request.method == 'GET':
        form.name.data = category.name
        form.body.data = category.body
    if form.validate_on_submit():
        category.name = form.name.data
        category.body = form.body.data
        db.session.commit()
        flash('Category edited successfully')
        return redirect(
            url_for('competition.submissions_overview',
                    comp_id=comp_id,
                    cat_id=cat_id))
    return render_template('competition/categoryEdit.html',
                           title='Edit Category',
                           form=form)
Example #6
0
def api_users():
    """Dummy function, calls other function"""
    check_permissions()
    return get_users()
Example #7
0
def user_management():
    """Displays users in a table"""
    check_permissions()
    return render_template('admin/userTable.html', title="User Management")