Example #1
0
def view_deck(username, deck, get_args):
    from collections import OrderedDict
    user = User.filter_by(username=username).first()
    deck = Deck.filter_by(user_id=user.id, name=deck).first()
    deck_dict = OrderedDict()

    priority_list = [
        'lands',
        'creatures',
        'artifacts',
        'enchantments',
        'planeswalkers',
        'instants',
        'sorceries'
    ]

    for card_type in priority_list:
        deck_dict.setdefault(card_type, [])
        for card, quantity in getattr(deck, card_type):
            already_added = False
            for ctype in priority_list[:priority_list.index(card_type)]:
                if (card, quantity) in deck_dict[ctype]:
                    already_added = True
                    break
            if not already_added:
                deck_dict[card_type].append((card, quantity))

    return custom_render('/views/view_deck.html', user=user, deck=deck, deck_dict=deck_dict)
Example #2
0
def login(username, password):
    if is_valid_login(username, password):
        user = User.filter_by(username=username).first()
        active_sessions = Session.filter_by(active=True, user_id=user.id).all()
        if active_sessions:
            for sess in active_sessions:
                sess.active = False
        session = Session()
        session.user_id = user.id
        session.create_date = datetime.now()
        session.expire_date = datetime.now() + timedelta(days=30)
        session.token = uuid4()
        session.insert()
        db.Session.commit()
        return session
    else:
        return None
Example #3
0
def is_valid_login(username, password):
    user = User.filter_by(username=username).first()
    if user:
        return sha256_crypt.verify(password, user.password)
    else:
        return False
Example #4
0
def view_users_decks(username, get_args):
    user = User.filter_by(username=username).first()
    if user:
        return custom_render('views/view_decks.html', user=user)
    else:
        abort(404)
Example #5
0
def account(username, get_args):
    user = User.filter_by(username=username).first()
    return custom_render('views/view_account.html', user=user)