def get_albums():
        session = DbSessionFactory.create_session()

        albums = session.query(Album) \
            .options(joinedload('tracks')) \
            .filter(Album.is_published) \
            .order_by(Album.year.desc()) \
            .all()

        return albums
Beispiel #2
0
    def get_albums():
        session = DbSessionFactory.create_session()

        albums = session.query(Album) \
            .options(joinedload('tracks')) \
            .filter(Album.is_published) \
            .order_by(Album.year.desc()) \
            .all()

        return albums
Beispiel #3
0
    def find_account_by_id(cls, user_id):
        if not user_id:
            return None

        session = DbSessionFactory.create_session()

        account = session.query(Account) \
            .filter(Account.id == user_id) \
            .first()

        return account
    def create_account(email, plain_text_password):
        session = DbSessionFactory.create_session()

        account = Account()
        account.email = email
        account.password_hash = AccountService.hash_text(plain_text_password)

        session.add(account)
        session.commit()

        return account
Beispiel #5
0
    def create_account(email, plain_text_password):
        session = DbSessionFactory.create_session()

        account = Account()
        account.email = email
        account.password_hash = AccountService.hash_text(plain_text_password)

        session.add(account)
        session.commit()

        return account
    def find_reset_code(cls, code):

        if not code or not code.strip():
            return None

        session = DbSessionFactory.create_session()
        reset = session.query(PasswordReset).\
            filter(PasswordReset.id == code).\
            first()

        return reset
Beispiel #7
0
    def __record_purchase(user_id: int, album_id: int,
                          amount_paid_usd: float, description: str):
        session = DbSessionFactory.create_session()

        purchase = AlbumPurchase()
        purchase.amount_paid = amount_paid_usd
        purchase.user_id = user_id
        purchase.album_id = album_id
        purchase.description = description

        session.add(purchase)
        session.commit()
Beispiel #8
0
    def find_account_by_email(cls, email):

        if not email or not email.strip():
            return None

        email = email.lower().strip()

        session = DbSessionFactory.create_session()

        account = session.query(Account) \
            .filter(Account.email == email) \
            .first()

        return account
    def find_account_by_email(cls, email):

        if not email or not email.strip():
            return None

        email = email.lower().strip()

        session = DbSessionFactory.create_session()

        account = session.query(Account) \
            .filter(Account.email == email) \
            .first()

        return account
    def set_password(cls, plain_text_password, account_id):
        print('Resetting password for user {}'.format(account_id))
        session = DbSessionFactory.create_session()

        account = session.query(Account). \
            filter(Account.id == account_id). \
            first()

        if not account:
            print("Warning: Cannot reset password, no account found.")
            return

        print("New password set.")
        account.password_hash = AccountService.hash_text(plain_text_password)
        session.commit()
    def create_album(cls, title: str, year: int, album_image: str,
                     price: float, url: str, track_titles: []):
        session = DbSessionFactory.create_session()

        album = Album(name=title, year=year, album_image=album_image, price=price,
                      url=url, is_published=True)

        session.add(album)

        for idx, title in enumerate(track_titles):
            track = Track(name=title, length=60, display_order=idx + 1)
            album.tracks.append(track)

        session.commit()
        return album
    def use_reset_code(cls, reset_code, user_ip):
        session = DbSessionFactory.create_session()

        reset = session.query(PasswordReset). \
            filter(PasswordReset.id == reset_code). \
            first()

        if not reset:
            return

        reset.used_ip_address = user_ip
        reset.was_used = True
        reset.used_date = datetime.datetime.now()

        session.commit()
    def create_reset_code(email):

        account = AccountService.find_account_by_email(email)
        if not account:
            return None

        session = DbSessionFactory.create_session()

        reset = PasswordReset()
        reset.used_ip_address = '1.2.3.4'  # set for real
        reset.user_id = account.id

        session.add(reset)
        session.commit()

        return reset
Beispiel #14
0
    def create_album(cls, title: str, year: int, album_image: str,
                     price: float, url: str, track_titles: []):
        session = DbSessionFactory.create_session()

        album = Album(name=title,
                      year=year,
                      album_image=album_image,
                      price=price,
                      url=url,
                      is_published=True)

        session.add(album)

        for idx, title in enumerate(track_titles):
            track = Track(name=title, length=60, display_order=idx + 1)
            album.tracks.append(track)

        session.commit()
        return album
Beispiel #15
0
    def get_album_by_id(cls, album_id):
        session = DbSessionFactory.create_session()

        return session.query(Album). \
            filter(Album.id == album_id) \
            .first()
Beispiel #16
0
 def get_purchased_album_ids(user_id: int):
     session = DbSessionFactory.create_session()
    def get_album_by_id(cls, album_id):
        session = DbSessionFactory.create_session()

        return session.query(Album). \
            filter(Album.id == album_id) \
            .first()