Ejemplo n.º 1
0
def league_data(user_id):
    res = {'success': False, 'data': {}}

    session = Session()
    users = session.query(User).filter(User.id == user_id).all()

    if len(users) != 0:
        league_data = users[0].leagues

        league_ids = [league.id for league in league_data]
        league_info = extract_league_info(league_data)
        league_games = extract_league_games(league_data)
        user_ids = {
            member.id
            for league in league_data for member in league.members
        }
        all_relevant_users = session.query(User).filter(
            User.id.in_(user_ids)).all()
        user_data = extract_user_data(all_relevant_users)

        data = {
            'myLeagues': league_ids,
            'leagueInfo': league_info,
            'leagueGames': league_games,
            'userData': user_data
        }

        res['success'] = True
        res['data'] = data

    session.close()
    return res
Ejemplo n.º 2
0
def login_user(username, password):
    session = Session()
    users = session.query(User).filter(User.username == username).all()
    token = ''
    if len(users) != 0:
        user = users[0]
        if (user.check_password(password)):
            token = user.encode_auth_token()

    session.close()
    return token
Ejemplo n.º 3
0
def register_user(username, password):
    if (len(username) < 5):
        return False
    if (len(password) < 6):
        return False

    session = Session()
    users = session.query(User).filter(User.username == username).all()

    unique_name = len(users) == 0

    if unique_name:
        new_user = User(username, password)
        session.add(new_user)
        session.commit()

    session.close()
    return unique_name
Ejemplo n.º 4
0
# coding=utf-8

from app.models.base import Session
from app.models.game import Game
from app.models.user import User
from app.models.league import League

session = Session()

users = session.query(User).delete()
leagues = session.query(League).delete()

session.commit()
Ejemplo n.º 5
0
# coding=utf-8

from app.models.base import Session
from app.models.user import User
from app.models.game import Game
from app.models.league import League

session = Session()

# print leagues
leagues = session.query(League).all()

print('\n### All leagues:')
for league in leagues:
    print(f'{league.id}, {league.league_name}, {league.game_name}')
    for game in league.games:
        print(f'\t{game.date}')
    for user in league.members:
        print(f'\t{user.username}')
print('')

# print games
games = session.query(Game).all()

print('\n### All games:')
for game in games:
    print(f'{game.date}, {game.winner}')
print('')

# print users
users = session.query(User).all()