Esempio n. 1
0
def create_user():

    if request.method == "POST":

        facebook_id = request.json["facebook_id"]
        thumbnail_image_location = request.json["thumbnail_image_location"]
        full_name = request.json["name"]
        email = request.json["email"]

        # See if this is the first time this user has logged in.
        user = g.db.query(User).filter(User.facebook_id == facebook_id).first()
        if user is None:

            new_user = User(
                facebook_id=facebook_id,
                thumbnail_image_location=thumbnail_image_location,
                full_name=full_name,
                email=email,
                created_at=arrow.utcnow(),
            )
            g.db.add(new_user)
            # Commit early so we get a user id in the response.
            g.db.flush()
            return resource_created(new_user)

        else:

            # Update pictures
            user.thumbnail_image_location = thumbnail_image_location
            return resource_modified(user)

    else:

        return invalid_method()
Esempio n. 2
0
def change_user(user_id):

    if request.method == "PUT":

        user_id = int(user_id)
        user = g.db.query(User).filter(User.id == user_id).first()
        params = request.json
        for key in params:

            if key in User.changeable:
                setattr(user, key, params[key])

        return resource_modified(user)

    else:

        return invalid_method()
Esempio n. 3
0
def change_match(match_id):

    if request.method == 'PUT':

        match_id = int(match_id)
        params = request.json
        active = params.get('active',None)
        match = g.db.query(Match).filter(Match.id == match_id).first()
        
        if active is False:
            match.active = False
            g.socketio.emit('cancel',match.serialize(),namespace='/chat'+str(match.id))
            
        return resource_modified(match)

    else:

        return invalid_method()