def process_login():
    """TODO: Receive the user's login credentials located in the 'request.form'
    dictionary, look up the user, and store them in the session."""
    email = request.form.get("email")
    password = request.form.get("password")
    if model.get_customer_by_email(email) == None:
        flash("Please contact ubermelon to sign up!")
    else:
        session['email'] = model.get_customer_by_email(email).email
        print session['email']
        flash("Successfully logged in!")

    return redirect("/melons")
Example #2
0
def process_login():
    """TODO: Receive the user's login credentials located in the 'request.form'
    dictionary, look up the user, and store them in the session."""
    email = request.form.get("email")
    if model.get_customer_by_email(email) is None:
        flash("You aren't a customer yet!")
    else:
        customer = model.get_customer_by_email(email)
        #next line is redundant, but not egregious - Lindsay
        first_name, last_name, email = customer.first_name, customer.last_name, customer.email
        session['customer'] = email
        flash("Logged in. Shop away!")
    return redirect ("/melons")
Example #3
0
def process_login():
    """TODO: Receive the user's login credentials located in the 'request.form'
    dictionary, look up the user, and store them in the session."""
    email = request.form.get("email")
    password = request.form.get("password")
    message = model.get_customer_by_email(email, password)
    return render_template("userpage.html", message=message)
Example #4
0
def shopping_cart():
    """TODO: Display the contents of the shopping cart. The shopping cart is a
    list held in the session that contains all the melons to be added."""
    if "cart" not in session or len(session["cart"])== 0 :
        flash("There is nothing in your cart.")
        return render_template("cart.html", display_cart = {}, total = 0)
    else:
        if "user" in session and session["logged_in"] == True:
            customer = model.get_customer_by_email(str(session["user"]))
            flash("Welcome, %s %s" % (customer.givenname, customer.surname))
        else:
            flash("That is an invalid login.")


        items = session["cart"]
        dict_of_melons = {}

        total_price = 0
        for item in items:
            #print(item,"#############")
            melon = model.get_melon_by_id(item)
            total_price += melon.price
            if melon.id in dict_of_melons:
                dict_of_melons[melon.id]["qty"] += 1
            else:
                dict_of_melons[melon.id] = {"qty":1, "name": melon.common_name, "price":melon.price}
        print(dict_of_melons)
        return render_template("cart.html", display_cart = dict_of_melons, total = total_price)  
def process_login():
    """TODO: Receive the user's login credentials located in the 'request.form'
    dictionary, look up the user, and store them in the session."""

    session.clear() # to clear up the session

    if request.method == "POST":

        #print request.form

        session['username'] = request.form['user_email']
        session['password'] = request.form['password']
        print session

    email = session['username']

    check_email = model.get_customer_by_email(email)

    print check_email

    if not check_email:
        flash('Sorry, invalid email address / password.')
    else:
        flash('Successfully logged in! Welcome to Ubermelon!')
        return redirect(url_for('list_melons'))

    return render_template("login.html")
Example #6
0
def process_login():
    """TODO: Receive the user's login credentials located in the 'request.form'
    dictionary, look up the user, and store them in the session."""

    row = model.get_customer_by_email(request.form.get('email'))
    if row:
        session['customer'] = row
        flash("Log in successful")

    return redirect("/melons")
Example #7
0
def process_login():
    """TODO: Receive the user's login credentials located in the 'request.form'
    dictionary, look up the user, and store them in the session."""

    f = request.form

    user_email = f.get('email')
    print(model.get_customer_by_email(user_email))
    customer = model.get_customer_by_email(user_email)

    if customer == None:
        print "You're not in the database!"
        flash("You're not in the database!")
    else:
        session['name'] = customer.firstname
        flash("You've successfully logged on! Yay!")


    return redirect("/melons")
Example #8
0
def process_login():
    """TODO: Receive the user's login credentials located in the 'request.form'
    dictionary, look up the user, and store them in the session."""
    #  test with emails in database:  [email protected], [email protected]
    if 'login' not in session:
        session['login']={}
    user_email = request.form.get("email")
    pwd = request.form.get("password")
    customer = model.get_customer_by_email(user_email)
    email, f_name, l_name = customer[0],customer[1],customer[2]
    flash("Welcome " +f_name+ " " +l_name+ ".")
    return redirect("/melons")
Example #9
0
def process_login():
    """TODO: Receive the user's login credentials located in the 'request.form'
    dictionary, look up the user, and store them in the session."""
    cust_email =  str(request.form["email"])
    customer = model.get_customer_by_email(cust_email)
    if customer == None:
        return "You are not in the customer database"
    #return "You entered username: %s and password: %s" % (request.form["email"], request.form["password"])
    else:
        session["customer"] = [customer.email, customer.givenname, customer.surname]
        flash("You've Successfully logged in.")
        return redirect("/melons")
Example #10
0
def list_melons():
    """This is the big page showing all the melons has to offer"""
    melons = model.get_melons()
    print(session,"########")
    if "user" in session and session["logged_in"] is True:
        customer = model.get_customer_by_email(str(session["user"]))
        flash("Welcome, %s %s" % (customer.givenname, customer.surname))

    else:
        flash("That is an invalid login.")
    return render_template("all_melons.html",
                           melon_list = melons)
Example #11
0
def process_login():
    """TODO: Receive the user's login credentials located in the 'request.form'
    dictionary, look up the user, and store them in the session."""

    user_email = request.form.get("email")
    user_password = request.form.get("password")
    user_info = model.get_customer_by_email(user_email)

    if user_info:
        session["user"] = user_info
        flash("Login Successful")

    return redirect("/melons")
Example #12
0
def process_login():
    """TODO: Receive the user's login credentials located in the 'request.form'
    dictionary, look up the user, and store them in the session."""
    email = request.form["email"]
    password = request.form["password"]
    customer = model.get_customer_by_email(email)

    if not customer:
        flash("Sorry! Login Error.")
        return redirect("/login")

    session['user'] = customer.givenname
    return redirect("/melons")
Example #13
0
def process_login():
    """user enters email ,used to look up customer in DB."""
    form_email = request.form['email']
    """setting variable customer object to result of calling get_customer_by_email method from model"""
    customer = model.get_customer_by_email(form_email)
    if customer:
        """setting session to customer givenname to be used on base.html"""
        session["cust"] = customer.givenname
        flash("Login successful.  Welcome back!")
        return redirect("/melons")
    else:
        flash("No such email in our customer database. Please re-enter.")
        return redirect("/login")
Example #14
0
def process_login():
    """TODO: Receive the user's login credentials located in the 'request.form'
    dictionary, look up the user, and store them in the session."""
    if request.method == 'POST':
        user_email = request.form.get('email')

    customer = model.get_customer_by_email(user_email)

    if 'user' not in session:
        session['user'] = customer.givenname

    flash("Successfully logged in!")
    return redirect("/melons")
Example #15
0
def process_login():
    """TODO: Receive the user's login credentials located in the 'request.form'
    dictionary, look up the user, and store them in the session."""

    username = request.form['username']
    customer = model.get_customer_by_email(username)
    if customer:
        session['user'] = [customer.givenname, customer.surname]
        flash("Successfully logged in")
        return redirect("/melons")
    else:
        flash("Account not found.")
        return redirect("/login")
def process_login():
    """TODO: Receive the user's login credentials located in the 'request.form'
    dictionary, look up the user, and store them in the session."""
    email = request.form["email"]
    password = request.form["password"]
    customer = model.get_customer_by_email(email)

    if not customer:
        flash("Sorry! Login Error.")
        return redirect("/login")

    session['user'] = customer.givenname
    return redirect("/melons")
Example #17
0
def process_login():
    """TODO: Receive the user's login credentials located in the 'request.form'
    dictionary, look up the user, and store them in the session.
    test email: [email protected], [email protected]
    """
    error = None
    email = request.form['email']
    customer = model.get_customer_by_email(email)
    if customer:
        session['username'] = customer.first_name
        return redirect("/melons")
    else:
        error = 'Invalid username/password.'
    return render_template('login.html', error = error)
def process_login():
    """TODO: Receive the user's login credentials located in the 'request.form'
    dictionary, look up the user, and store them in the session."""
    
    email = request.form.get('email')
    customer = model.get_customer_by_email(email)

    if customer:
        if 'users' in session:
            if customer.email not in session['users']:
               session['users'] = {customer.email: customer.password}
               print session['users']
    
    # flash("Login Successful")
    return redirect("/melons")
Example #19
0
def process_login():
    email = request.form.get("email")
    password = request.form.get("password")
    customer = model.get_customer_by_email(email)

    if customer == None:
        flash ("This customer is not registered yet")
        return redirect(url_for('process_login'))
    else:
        session['email'] = customer.email
        session['givenname'] = customer.givenname
        session['lastname'] = customer.surname
        session['loggedIn'] = "yes"
        flash("Hello " + customer.givenname + " " + customer.surname + "!")
        return redirect(url_for('list_melons'))
Example #20
0
def process_login():
    print "this is running"
    email = request.form['email']
    password = request.form['password']
    print email
    print password
    in_db = model.get_customer_by_email(email)
    print in_db
    if 'customer' not in session:
        session['customer'] = {}
        session['customer'] = email
    print session
    flash(email + " is logged in.")
    """TODO: Receive the user's login credentials located in the 'request.form'
    dictionary, look up the user, and store them in the session."""
    return redirect("/melons")
Example #21
0
def process_login():
    """TODO: Receive the user's login credentials located in the 'request.form'
    dictionary, look up the user, and store them in the session."""
    
    if request.method == "POST": 
        input_email = request.form['email']
        print "input email is %r" % input_email

        customer = model.get_customer_by_email(input_email)
   
        if input_email == customer.email:
            session["givenname"] = customer.givenname
        print "********************************************"
        print session 

    return redirect(url_for("list_melons"))
Example #22
0
def process_login():
    email = request.form.get('email')
    password = request.form.get('password')
    user = model.get_customer_by_email(email)

    if user and password == user.password:
        flash("Welcome " + user.givenname +
              "! You have successfully logged in.")
        session['name'] = user.givenname

    else:
        flash("Oops, please check you login information again")
        return render_template("login.html")
    """TODO: Receive the user's login credentials located in the 'request.form'
    dictionary, look up the user, and store them in the session."""
    return list_melons()
Example #23
0
def process_login():
    """TODO: Receive the user's login credentials located in the 'request.form'
    dictionary, look up the user, and store them in the session."""

    email = request.form.get("email")
    customer = model.get_customer_by_email(email)
    # print customer

    if not customer:
        flash("Username or password is wrong. Please try again.")
        return redirect("/login")
    else:
        flash("Welcome back!")
        session["customer"] = customer
        print session
        return redirect("/melons")
Example #24
0
def process_login():
    username = request.form.get("email")
    password = request.form.get("password")
    #Stores username, password collected from form and checks against Db.
    cname = model.get_customer_by_email(username)
    print cname.givenname

    #if user exist in Db, sends them to logged in session, otherwise 
    #sends them to melons page
    if cname != None:
        session['email'] = cname.email
        print session['email']
        flash("Successfully logged in %s" % cname.email)
    return redirect("/melons")

    return "Oops! This needs to be implemented"
Example #25
0
def process_login():
    """TODO: Receive the user's login credentials located in the 'request.form'
    dictionary, look up the user, and store them in the session."""

    email = request.form.get("email")
    password = request.form.get("password")

    customer = model.get_customer_by_email(email)

    if customer:
        session["customer"] = customer # {'username': username, 'email': email}
        flash("Successfully logged in")
        return redirect("/melons")
    else:
        flash("Username not found")
        return redirect("/login")
Example #26
0
def process_login():
    """See if email associated with the log in is in the Customer DB, then store them in a session."""
    
    if request.method == "POST": 
        input_email = request.form['email']
        print "input email is %r" % input_email

        customer = model.get_customer_by_email(input_email)
   
        if customer is not None:
            session["givenname"] = customer.givenname
        else:
            flash("Error, customer doesn't exist")
            return redirect(url_for("show_login"))
            
        print "********************************************"
        print session 

    return redirect(url_for("list_melons"))
def process_login():
    """TODO: Receive the user's login credentials located in the 'request.form'
    dictionary, look up the user, and store them in the session."""

    email = request.form.get("email")
    password = request.form.get("password")

    customer = model.get_customer_by_email(email)

    if customer and password == customer.password:
        session["customer"] = [str(customer.first_name), str(customer.last_name), str(customer.email)]
        flash ("Welcome %s!" % str(customer.first_name))
        return redirect("/melons")
    elif customer and password != customer.password:
        flash ("Incorrect password.")
        return redirect("/login")
    else:
        flash ("Please register with Ubermelon")
        return redirect("/login")
def process_login():
    """TODO: Receive the user's login credentials located in the 'request.form'
    dictionary, look up the user, and store them in the session."""
    
    email = request.form.get("email")
    password = request.form.get("password")

    customer = model.get_customer_by_email(email,password)
    print customer

    if customer == None:
        flash("No user found for that email/password combination.")
        return redirect("/login")
    else:   # Is there need for a logged_in = True?
        session["current_user"] = { "logged_in": True,
                                    "customer_id": customer.id,
                                    "first_name": customer.first,
                                    "last_name": customer.last}
        flash("Welcome, " + session["current_user"]["first_name"] + ".")
        return redirect("/melons")
Example #29
0
def process_login():
    """TODO: Receive the user's login credentials located in the 'request.form'
    dictionary, look up the user, and store them in the session."""
    if session.get("customer", None) is not None:
        flash("Log out before logging in again!")
        return redirect("/login")
    else:
        email = request.form.get("email")
        password = request.form.get("password")
        customer = model.get_customer_by_email(email)
        if customer is None:
            flash("You don't exist!")
            return redirect("/login")
        if password == customer.password: #successful login case
            flash("Welcome, %s!" % customer.givenname)
            session["customer"] = (customer.givenname, customer.email, customer.password)
            return redirect("/melons")
        else:
            flash("Incorrect email or password.")
            return redirect("/login")
Example #30
0
def process_login():
    """TODO: Receive the user's login credentials located in the 'request.form'
    dictionary, look up the user, and store them in the session."""
    session["logged_in"] = False
    email = request.form.get("email")
    # password = request.form.get("password")
    customer = model.get_customer_by_email(email)

    if customer:
        flash("Welcome, %s %s" % (customer.givenname, customer.surname))
        if "user" in session:
            session["logged_in"] = True
        else:
            session["user"] = email
            session["logged_in"] = True
        return redirect("/melons")
    else:
        flash("That is an invalid login.")
        session["logged_in"] = False
        return render_template("login.html")
Example #31
0
def process_login():
    """TODO: Receive the user's login credentials located in the 'request.form'
    dictionary, look up the user, and store them in the session."""
    session["logged_in"] = False
    email = request.form.get("email")
    # password = request.form.get("password")
    customer = model.get_customer_by_email(email)

    if customer:
        flash("Welcome, %s %s" % (customer.givenname, customer.surname))
        if "user" in session:
            session["logged_in"] = True
        else:
            session["user"] = email
            session["logged_in"] = True
        return redirect("/melons")
    else:
        flash("That is an invalid login.")
        session["logged_in"] = False
        return render_template("login.html")
Example #32
0
def process_login():
    """TODO: Receive the user's login credentials located in the 'request.form'
    dictionary, look up the user, and store them in the session."""

    email = request.form.get("email")
    password = request.form.get("password")
    customer = model.get_customer_by_email(email)

    if customer == None:
        flash("No user with this email exists!")
        return render_template("login.html")
    else:
        if password != customer.password:
            flash("Incorrect password. Please try again.")
            return render_template("login.html")
        else:
            session["user"] = {
                "name": customer.name,
                "email": customer.email,
                "password": customer.password
            }
            g.display = session["user"]["name"]
            flash("Login successful!")
            return redirect("/melons")
Example #33
0
def process_login():
    """TODO: Receive the user's login credentials located in the 'request.form"""
    email = request.form.get("email")
    password = request.form.get("password")

    cust = model.get_customer_by_email(email)

    if cust == None:
        flash('Login Unsuccessful')
        return render_template("login.html")
    else:
        session["cust"] = cust.givenname

    # cust = model.Customer(email, password)
    # print cust.email, cust.password

    # if not 'login' in session:
    #     session['login'] = {}
    # if email not in session['login']:
    #     session['login'][email]=password
    #     print "yes!"
    #     print session['login']

    return render_template("index.html")