mirror of
https://github.com/aljazceru/CTFd.git
synced 2025-12-20 07:14:24 +01:00
Latest set of changes (#190)
* PEP 8 compliance (#183) * Group imports: standard library, third party, local * Remove unnecessary spaces * Comments should start with a # and a single space * Adding tests for GETs on user facing pages * Adding more user facing tests 51% test coverage * Fixes #182 * Cleaning up Pages Fixes a bug with CSS updating
This commit is contained in:
@@ -1,19 +1,13 @@
|
||||
from flask import current_app as app, render_template, render_template_string, request, redirect, abort, jsonify, json as json_mod, url_for, session, Blueprint, Response, send_file
|
||||
from CTFd.utils import authed, ip2long, long2ip, is_setup, validate_url, get_config, set_config, sha512, get_ip, cache, ctftime, view_after_ctf, ctf_started, \
|
||||
is_admin
|
||||
from CTFd.models import db, Teams, Solves, Awards, Challenges, WrongKeys, Keys, Tags, Files, Tracking, Pages, Config
|
||||
|
||||
from jinja2.exceptions import TemplateNotFound
|
||||
from passlib.hash import bcrypt_sha256
|
||||
from collections import OrderedDict
|
||||
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import json
|
||||
import os
|
||||
import datetime
|
||||
|
||||
from flask import current_app as app, render_template, request, redirect, abort, jsonify, url_for, session, Blueprint, Response, send_file
|
||||
from jinja2.exceptions import TemplateNotFound
|
||||
from passlib.hash import bcrypt_sha256
|
||||
|
||||
from CTFd.utils import authed, is_setup, validate_url, get_config, set_config, sha512, cache, ctftime, view_after_ctf, ctf_started, \
|
||||
is_admin
|
||||
from CTFd.models import db, Teams, Solves, Awards, Files, Pages
|
||||
|
||||
views = Blueprint('views', __name__)
|
||||
|
||||
@@ -38,10 +32,10 @@ def setup():
|
||||
ctf_name = request.form['ctf_name']
|
||||
ctf_name = set_config('ctf_name', ctf_name)
|
||||
|
||||
## CSS
|
||||
# CSS
|
||||
css = set_config('start', '')
|
||||
|
||||
## Admin user
|
||||
# Admin user
|
||||
name = request.form['name']
|
||||
email = request.form['email']
|
||||
password = request.form['password']
|
||||
@@ -49,7 +43,7 @@ def setup():
|
||||
admin.admin = True
|
||||
admin.banned = True
|
||||
|
||||
## Index page
|
||||
# Index page
|
||||
page = Pages('index', """<div class="container main-container">
|
||||
<img class="logo" src="{0}/static/original/img/logo.png" />
|
||||
<h3 class="text-center">
|
||||
@@ -61,20 +55,20 @@ def setup():
|
||||
</h4>
|
||||
</div>""".format(request.script_root))
|
||||
|
||||
#max attempts per challenge
|
||||
max_tries = set_config("max_tries",0)
|
||||
# max attempts per challenge
|
||||
max_tries = set_config("max_tries", 0)
|
||||
|
||||
## Start time
|
||||
# Start time
|
||||
start = set_config('start', None)
|
||||
end = set_config('end', None)
|
||||
|
||||
## Challenges cannot be viewed by unregistered users
|
||||
# Challenges cannot be viewed by unregistered users
|
||||
view_challenges_unregistered = set_config('view_challenges_unregistered', None)
|
||||
|
||||
## Allow/Disallow registration
|
||||
# Allow/Disallow registration
|
||||
prevent_registration = set_config('prevent_registration', None)
|
||||
|
||||
## Verify emails
|
||||
# Verify emails
|
||||
verify_emails = set_config('verify_emails', None)
|
||||
|
||||
mail_server = set_config('mail_server', None)
|
||||
@@ -118,13 +112,13 @@ def static_html(template):
|
||||
abort(404)
|
||||
|
||||
|
||||
@views.route('/teams', defaults={'page':'1'})
|
||||
@views.route('/teams', defaults={'page': '1'})
|
||||
@views.route('/teams/<page>')
|
||||
def teams(page):
|
||||
page = abs(int(page))
|
||||
results_per_page = 50
|
||||
page_start = results_per_page * ( page - 1 )
|
||||
page_end = results_per_page * ( page - 1 ) + results_per_page
|
||||
page_start = results_per_page * (page - 1)
|
||||
page_end = results_per_page * (page - 1) + results_per_page
|
||||
|
||||
if get_config('verify_emails'):
|
||||
count = Teams.query.filter_by(verified=True, banned=False).count()
|
||||
@@ -150,9 +144,9 @@ def team(teamid):
|
||||
if request.method == 'GET':
|
||||
return render_template('team.html', solves=solves, awards=awards, team=user, score=score, place=place)
|
||||
elif request.method == 'POST':
|
||||
json = {'solves':[]}
|
||||
json = {'solves': []}
|
||||
for x in solves:
|
||||
json['solves'].append({'id':x.id, 'chal':x.chalid, 'team':x.teamid})
|
||||
json['solves'].append({'id': x.id, 'chal': x.chalid, 'team': x.teamid})
|
||||
return jsonify(json)
|
||||
|
||||
|
||||
@@ -182,7 +176,7 @@ def profile():
|
||||
errors.append("Your old password doesn't match what we have.")
|
||||
if not valid_email:
|
||||
errors.append("That email doesn't look right")
|
||||
if not get_config('prevent_name_change') and names and name!=session['username']:
|
||||
if not get_config('prevent_name_change') and names and name != session['username']:
|
||||
errors.append('That team name is already taken')
|
||||
if emails and emails.id != session['id']:
|
||||
errors.append('That email has already been used')
|
||||
@@ -238,4 +232,4 @@ def file_handler(path):
|
||||
pass
|
||||
else:
|
||||
abort(403)
|
||||
return send_file(os.path.join(app.root_path, 'uploads', f.location))
|
||||
return send_file(os.path.join(app.root_path, 'uploads', f.location))
|
||||
|
||||
Reference in New Issue
Block a user