Example #1
0
def delete_session(sessionid):
    '''
    Marks the session as inactive.
    
    TODO: Implement some kind of authentication and permission system here to 
    restrict access to deleting a sessionid.
    
    :param sessionid:
    :status 204: Deleted successfully
    :status 400: Bad parameters (badly formed sessionid)
    :status 401: Wrong credentials
    :status 404: Sessionid does not exist
    '''
    error = {}

    if not controller._is_uuid_valid(sessionid):
        error["message"] = "Invalid request."
        error["code"] = 400
        return jsonify(error=error), status.HTTP_400_BAD_REQUEST

    else:
        try:
            #############################
            # Success
            #############################

            controller.delete_session(sessionid)

            return "", status.HTTP_204_NO_CONTENT

        except SessionidNotFoundException:
            error["message"] = "SessionID not found."
            error["code"] = 404
            return jsonify(error=error), status.HTTP_404_NOT_FOUND

        except AuthenticationFailed:
            error[
                "message"] = "Could not authenticate. Check your credentials."
            error["code"] = 401
            return jsonify(error=error), status.HTTP_401_UNAUTHORIZED
Example #2
0
def delete_session(sessionid):
    '''
    Marks the session as inactive.
    
    TODO: Implement some kind of authentication and permission system here to 
    restrict access to deleting a sessionid.
    
    :param sessionid:
    :status 204: Deleted successfully
    :status 400: Bad parameters (badly formed sessionid)
    :status 401: Wrong credentials
    :status 404: Sessionid does not exist
    '''
    error = {}
    
    if not controller._is_uuid_valid(sessionid):
        error["message"] = "Invalid request." 
        error["code"] = 400
        return jsonify(error=error), status.HTTP_400_BAD_REQUEST
    
    else:
        try:
            #############################
            # Success
            #############################
            
            controller.delete_session(sessionid)  
                      
            return "", status.HTTP_204_NO_CONTENT
        
        
        except SessionidNotFoundException:
            error["message"] = "SessionID not found." 
            error["code"] = 404
            return jsonify(error=error), status.HTTP_404_NOT_FOUND 
        
        except AuthenticationFailed:
            error["message"] = "Could not authenticate. Check your credentials." 
            error["code"] = 401
            return jsonify(error=error), status.HTTP_401_UNAUTHORIZED   
Example #3
0
def get_session(sessionid):
    '''
    Get information about the sessionid.
    
    TODO: Implement some kind of authentication and permission system here to 
    restrict access to retrieving user information from a sessionid.
    
    :param sessionid:
    :status 200: Successful request
    :status 400: Not JSON object or missing parameters
    :status 401: Wrong credentials
    :status 404: Sessionid does not exist
    '''

    #     required_fields = ["sessionid"]
    #     if not request.json or not (set(required_fields).issubset(request.json)):
    #         return jsonify({'message': 'Invalid request. Please try again.'}), status.HTTP_400_BAD_REQUEST
    #     else:

    error = {}

    if not controller._is_uuid_valid(sessionid):
        error["message"] = "Invalid request."
        error["code"] = 400
        return jsonify(error=error), status.HTTP_400_BAD_REQUEST

    else:
        session = {}
        inactive = False
        if ("inactive" in request.args):
            if request.args["inactive"].lower() == "true":
                inactive = True
        try:

            #############################
            # Success
            #############################

            gamingsession = controller.get_session(sessionid, inactive)

            gamingsession_response = simplejson.dumps(
                gamingsession.as_hateoas(), indent=2)
            response = make_response(gamingsession_response,
                                     status.HTTP_200_OK)
            response.headers["X-Total-Count"] = 1
            response.headers["Content-Type"] = "application/json"

            return response

        except UserNotFoundException:
            error["message"] = "User not found."
            error["code"] = 404
            return jsonify(error=error), status.HTTP_404_NOT_FOUND

        except SessionidNotFoundException:
            error["message"] = "SessionID not found."
            error["code"] = 404
            return jsonify(error=error), status.HTTP_404_NOT_FOUND

        except AuthenticationFailed:
            error[
                "message"] = "Could not authenticate. Check your credentials."
            error["code"] = 401
            return jsonify(error=error), status.HTTP_401_UNAUTHORIZED
Example #4
0
def get_session(sessionid):
    '''
    Get information about the sessionid.
    
    TODO: Implement some kind of authentication and permission system here to 
    restrict access to retrieving user information from a sessionid.
    
    :param sessionid:
    :status 200: Successful request
    :status 400: Not JSON object or missing parameters
    :status 401: Wrong credentials
    :status 404: Sessionid does not exist
    '''

#     required_fields = ["sessionid"]
#     if not request.json or not (set(required_fields).issubset(request.json)): 
#         return jsonify({'message': 'Invalid request. Please try again.'}), status.HTTP_400_BAD_REQUEST
#     else:

    error = {}
    
    if not controller._is_uuid_valid(sessionid):
        error["message"] = "Invalid request." 
        error["code"] = 400
        return jsonify(error=error), status.HTTP_400_BAD_REQUEST
    
    else:
        session = {}
        inactive = False
        if ("inactive" in request.args):
            if request.args["inactive"].lower() == "true":
                inactive = True
        try:
            
            #############################
            # Success
            #############################
            
            gamingsession = controller.get_session(sessionid, inactive) 
            
            gamingsession_response = simplejson.dumps(gamingsession.as_hateoas(), indent=2)
            response = make_response(gamingsession_response, status.HTTP_200_OK)
            response.headers["X-Total-Count"] = 1
            response.headers["Content-Type"] = "application/json"
            
            return response

             
        except UserNotFoundException:
            error["message"] = "User not found." 
            error["code"] = 404
            return jsonify(error=error), status.HTTP_404_NOT_FOUND 
                
        except SessionidNotFoundException:
            error["message"] = "SessionID not found." 
            error["code"] = 404
            return jsonify(error=error), status.HTTP_404_NOT_FOUND 
      
        except AuthenticationFailed:
            error["message"] = "Could not authenticate. Check your credentials." 
            error["code"] = 401
            return jsonify(error=error), status.HTTP_401_UNAUTHORIZED