Exemplo n.º 1
0
def set_user_fav_team():
    data = request.values
    headers = request.headers

    print("Client ID = " + headers['clientID'])
    print("API key = " + headers['apiKey'])

    clientID = ''
    apiKey = ''

    # used to validate id the headers are being passed or not
    if all(header in headers for header in ("clientID", "apiKey")):
        clientID = headers['clientID']
        apiKey = headers['apiKey']
    else:
        print("HEADERS DO NOT EXIST")
    # authenticate the clientID
    if auth.authenticate_client(clientID, apiKey):
        print("Client is authenticated - proceed")
        favTeam = {'uuid': data['uuid'], 'favTeam': data['favTeam']}
        if db.insertIntoCollection("userteams", favTeam):
            return jsonify({'status': True, 'user': data['uuid'], 'favTeam': data['favTeam']}), 201
        else:
            return jsonify({'status': False, 'message': 'There was an error adding the new user.'}), 400
    else:
        return jsonify({'status': False, 'message': 'The request was made from a non-authenticated client'}), 400
Exemplo n.º 2
0
def register_game():
    dbEntry = db.insertIntoCollection('competitions', request.json)
    return jsonify({
        'status': True,
        'message': 'Game insertion successful.',
        'gameid': str(dbEntry.inserted_id)
    }), 201
Exemplo n.º 3
0
def register_user():
    # TODO
    dbEntry = db.insertIntoCollection('users', request.json)
    return jsonify({
        'status': True,
        'message': 'User insertion successful.',
        'userid': str(dbEntry.inserted_id)
    }), 201
Exemplo n.º 4
0
def addGame():
    data = request.values
    headers = request.headers

    print("adminAPI -> addGame()")

    if auth.authenticate_client(headers['clientID'], headers['apiKey']):
        if config['GENERAL']['authentication'] == "ON":
            try:
                jwt.decode(headers['x-access-token'],
                           config['JWT']['JWT_SECRET'],
                           config['JWT']['JWT_ALGORITHM'])
            except jwt.exceptions.DecodeError:
                return jsonify({
                    'status': False,
                    'message': 'Invalid client token'
                }), 400
            except jwt.exceptions.ExpiredSignature:
                return jsonify({
                    'status': False,
                    'message': 'Token has expired'
                }), 400

        _UUID = str(uuid.uuid4())
        currDate = datetime.datetime.now()
        game = {
            'uuid': _UUID,
            'season': data['season'],
            'homeTeamId': data['homeTeamId'],
            'awayTeamId': data['awayTeamId'],
            'field': {
                'name': data['fieldName'],
                'address': data['fieldAddress'],
                'latt': data['fieldLatt'],
                'logt': data['fieldLogt']
            },
            'date': data['date'],
            'hour': data['hour'],
            'description': data['description'],
            'result': data['result'],
            'createdAt': currDate,
            'modifiedAt': currDate
        }

        if db.insertIntoCollection("games", game):
            return jsonify({'status': True, 'gameId': _UUID}), 201
        else:
            return jsonify({
                'status': False,
                'message': 'There was an error adding the new game.'
            }), 400
    else:
        return jsonify({
            'status':
            False,
            'message':
            'The request was made from a non-authenticated client'
        }), 400
Exemplo n.º 5
0
def addPlayer():
    data = request.values
    headers = request.headers

    if auth.authenticate_client(headers['clientID'], headers['apiKey']):
        if config['GENERAL']['authentication'] == "ON":
            try:
                jwt.decode(headers['x-access-token'],
                           config['JWT']['JWT_SECRET'],
                           config['JWT']['JWT_ALGORITHM'])
            except jwt.exceptions.DecodeError:
                return jsonify({
                    'status': False,
                    'message': 'Invalid client token'
                }), 400
            except jwt.exceptions.ExpiredSignature:
                return jsonify({
                    'status': False,
                    'message': 'Token has expired'
                }), 400

        _UUID = str(uuid.uuid4())
        currDate = datetime.datetime.now()
        player = {
            'uuid': _UUID,
            'name': data['name'],
            'nick': data['nick'],
            'email': data['email'],
            'picture': data['picture'],
            'mobile': data['mobile'],
            'position': data['position'],
            'description': data['description'],
            'actualTeam': data['teamId'],
            'parentId': data['parentId'],
            'createdAt': str(currDate),
            'modifiedAt': str(currDate)
        }
        if db.insertIntoCollection("players", player):
            return jsonify({'status': True, 'playerId': _UUID}), 201
        else:
            return jsonify({
                'status':
                False,
                'message':
                'There was an error adding the new player.'
            }), 400
    else:
        return jsonify({
            'status':
            False,
            'message':
            'The request was made from a non-authenticated client'
        }), 400
Exemplo n.º 6
0
def addSeason():
    data = request.values
    headers = request.headers

    if auth.authenticate_client(headers['clientID'], headers['apiKey']):
        if config['GENERAL']['authentication'] == "ON":
            try:
                jwt.decode(headers['x-access-token'],
                           config['JWT']['JWT_SECRET'],
                           config['JWT']['JWT_ALGORITHM'])
            except jwt.exceptions.DecodeError:
                return jsonify({
                    'status': False,
                    'message': 'Invalid client token'
                }), 400
            except jwt.exceptions.ExpiredSignature:
                return jsonify({
                    'status': False,
                    'message': 'Token has expired'
                }), 400

        _UUID = str(uuid.uuid4())
        currDate = datetime.datetime.now()
        season = {
            'uuid': _UUID,
            'name': data['name'],
            'createdAt': str(currDate),
            'modifiedAt': str(currDate)
        }

        if db.insertIntoCollection("seasons", season):
            return jsonify({'status': True, 'seasonId': _UUID}), 201
        else:
            return jsonify({
                'status':
                False,
                'message':
                'There was an error adding the new season.'
            }), 400
    else:
        return jsonify({
            'status':
            False,
            'message':
            'The request was made from a non-authenticated client'
        }), 400
Exemplo n.º 7
0
def registration():
    data = request.values
    headers = request.headers

    print("Receiving request to register a new User => " + data['email'])
    print("Client ID = " + headers['clientID'])
    print("API key = " + headers['apiKey'])

    clientID = ''
    apiKey = ''

    # used to validate id the headers are being passed or not
    if all(header in headers for header in ("clientID", "apiKey")):
        clientID = headers['clientID']
        apiKey = headers['apiKey']
    else:
        print("HEADERS DO NOT EXIST")

    # authenticate the clientID
    if auth.authenticate_client(clientID, apiKey):
        print("Client is authenticated - proceed")
        if db.checkUserEmail(data['email']):
            return jsonify({'status': False, 'message': 'This user email has already been registered previously.'}), 400
        else:
            password = str(bcrypt.hashpw(
                bytes(data['password'], 'utf-8'), bcrypt.gensalt()), 'utf8')

            _UUID = str(uuid.uuid4())
            currDate = datetime.datetime.now()
            user = {'uuid': _UUID, 'name': data['name'], 'email': data['email'], 'password': password,
                    'description': data['description'], 'type': data['type'], 'createdAt': str(currDate),
                    'modifiedAt': str(currDate)}
            if db.insertIntoCollection("users", user):
                return jsonify({'status': True, 'userId': _UUID}), 201
            else:
                return jsonify({'status': False, 'message': 'There was an error adding the new user.'}), 400
    else:
        return jsonify({'status': False, 'message': 'The request was made from a non-authenticated client'}), 400