Example #1
0
def status(name):
    elasticsearch_url = "http://{0}:{1}/".format(ELASTICSEARCH_HOST, ELASTICSEARCH_PORT)
    es_state = requests.get(elasticsearch_url)
    if es_state.status_code == 200:
        return "", 204
    else:
        Flask.abort(500)
Example #2
0
def joinGame(gameid, username):
    if username in getPlayers(gameid):
        return False
    db = get_db()
    if db.cursor().execute('SELECT * FROM userGames WHERE gameid=:id', {"id": gameid}).fetchone() is None:
        Flask.abort(402)
    db.cursor().execute('INSERT INTO userGames VALUES(?,?,?,?,?)', (None, getUserID(username), gameid, False, 0))
    db.commit()
Example #3
0
def startGame(gameid):
    db = get_db()
    sets = db.cursor().execute("SELECT sets FROM games WHERE gameid=:id", {"id": gameid}).fetchone()
    if sets is None:
        Flask.abort(401)
    sets = [allSets[Set] for Set in pickle.loads(sets[0])]
    players = getPlayers(gameid)
    print players, "players New Game"
    updateGame(gameid, Game(players, sets))
Example #4
0
def ready(gameid):
    if request.method == "POST":
        if request.form.has_key("join"):
            print "join"
            joinGame(gameid, session['username'])
            return redirect(url_for('lobby'))
        elif request.form.has_key("start"):
            startGame(gameid)
            return redirect(url_for("game", gameid=gameid))
    Flask.abort(301)
Example #5
0
def newGame():
    if request.method == "POST":
        sets = []
        for Set in allSets:
            if Set in request.form:
                sets.append(Set)
        username = session['username']
        createPendingGame(username, sets, request.form['numberOfPlayers'])
        return redirect(url_for('lobby', _method="POST", pending="See Pending Games"))
    else:
        Flask.abort(304)
Example #6
0
def getPlayers(gameid):
    db = get_db()
    players = db.cursor().execute(
        "select username from users U, userGames uG where uG.gameid =%d and uG.userid = U.userid" % int(
            gameid)).fetchall()
    print db.cursor().execute("select * from users U, userGames uG where uG.gameid =%d and uG.userid = U.userid" % int(
        gameid)).fetchall(), "players..."
    if players is None:
        Flask.abort(402)
    elif len(players) == 0:
        return None
    return [str(player[0]) for player in players]
Example #7
0
def createPendingGame(creator, sets=[base], numberOfPlayers=4):
    db = get_db()
    userid = getUserID(creator)
    if not userid:
        Flask.abort(402)

    db.cursor().execute('INSERT INTO games VALUES(?,?,?,?,?,?,?,?)',
                        (None, pickle.dumps(sets), None, datetime.utcnow(),
                            False, False, numberOfPlayers, userid))
    gameid = getLastRow("games", "gameid")
    print gameid, "lastrowid"

    db.cursor().execute('INSERT INTO userGames VALUES(?,?,?,?,?)', (None, userid, gameid, False, 0))
    db.commit()
Example #8
0
def choice(option, gameid):
    game = getCurrentGame(gameid)
    turn = game.currentTurn
    if not request.values.has_key('callback'):
        return Flask.abort(201)
    turn.event(request.values['callback'], option)
    updateGame(gameid, game)
Example #9
0
def supply(gameid):
    game = getCurrentGame(gameid)
    if not game:
        return Flask.abort(401)
    supply = game.supply
    print jsonify(supply.toDict())
    return jsonify(supply.toDict())
def login():
    # Here we use a class of some kind to represent and validate our
    # client-side form data. For example, WTForms is a library that will
    # handle this for us, and we use a custom LoginForm to validate.
    form = LoginForm()
    if form.validate_on_submit():
        # Login and validate the user.
        # user should be an instance of your `User` class
        login_user(user)

        Flask.flash('Logged in successfully.')

        next = Flask.request.args.get('next')
        # next_is_valid should check if the user has valid
        # permission to access the `next` url
        if not next_is_valid(next):
            return Flask.abort(400)

        return Flask.redirect(next or Flask.url_for('index'))
    return Flask.render_template('login.html', form=form)
Example #11
0
import os
from flask import Flask, request
from flask.ext.mail import Mail
from ..models import db
from .common import abort
from flask.ext.restful import Api, output_json

from . import index, users, auth

app = Flask(__name__)
app.abort = abort

env = os.environ.get('ENV', 'dev')
app.config.from_object('website.settings.%sConfig' % env.capitalize())
app.config['ERROR_404_HELP'] = False

auth.init(app)

db.init_app(app)
mail = Mail(app)

api = Api(app, catch_all_404s=True, default_mediatype='application/hal+json')
api.representations = {'application/hal+json': output_json}


@app.before_request
def validate_mimetype():
    message = "This endpoint only supports Content-Type: %s requests, not %s."
    json = 'application/json'
    if request.method in ['POST', 'PUT']:
        if request.mimetype != json: