Beispiel #1
0
def admin_create_team():
    name = request.form.get('name', None)
    password = request.form.get('password', None)
    email = request.form.get('email', None)
    website = request.form.get('website', None)
    affiliation = request.form.get('affiliation', None)
    country = request.form.get('country', None)

    admin_user = True if request.form.get('admin', None) == 'on' else False
    verified = True if request.form.get('verified', None) == 'on' else False
    hidden = True if request.form.get('hidden', None) == 'on' else False

    errors = []

    if not name:
        errors.append('The team requires a name')
    elif Teams.query.filter(Teams.name == name).first():
        errors.append('That name is taken')

    if utils.check_email_format(name) is True:
        errors.append('Team name cannot be an email address')

    if not email:
        errors.append('The team requires an email')
    elif Teams.query.filter(Teams.email == email).first():
        errors.append('That email is taken')

    if email:
        valid_email = utils.check_email_format(email)
        if not valid_email:
            errors.append("That email address is invalid")

    if not password:
        errors.append('The team requires a password')

    if website and (website.startswith('http://')
                    or website.startswith('https://')) is False:
        errors.append('Websites must start with http:// or https://')

    if errors:
        db.session.close()
        return jsonify({'data': errors})

    team = Teams(name, email, password)
    team.website = website
    team.affiliation = affiliation
    team.country = country

    team.admin = admin_user
    team.verified = verified
    team.banned = hidden

    db.session.add(team)
    db.session.commit()
    db.session.close()
    return jsonify({'data': ['success']})
Beispiel #2
0
            chal = random.randint(1, CHAL_AMOUNT)
            filename = gen_file()
            md5hash = hashlib.md5(filename).hexdigest()
            db.session.add(Files(chal, os.path.join("static/uploads", md5hash, filename)))
        db.session.commit()

        ### Generating Users
        print("GENERATING USERS")
        used = []
        count = 0
        while count < USER_AMOUNT:
            name = gen_name()
            if name not in used:
                used.append(name)
                team = Teams(name, name.lower() + gen_email(), "password")
                team.verified = True
                db.session.add(team)
                count += 1
        db.session.commit()

        ### Generating Solves
        print("GENERATING SOLVES")
        for x in range(USER_AMOUNT):
            used = []
            base_time = datetime.datetime.utcnow() + datetime.timedelta(minutes=-10000)
            for y in range(random.randint(1, CHAL_AMOUNT)):
                chalid = random.randint(1, CHAL_AMOUNT)
                if chalid not in used:
                    used.append(chalid)
                    solve = Solves(chalid, x + 1, "127.0.0.1", gen_word())
Beispiel #3
0
            filename = gen_file()
            md5hash = hashlib.md5(filename.encode('utf-8')).hexdigest()
            db.session.add(Files(chal, md5hash + '/' + filename))

        db.session.commit()

        # Generating Users
        print("GENERATING USERS")
        used = []
        count = 0
        while count < USER_AMOUNT:
            name = gen_name()
            if name not in used:
                used.append(name)
                team = Teams(name, name.lower() + gen_email(), 'password')
                team.verified = True
                db.session.add(team)
                count += 1

        db.session.commit()

        # Generating Solves
        print("GENERATING SOLVES")
        for x in range(USER_AMOUNT):
            used = []
            base_time = datetime.datetime.utcnow() + datetime.timedelta(minutes=-10000)
            for y in range(random.randint(1, CHAL_AMOUNT)):
                chalid = random.randint(1, CHAL_AMOUNT)
                if chalid not in used:
                    used.append(chalid)
                    solve = Solves(x + 1, chalid, '127.0.0.1', gen_word())
Beispiel #4
0
def admin_create_team_custom():
    name = request.form.get('name', None)
    password = request.form.get('password', None)
    email = request.form.get('email', None)
    color = request.form.get('color', None)
    image = request.form.get('image', None)
    school = request.form.get('school', None)
    if not color in teamColors:
        color = "RED"
    if not image in teamImages:
        image = "HULK"

    admin_user = True if request.form.get('admin', None) == 'on' else False
    verified = True if request.form.get('verified', None) == 'on' else False
    hidden = True if request.form.get('hidden', None) == 'on' else False

    smart_color = SmartCityTeam.query.add_columns('color').filter_by(
        color=color).first()
    smart_image = SmartCityTeam.query.add_columns('image').filter_by(
        image=image).first()

    errors = []

    if not name:
        errors.append('The team requires a name')
    elif Teams.query.filter(Teams.name == name).first():
        errors.append('That name is taken')

    if utils.check_email_format(name) is True:
        errors.append('Team name cannot be an email address')

    if not email:
        errors.append('The team requires an email')
    elif Teams.query.filter(Teams.email == email).first():
        errors.append('That email is taken')

    if email:
        valid_email = utils.check_email_format(email)
        if not valid_email:
            errors.append("That email address is invalid")

    if not password:
        errors.append('The team requires a password')

    if smart_color:
        errors.append('Color was taken. Available Colors: ' +
                      getAvailableColors())
    if smart_image:
        errors.append('Imagge already taken')
    if errors:
        db.session.close()
        return jsonify({'data': errors})

    team = Teams(name, email, password)

    #team.website = website
    #team.affiliation = affiliation
    #team.country = country

    team.admin = admin_user
    team.verified = verified
    team.hidden = hidden

    db.session.add(team)
    db.session.commit()

    smart_team = SmartCityTeam(team.id, name, color, image, school)
    db.session.add(smart_team)
    db.session.commit()
    db.session.close()

    return jsonify({'data': ['success']})