コード例 #1
0
def newEvent():
    username = appUtils.getUsernameFromVerification(request, gateway)
    if (not username):
        return Response("", status=301)

    req = request.json
    eventName = req.get("name")
    gameId = req.get("gameId")
    groupId = req.get("groupId")
    ends = req.get("ends")

    etime = 0
    if (appUtils.sanitize({ends})):
        etime = appUtils.createDate(ends)

    if (appUtils.sanitize({eventName, gameId, groupId}) and etime != None):
        gateway.newEvent(eventName, gameId, username, groupId, etime)
        return Response("", status=200)
    return Response("", status=400)
コード例 #2
0
def parseInvitations(eventId):
    username = appUtils.getUsernameFromVerification(request, gateway)
    if (not username):
        return Response("", status=301)

    req = request.json
    invitationStatus = req.get("status")
    if (appUtils.sanitize({invitationStatus, eventId})):
        gateway.parseInvitations(username, eventId, invitationStatus)
        return Response("", status=200)
    return Response("", status=400)
コード例 #3
0
def newuser():
    req = request.json
    username = req.get('username')
    password = req.get('password')

    if (appUtils.sanitize({username, password})):
        token = gateway.newUser(username, password)
        if (token != None):
            result = '{"bearer":"' + token + '"}'
            return Response(result, status=200, mimetype='application/json')
        return Response("", status=401)
    return Response("", status=400)
コード例 #4
0
def addComment():
    username = appUtils.getUsernameFromVerification(request, gateway)
    if (not username):
        return Response("", status=301)
    req = request.json

    eventId = req.get("eventId")
    targetId = req.get("targetId")
    content = req.get("content")
    if (appUtils.sanitize({eventId, targetId, content})):
        gateway.addComment(username, content, eventId, targetId)
        return Response("", status=200)
    return Response("", status=400)
コード例 #5
0
def updateEvent():
    username = appUtils.getUsernameFromVerification(request, gateway)
    if (not username):
        return Response("", status=301)

    req = request.json
    eventId = req.get('eventId')
    description = req.get('description')
    ends = req.get('date')
    optlower = req.get('optlower')
    optupper = req.get('optupper')

    etime = 0
    if (appUtils.sanitize({ends})):
        etime = appUtils.createDate(ends)

    if (appUtils.sanitize({description, optlower, optupper, eventId})
            and etime != None):
        gateway.updateEvent(username, eventId, description, etime, optlower,
                            optupper)
        return Response("", status=200)
    return Response("", status=400)
コード例 #6
0
def voteDate():
    username = appUtils.getUsernameFromVerification(request, gateway)
    if (not username):
        return Response("", status=301)

    req = request.json
    hours = []
    for i in range(0, 24):
        hour = req.get(str(i))
        if (hour != None):
            hours.append(i)
    eventId = req.get('eventId')
    date = req.get('date')

    etime = None
    if (appUtils.sanitize(date)):
        etime = appUtils.createDate(date)

    if (appUtils.sanitize(hours) and appUtils.sanitize(eventId)
            and etime != None):
        gateway.voteDate(username, eventId, date, hours)
        return Response("", status=200)
    return Response("", status=400)
コード例 #7
0
def inviteUserToEvent():
    username = appUtils.getUsernameFromVerification(request, gateway)
    if (not username):
        return Response("", status=400)
    req = request.json

    targetUser = req.get('targetuser')
    eventId = req.get('eventid')
    if (not appUtils.sanitize({targetUser, eventId})):
        return Response("", status=400)

    if (targetUser != None and eventId != None):
        gateway.inviteToEvent(username, targetUser, eventId)
        return Response("", status=200)
    return Response("", status=400)
コード例 #8
0
def joinGroup():
    username = appUtils.getUsernameFromVerification(request, gateway)
    if (not username):
        return Response("", status=400)
    req = request.json

    targetGroup = req.get('group')
    if (not appUtils.sanitize({targetGroup})):
        return Response("", status=400)

    if (targetGroup != None):
        result = gateway.joinGroup(username, targetGroup)
        if (result):
            return Response("", status=201)
        return Response("", status=200)
    return Response("", status=400)
コード例 #9
0
def parseRequest():
    username = appUtils.getUsernameFromVerification(request, gateway)
    if (not username):
        return Response("", status=400)
    req = request.json

    targetuser = req.get('user')
    targetgroup = req.get('group')
    accepted = req.get('accepted')

    if (appUtils.sanitize({targetuser, targetgroup, accepted})):
        if (int(accepted) == 1):
            gateway.addToGroup(username, targetuser, targetgroup)
            return Response("", status=200)
        else:
            print('not accepted')
    return Response("", status=400)
コード例 #10
0
def friendRequest():
    username = appUtils.getUsernameFromVerification(request, gateway)
    if (not username):
        return Response("", status=400)

    req = request.json
    friend = req.get('friend')
    accepted = req.get('accepted')

    if (appUtils.sanitize({friend, accepted})):
        if (len(friend) < 3):
            return Response("", status=203)
        if (int(accepted) == 1):
            gateway.newRelation(username, friend, 1)
        #else:
        #   gateway.removeRelation(friend, username)
    return Response("", status=200)
コード例 #11
0
def login():
    username = appUtils.getUsernameFromVerification(request, gateway)
    if (username != None):
        print(username + ' logged in')
        return Response("", status=200)

    req = request.json
    username = req.get('username')
    password = req.get('password')

    if (username == None or password == None):
        return Response("", status=401)

    if (appUtils.sanitize({username, password})):
        token = tryLogin(req["username"], req["password"])
        if (token != None):
            result = '{"bearer":"' + token + '"}'
            return Response(result, status=200, mimetype='application/json')
        return Response("", status=401)
    return Response("", status=400)