Exemple #1
0
async def postUser(request):
    body = request.json

    if 'first_name' not in body and 'last_name' not in body and 'apn_token' not in body:
        return json_response({'error': Response.BadRequest}, status=400)

    body['session_token'] = Auth.GenerateSessionToken()
    user_id = db.insertUser(body)
    user = db.findUserById(user_id)

    return json_response({'user': user}, status=201)
Exemple #2
0
async def getUser(request, id):
    user = db.findUserById(id)
    if user == None:
        return json_response({'error': Response.NotFoundError}, status=404)

    if not Auth.ValidateUser(user, request):
        return json_response({'error': Response.InvalidUser}, status=400)

    newSessionToken = Auth.GenerateSessionToken()
    db.updateUserSessionToken(id, newSessionToken)
    user = db.findUserById(id)

    return json_response({'user': user}, status=200)