Ejemplo n.º 1
0
def route_login(invalid_login=False):
    if request.method == 'GET':
        return render_template('login.html', invalid_login=invalid_login)
    elif request.method == 'POST':
        username = request.form['username']
        plain_text_password = request.form['plain_text_password']

        if functions.username_exists(username):
            hashed_password = data_handler.get_hashed_password(username)
            if functions.verify_password(plain_text_password, hashed_password):
                session['username'] = username
                return redirect("/")
        return render_template('login.html', invalid_login=True)
Ejemplo n.º 2
0
def route_login():
    if request.method == 'GET':
        return render_template('login.html')

    username = request.form['username']
    plain_text_password = request.form['plain_text_password']

    if functions.username_exists(username):
        hashed_password = data_handler.get_hashed_password(username)
        if functions.verify_password(plain_text_password, hashed_password):
            session['username'] = username
            return redirect("/")
    error_message = 'Invalid username or password'
    return render_template('login.html', error_message=error_message)
Ejemplo n.º 3
0
def route_register():
    if request.method == 'GET':
        return render_template('register.html')

    username = request.form["username"]
    password = request.form["password"]
    password2 = request.form["password2"]

    if functions.username_exists(username):
        error_message = "The username you entered is already in use"
        return render_template('register.html', error_message=error_message)
    elif password != password2:
        error_message = "The passwords you entered did not match"
        return render_template('register.html', error_message=error_message)
    hash_password = functions.hash_password(password)
    data_handler.register_user(username, hash_password)
    return redirect("/")
Ejemplo n.º 4
0
def route_register():
    if request.method == 'GET':
        return render_template('register.html')

    if request.method == 'POST':
        username = request.form["username"]
        password = request.form["password"]
        password2 = request.form["password2"]

        if functions.username_exists(username):
            return render_template(
                'register.html',
                message="The username you entered is already in use")
        elif password != password2:
            return render_template(
                'register.html',
                message="Passwords do not match please fill again")
        else:
            hash_password = functions.hash_password(password)
            data_handler.register_user(username, hash_password)
            return redirect("/")
Ejemplo n.º 5
0
def user():
    uname = request.args.get('uname')

    if not functions.username_exists(uname):
        flash('User not found!')
        return redirect(url_for('home'))

    user_id = functions.get_id_of_username(uname)

    recipes = functions.get_recipes_of_user(user_id)
    for recipe in recipes:
        recipe['category_name'] = functions.get_category_name_by_id(
            recipe['category'])
        recipe['score'] = functions.get_score(recipe['id'])

    # TODO: add sorting
    '''
    sort_by = 'alpha'
    if request.method == "POST":
        sort_by = request.form.get("sortBy")
    recipes = functions.get_all_recipes(sort_by);
    '''

    likedrecipes = functions.get_likes_of_user(user_id)
    for recipe in likedrecipes:
        recipe['category_name'] = functions.get_category_name_by_id(
            recipe['category'])
        recipe['score'] = functions.get_score(recipe['id'])

    if 'logged_in' in session.keys() and session['logged_in'] == True:
        if (session['username'] == uname):
            0
    return render_template('user.html',
                           uname=uname,
                           recipes=recipes,
                           likedrecipes=likedrecipes)