示例#1
0
def mymovies():

    # Get movies list
    metadata = MetaData(bind=engine)
    movies = Table('movie', metadata, autoload=True)

    # Redirect to index if not logged in
    if 'logged_in' not in session:
        return redirect(url_for('index'))

    movie_lists = Table('movie_lists', metadata, autoload=True)

    # Get movies list
    ml = movie_lists.select(
        movie_lists.c.username == session['username']).execute()

    movieIDArray = []
    for object in ml:
        movieIDArray.append(object['movieID'])

    moviesList = []
    for object in movieIDArray:
        moviesList += db.session.query(movies).filter(
            movies.c.movieID == object)

    return render_template('mymovies.html', movies=moviesList)
示例#2
0
def login():

    error = ''

    try:
        if request.method == "POST":
            # User has entered username
            attempted_username = request.form['inputUsername']
            attempted_password = request.form['inputPassword']

            # Check if user exists
            metadata = MetaData(bind=engine)
            users = Table('users', metadata, autoload=True)

            r = users.select(
                users.c.email == attempted_username).execute().first()

            if r['pw'] != attempted_password:
                error = "Invalid Password. Try again."
                return render_template('login.html', error=error)

            if r is not None:

                session['logged_in'] = True
                session['username'] = r['email']
                session['firstName'] = r['firstName']

                # Get movies list
                metadata = MetaData(bind=engine)
                movies = Table('movie', metadata, autoload=True)
                movie_lists = Table('movie_lists', metadata, autoload=True)
                ml = movie_lists.select(
                    movie_lists.c.username == session['username']).execute()

                movieIDArray = []
                for object in ml:
                    movieIDArray.append(object['movieID'])

                moviesList = []
                for object in movieIDArray:
                    moviesList += db.session.query(movies).filter(
                        movies.c.movieID == object)

                return render_template('mymovies.html',
                                       movies=moviesList,
                                       loginsuccess="true")

            else:
                error = "Invalid Credentials. Try again."

        return render_template('login.html', error=error)

    except Exception as e:
        error = 'Invalid credentials. Try again.'
        return render_template("login.html", error=error)
示例#3
0
def login():

    error = ''

    try:
        if request.method == "POST":
            # User has entered username
            attempted_username = request.form['inputUsername']
            attempted_password = request.form['inputPassword']

            # Check if user exists
            metadata = MetaData(bind=engine)
            users = Table('users', metadata, autoload=True)

            r = users.select(users.c.email == attempted_username).execute().first()

            if r['pw'] != attempted_password:
                error = "Invalid Password. Try again."
                return render_template('login.html', error=error)

            if r is not None:

                session['logged_in'] = True
                session['username'] = r['email']
                session['firstName'] = r['firstName']

                # Get movies list
                metadata = MetaData(bind=engine)
                movies = Table('movie', metadata, autoload=True)
                movie_lists = Table('movie_lists', metadata, autoload=True)
                ml = movie_lists.select(movie_lists.c.username == session['username']).execute()

                movieIDArray = []
                for object in ml:
                    movieIDArray.append(object['movieID'])

                moviesList = []
                for object in movieIDArray:
                    moviesList += db.session.query(movies).filter(movies.c.movieID == object)

                return render_template('mymovies.html', movies=moviesList, loginsuccess="true")

            else:
                error = "Invalid Credentials. Try again."

        return render_template('login.html', error=error)

    except Exception as e:
        error='Invalid credentials. Try again.'
        return render_template("login.html", error=error)
示例#4
0
def home():

    # Get friends list
    metadata = MetaData(bind=engine)
    movies = Table('movie', metadata, autoload=True)

    # Redirect to index if not logged in
    if 'logged_in' not in session:
        return redirect(url_for('index'))

    # Get friends list
    metadata = MetaData(bind=engine)
    friends = Table('friends', metadata, autoload=True)
    users = Table('users', metadata, autoload=True)
    movie_lists = Table('movie_lists', metadata, autoload=True)

    r = friends.select(friends.c.friend1 == session['username']).execute()

    friendArray = []
    for object in r:
        friendArray.append(object['friend2'])

    friends = []
    for object in friendArray:
        friends += db.session.query(users).filter(users.c.email == object)

    # Get movies list
    ml = movie_lists.select(
        movie_lists.c.username == session['username']).execute()

    movieIDArray = []
    for object in ml:
        movieIDArray.append(object['movieID'])

    moviesList = []
    for object in movieIDArray:
        moviesList += db.session.query(movies).filter(
            movies.c.movieID == object)

    if 'logged_in' not in session:
        return redirect(url_for('index'))

    return render_template('home.html', friends=friends, movies=moviesList)
示例#5
0
def home():

    # Get friends list
    metadata = MetaData(bind=engine)
    movies = Table('movie', metadata, autoload=True)

    # Redirect to index if not logged in
    if 'logged_in' not in session:
        return redirect(url_for('index'))

    # Get friends list
    metadata = MetaData(bind=engine)
    friends = Table('friends', metadata, autoload=True)
    users = Table('users', metadata, autoload=True)
    movie_lists = Table('movie_lists', metadata, autoload=True)

    r = friends.select(friends.c.friend1 == session['username']).execute()

    friendArray = []
    for object in r:
        friendArray.append(object['friend2'])

    friends = []
    for object in friendArray:
        friends += db.session.query(users).filter(users.c.email == object)

    # Get movies list
    ml = movie_lists.select(movie_lists.c.username == session['username']).execute()

    movieIDArray = []
    for object in ml:
        movieIDArray.append(object['movieID'])

    moviesList = []
    for object in movieIDArray:
        moviesList += db.session.query(movies).filter(movies.c.movieID == object)

    if 'logged_in' not in session:
        return redirect(url_for('index'))

    return render_template('home.html', friends=friends, movies=moviesList)
示例#6
0
def mymovies():

    # Get movies list
    metadata = MetaData(bind=engine)
    movies = Table('movie', metadata, autoload=True)

    # Redirect to index if not logged in
    if 'logged_in' not in session:
        return redirect(url_for('index'))

    movie_lists = Table('movie_lists', metadata, autoload=True)

    # Get movies list
    ml = movie_lists.select(movie_lists.c.username == session['username']).execute()

    movieIDArray = []
    for object in ml:
        movieIDArray.append(object['movieID'])

    moviesList = []
    for object in movieIDArray:
        moviesList += db.session.query(movies).filter(movies.c.movieID == object)

    return render_template('mymovies.html', movies=moviesList)