Ejemplo n.º 1
0
def reviews(productid):
    if 'username' in session:
        user = User(session['username'], session['email'], session['password'],
                    session['question'], session['answer'])
    else:
        user = None

    reviewsform = Reviews(request.form)
    conn = sqlite3.connect(os.path.join(file_directory, "storage.db"))
    c = conn.cursor()
    c.execute("SELECT rowid,* FROM products WHERE rowid={}".format(productid))
    product = c.fetchone()

    c.execute("SELECT * FROM reviews")
    reviews = c.fetchall()

    if request.method == "POST" and reviewsform.validate():
        c.execute("""INSERT INTO reviews VALUES ("{}", "{}", "{}")""".format(
            product[0], user.get_username(), reviewsform.reviews.data))
        conn.commit()
        return redirect(url_for('main.reviews', productid=productid))

    return render_template("main/Reviews.html",
                           user=user,
                           product=product,
                           reviews=reviews,
                           form=reviewsform)
Ejemplo n.º 2
0
def Profile():
    if 'username' in session:
        user = User(session['username'], session['email'], session['password'], session['question'], session['answer'])
        # get payment information if have
        conn = sqlite3.connect(os.path.join(file_directory, "storage.db"))
        c = conn.cursor()
        c.execute("SELECT * FROM paymentdetails WHERE username='******' ".format(user.get_username()))
        # self define paymentinformation and fetch one and return into payment information variable.
        paymentinformation = c.fetchone()
        # get all the 4 attribute from the PaymentInfo.py
        if paymentinformation:
            payment_details = PaymentInfo(paymentinformation[1], paymentinformation[2], paymentinformation[3],
                                          int(paymentinformation[4]))
        else:
            payment_details = PaymentInfo("", "", "", "")
    else:
        return redirect(url_for('user.signin'))

    payment_form = PaymentOptions(request.form)
    if request.method == "POST" and payment_form.validate():
        print("this code is running")
        conn = sqlite3.connect(os.path.join(file_directory, "storage.db"))
        c = conn.cursor()
        c.execute("SELECT * FROM paymentdetails WHERE username='******' ".format(user.get_username()))
        result = c.fetchone()
        if not result:
            c.execute("INSERT INTO paymentdetails VALUES ('{}','{}','{}','{}','{}')".format(user.get_username(),
                                                                                            payment_form.Name.data,
                                                                                            payment_form.CreditCardno.data,
                                                                                            payment_form.ExpiryDate.data,
                                                                                            payment_form.SecretNumber.data))
            conn.commit()
            conn.close()
            return redirect(url_for('user.Profile'))
        else:
            flash('Only can store 1 card detail')

    return render_template("user/Profile.html", user=user, form=payment_form, payment_details=payment_details)