Exemplo n.º 1
0
def create_reservations(reservations: [Ticket]):
    """ Given a list of Tickets, insert a reservation for each ticket into the DB. """
    seq_of_parameters = [
        ReservationSchema(user_id=rsv.owner_id,
                          projection_id=rsv.projection_id,
                          row=rsv.row,
                          col=rsv.col) for rsv in reservations
    ]
    session.add_all(seq_of_parameters)
    session.commit()
def register(username, password, email):
    # hash the password
    user_salt = bcrypt.gensalt()
    hashed_password = bcrypt.hashpw(password.encode(), user_salt)
    new_user = Client(username=username, password=hashed_password, salt=user_salt, email=email)
    session.add(new_user)
    session.commit()  # to save the user and id
    invalid_logins = InvalidLogin(id_=new_user.id_, login_count=0)
    session.add(invalid_logins)
    session.flush()
    session.commit()
def generate_tan_codes(user):
    if len(user.tan_codes) == 0:
        tan_codes, success = send_tan_codes(user.email)
        # if not success:
        #     print('Something went wrong when creating your TAN codes.')
        #     return
        # self.__tan_codes = tan_codes
        tan_codes_to_save = []
        for tan_code in tan_codes:
            tan_codes_to_save.append(TanCode(user_id=user.id_, tan_code=tan_code))
        session.add_all(tan_codes_to_save)
        session.flush()
        session.commit()
    else:
        print('You still have {} TAN codes left.'.format(MAX_TAN_CODE_COUNT - len(user.tan_codes)))
Exemplo n.º 4
0
def save_character(character: Character):
    """
    Save the character into the database
    """
    character_info: SavedCharacterSchema = session.query(SavedCharacterSchema).filter_by(name=character.name).one_or_none()

    character_level: int = character.level  # type: int
    character_class: str = character.get_class()  # type: str
    character_gold: int = character.inventory['gold']  # type: int
    equipment: {str: int} = character.equipment
    headpiece_id: int = get_item_id_or_none(equipment[CHARACTER_EQUIPMENT_HEADPIECE_KEY])
    shoulderpad_id: int = get_item_id_or_none(equipment[CHARACTER_EQUIPMENT_SHOULDERPAD_KEY])
    necklace_id: int = get_item_id_or_none(equipment[CHARACTER_EQUIPMENT_NECKLACE_KEY])
    chestguard_id: int = get_item_id_or_none(equipment[CHARACTER_EQUIPMENT_CHESTGUARD_KEY])
    bracer_id: int = get_item_id_or_none(equipment[CHARACTER_EQUIPMENT_BRACER_KEY])
    gloves_id: int = get_item_id_or_none(equipment[CHARACTER_EQUIPMENT_GLOVES_KEY])
    belt_id: int = get_item_id_or_none(equipment[CHARACTER_EQUIPMENT_BELT_KEY])
    leggings_id: int = get_item_id_or_none(equipment[CHARACTER_EQUIPMENT_LEGGINGS_KEY])
    boots_id: int = get_item_id_or_none(equipment[CHARACTER_EQUIPMENT_BOOTS_KEY])

    character_values: {str: int or str} = {
        'name': character.name, 'character_class': character_class, 'level': character_level, 'gold': character_gold,
        'headpiece_id': headpiece_id, 'shoulderpad_id': shoulderpad_id, 'necklace_id': necklace_id,
        'chestguard_id': chestguard_id, 'belt_id': belt_id, 'bracer_id': bracer_id, 'gloves_id': gloves_id,
        'leggings_id': leggings_id, 'boots_id': boots_id}

    # if the character exists, update the row, otherwise create a new one
    if character_info:
        session.query(SavedCharacterSchema).filter_by(name=character.name).update(character_values)
    else:
        session.add(SavedCharacterSchema(**character_values))
    session.commit()

    # save the sub-tables
    char_entry = session.query(SavedCharacterSchema).filter_by(name=character.name).first().entry
    save_loaded_scripts(char_entry, character.loaded_scripts)
    save_killed_monsters(char_entry, character.killed_monsters)
    save_completed_quests(char_entry, character.completed_quests)
    save_inventory(char_entry, character.inventory)

    session.commit()
    print("-" * 40)
    print(f'Character {character.name} was saved successfully!')
    print("-" * 40)
Exemplo n.º 5
0
def save_character(character: Character):
    """
    Save the character into the database
    """
    character_info: SavedCharacterSchema = session.query(
        SavedCharacterSchema).filter_by(name=character.name).one_or_none()

    character_level: int = character.level  # type: int
    character_class: str = character.get_class()  # type: str
    character_gold: int = character.inventory['gold']  # type: int
    equipment: {str: int} = character.equipment
    headpiece_id: int = get_item_id_or_none(
        equipment[CHARACTER_EQUIPMENT_HEADPIECE_KEY])
    shoulderpad_id: int = get_item_id_or_none(
        equipment[CHARACTER_EQUIPMENT_SHOULDERPAD_KEY])
    necklace_id: int = get_item_id_or_none(
        equipment[CHARACTER_EQUIPMENT_NECKLACE_KEY])
    chestguard_id: int = get_item_id_or_none(
        equipment[CHARACTER_EQUIPMENT_CHESTGUARD_KEY])
    bracer_id: int = get_item_id_or_none(
        equipment[CHARACTER_EQUIPMENT_BRACER_KEY])
    gloves_id: int = get_item_id_or_none(
        equipment[CHARACTER_EQUIPMENT_GLOVES_KEY])
    belt_id: int = get_item_id_or_none(equipment[CHARACTER_EQUIPMENT_BELT_KEY])
    leggings_id: int = get_item_id_or_none(
        equipment[CHARACTER_EQUIPMENT_LEGGINGS_KEY])
    boots_id: int = get_item_id_or_none(
        equipment[CHARACTER_EQUIPMENT_BOOTS_KEY])

    character_values: {
        str: int or str
    } = {
        'name': character.name,
        'character_class': character_class,
        'level': character_level,
        'gold': character_gold,
        'headpiece_id': headpiece_id,
        'shoulderpad_id': shoulderpad_id,
        'necklace_id': necklace_id,
        'chestguard_id': chestguard_id,
        'belt_id': belt_id,
        'bracer_id': bracer_id,
        'gloves_id': gloves_id,
        'leggings_id': leggings_id,
        'boots_id': boots_id
    }

    # if the character exists, update the row, otherwise create a new one
    if character_info:
        session.query(SavedCharacterSchema).filter_by(
            name=character.name).update(character_values)
    else:
        session.add(SavedCharacterSchema(**character_values))
    session.commit()

    # save the sub-tables
    char_entry = session.query(SavedCharacterSchema).filter_by(
        name=character.name).first().entry
    save_loaded_scripts(char_entry, character.loaded_scripts)
    save_killed_monsters(char_entry, character.killed_monsters)
    save_completed_quests(char_entry, character.completed_quests)
    save_inventory(char_entry, character.inventory)

    session.commit()
    print("-" * 40)
    print(f'Character {character.name} was saved successfully!')
    print("-" * 40)
def consume_tan_code(tan_code):
    t_code = session.query(TanCode).filter_by(tan_code=tan_code)
    t_code.delete(synchronize_session='fetch')
    session.flush()
    session.commit()
def change_password(user, password):
    user_salt = user.salt
    hashed_password = bcrypt.hashpw(password.encode(), user_salt)
    user.password = hashed_password
    session.commit()
def save_db():
    session.commit()
Exemplo n.º 9
0
def cancel_reservation(cinema: Cinema, username: str):
    user = cinema.user
    _ = session.query(ReservationSchema).filter_by(user_id=user.id_).delete()
    session.flush()
    session.commit()
    print('You have successfully cancelled all your reservations!')