Exemplo 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
Exemplo 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
Exemplo 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
Exemplo n.º 4
0
game9 = Game(datetime(2020, 10, 10, 13, 0))
game10 = Game(datetime(2020, 10, 12, 17, 0))
game11 = Game(datetime(2020, 10, 14, 20, 0))
game12 = Game(datetime(2020, 10, 15, 18, 0))

#6 - create users
user1 = User("GyozaCrumb", "password1")
user2 = User("socho", "password2")
user3 = User("corgo", "password3")
user4 = User("gabin", "password4")

league1.games = [game1, game2, game3, game4]
league2.games = [game5, game6, game7, game8]
league3.games = [game9, game10, game11, game12]

league1.members = [user1, user2, user3]
league2.members = [user1, user2, user3, user4]
league3.members = [user1, user3]

session.add(league1)
session.add(league2)
session.add(league3)

session.commit()
session.flush()
game1.winner = user1.id
game2.winner = user2.id
game3.winner = user1.id
session.commit()
session.close()