示例#1
0
def task(task_id=None):
    task = get_object_or_404(Task, Task.id == task_id)
    if not task.can_access_by(g.user):
        if task.is_team_only():
            flash('This task is for selected team only', category='danger')
        return redirect(url_for('all_task'))
    form = SubmitFlagForm(task.id)
    if form.validate_on_submit():
        log_data = SubmitLogs(g.user, task, form.flag.data)
        db.session.add(log_data)
        db.session.commit()
        if form.flag.data == task.flag:
            if UserSolved.query.filter_by(user_id=g.user.id,
                                          task_id=task.id).first():
                flash('Correct flag but you already solved this task.',
                      category='success')
                return redirect(url_for('task', task_id=task.id))
            elif g.user.team and task in g.user.team.solved_tasks():
                flash(
                    'Correct flag but your team-mate already solved this task.',
                    category='success')
            else:
                flash('Correct Flag. Congrats!', category='success')
            solved_data = UserSolved(g.user, task)
            db.session.add(solved_data)
            db.session.commit()
            return redirect(url_for('task', task_id=task.id))
        else:
            flash('Wrong Flag. Bad luck. Please try harder!',
                  category='danger')
    return render_template('task.html', task=task, form=form)
示例#2
0
def profile(user_id=None):
    if user_id is None or user_id == g.user.id:
        join_team_form = JoinTeamForm()
        leave_team_form = LeaveTeamForm()
        if not app.config['LOCK_TEAM']:
            if join_team_form.invite_code.data and join_team_form.validate_on_submit(
            ) and not g.user.team:
                team = Team.query.filter_by(
                    invite_code=join_team_form.invite_code.data).first()
                g.user.team = team
                db.session.add(g.user)
                db.session.commit()
                flash("You've joined team <strong>%s</strong> !" % team.name,
                      category='success')
            if leave_team_form.team_id.data and leave_team_form.validate_on_submit(
            ) and g.user.team:
                team = Team.query.get(leave_team_form.team_id.data)
                if g.user.team == team:
                    g.user.team = None
                    db.session.add(g.user)
                    db.session.commit()
                    flash("You've left team <strong>%s</strong> !" % team.name,
                          category='success')

        return render_template('profile.html',
                               user=g.user,
                               join_team_form=join_team_form,
                               leave_team_form=leave_team_form,
                               locked_team=app.config['LOCK_TEAM'],
                               locked_profile=app.config['LOCK_PROFILE'])
    else:
        user = get_object_or_404(User, User.id == user_id)
        return render_template('profile.html', user=user)
示例#3
0
def confirm_delete_task(task_id=None):
    task = get_object_or_404(Task, Task.id == task_id)
    if request.method == 'POST':
        db.session.delete(task)
        db.session.commit()
        flash('Task deleted', category='success')
        return redirect(url_for('admin'))
    return render_template('confirm_delete_task.html', task=task)
示例#4
0
def toggle_task(task_id=None, toggle=''):
    task = get_object_or_404(Task, Task.id == task_id)
    if toggle not in ['open', 'close']:
        return redirect(url_for('index'))
    else:
        task.is_open = True if toggle == 'open' else False
        db.session.add(task)
        db.session.commit()
        return redirect(url_for('admin'))
示例#5
0
def team(team_id=None):
    if team_id is None:
        if g.user.team:
            return render_template('team.html', team=g.user.team)
        else:
            return redirect(url_for('profile'))

    team = get_object_or_404(Team, Team.id == team_id)
    return render_template('team.html', team=team)
示例#6
0
def edit_hint(hint_id=None):
    model = get_object_or_404(Hint, Hint.id == hint_id)
    form = HintForm(obj=model)

    if form.validate_on_submit():
        form.populate_obj(model)
        db.session.add(model)
        db.session.commit()
        flash('Hint updated', category='success')
        return redirect(url_for('task', task_id=model.task.id))
    return render_template('edit_hint.html', task=model, form=form)
示例#7
0
def edit_task(task_id=None):
    model = get_object_or_404(Task, Task.id == task_id)
    form = TaskForm(obj=model)

    if form.validate_on_submit():
        form.populate_obj(model)
        db.session.add(model)
        db.session.commit()
        flash('Task updated', category='success')
        return redirect(url_for('admin'))
    return render_template('edit_task.html', task=model, form=form)
示例#8
0
def edit_team(team_id=None):
    model = get_object_or_404(Team, Team.id == team_id)
    if g.user not in model.members and not g.user.is_admin():
        return redirect(url_for('index'))
    form = TeamForm(obj=model)

    if form.validate_on_submit():
        form.populate_obj(model)
        db.session.add(model)
        db.session.commit()
        flash('Team updated', category='success')
        return redirect(url_for('team', team_id=model.id))
    return render_template('edit_team.html', team=model, form=form)
示例#9
0
def change_password(user_id=None):
    if g.user.is_admin():
        user = get_object_or_404(User, User.id == user_id)
    else:
        user = User.query.get(g.user.id)
    form = ChangePasswordForm()
    if form.validate_on_submit():
        user.set_password(form.new_password.data)
        db.session.add(user)
        db.session.commit()
        flash('Password changed successfully.', category='success')
        return redirect(url_for('profile', user_id=user.id))
    return render_template('change_password.html', user=user, form=form)