Пример #1
0
def rebuildTokens(context, request):
    """
        Rebuild tokens

        Move any user that has old style tokens to the new tokens collection
    """
    # Find all users with tokens
    users_with_tokens = request.db.db.users.find({'$or': [{'iosDevices.0': {'$exists': True}}, {'androidDevices.0': {'$exists': True}}]})

    platforms = [
        ('ios', 'iosDevices'),
        ('android', 'androidDevices')
    ]

    for user in users_with_tokens:
        for platform, oldfield in platforms:
            tokens = user.get(oldfield, [])

            for token in tokens:
                newtoken = Token.from_object(request, {
                    'platform': platform,
                    'token': token,
                    'objectId': 'token',
                    '_owner': user['username'],
                    '_creator': user['username'],
                })
                newtoken.setDates()
                newtoken.insert()

    # Clean old token fields
    request.db.db.users.update({}, {'$unset': {'iosDevices': '', 'androidDevices': ''}}, multi=True)

    handler = JSONResourceRoot(request, [])
    return handler.buildResponse()
Пример #2
0
def add_device_token(tokens, request):
    """
        Adds a user device token

        Adds a new user device linked to a user. If the token already exists for any user, we'll assume that the new
        user is using the old user's device, so we'll delete all the previous tokens and replace them with the new one.
    """
    newtoken = Token.from_request(request)

    if '_id' in newtoken:
        newtoken.delete()
        newtoken = Token.from_request(request)

    # insert the token always
    newtoken.insert()

    handler = JSONResourceEntity(request, newtoken.flatten(), status_code=201)
    return handler.buildResponse()
Пример #3
0
def add_device_token(tokens, request):
    """
        Adds a user device token

        Adds a new user device linked to a user. If the token already exists for any user, we'll assume that the new
        user is using the old user's device, so we'll delete all the previous tokens and replace them with the new one.

        16/07/2018 Si este WS nos devuelve un 404 y no entra, es que no tenemos en el nginx del max el /tokens
                   la nueva APP Utalk lo utiliza
                   la antigua utiliza el fix_deprecated_add_token
                   POST /people/{username}/device/{platform}/{token}
    """
    newtoken = Token.from_request(request)

    if '_id' in newtoken:
        newtoken.delete()
        newtoken = Token.from_request(request)

    # insert the token always
    newtoken.insert()

    handler = JSONResourceEntity(request, newtoken.flatten(), status_code=201)
    return handler.buildResponse()