コード例 #1
0
def register():
    if request.method == 'POST':
        username = request.form['username']
        password = request.form['password']
        db = get_db()
        error = None

        if not username:
            error = 'Username is required'
        elif not password:
            error = 'Password is required'

        elif db.execute('SELECT id FROM user WHERE username = ?',
                        (username, )).fetchone() is not None:
            error = 'User {} is already registered.'.format(username)

        if error is None:
            db.execute('INSERT INTO user (username, password) VALUES (?,?)',
                       (username, generate_password_hash(password)))
            db.commit()
            return redirect(url_for('auth.login'))

        flash(error)

    return render_template('auth/register.html')
コード例 #2
0
ファイル: user.py プロジェクト: saikhurana98/SHOR
def change_details():

    if request.method == 'POST':
        db = get_db()
        user_details = db.execute('SELECT * FROM user;').fetchall()
        print(user_details)

        _name = request.form['name']
        #_address=request.form['address']
        #_contact=request.form['contact']
        #_email=request.form['email']
        print("Hi1")
        #If nothing has been entered into the fields, don't change the data
        if _name is not None:
            print("Hi2")
            print(_name)
            db.execute("UPDATE user SET name = '?' WHERE id = ?;", (
                _name,
                str(g.user),
            ))
            print("Hi3")
        """
        if not _address :
            db.execute("UPDATE user SET address={} WHERE id={}".format(_address, g.user))
        if not _contact :
            db.execute("UPDATE user SET contact={} WHERE id={}".format(_contact, g.user))
        if not _email :
            db.execute("UPDATE user SET email={} WHERE id={}".format(_email, g.user))
"""
    return render_template('user/user_profile.html')
コード例 #3
0
    def load_logged_in_user():
        user_id = session.get('user_id')

        if user_id is None:
            g.user = None
        else:
            g.user = get_db().execute('SELECT * FROM user WHERE id = ?',
                                      (user_id, )).fetchone()
コード例 #4
0
ファイル: user.py プロジェクト: saikhurana98/SHOR
def details():
    if g.user is not None:
        db = get_db()
        products = db.execute('SELECT * FROM user;').fetchall()
        return render_template('user/user_profile.html', products=products)
    else:
        return redirect(url_for(auth.login))
    return render_template('user/user_profile.html', products=products)
コード例 #5
0
ファイル: shop.py プロジェクト: saikhurana98/SHOR
def my_wishlist():
    """
    Get the prouct information and then template it out
    Extract unique codes from the user wishlist string
    Template out the product information
    """
    db = get_db()
    wishlist = db.execute('SELECT wishlist FROM user WHERE id = ?;',
                          (format(g.user['id']), )).fetchall()
    print(wishlist)
    wishlist_string = wishlist.split(",")
    wishlist_int = map(int, wishlist_string)
    return render_template('/shop/wishlist.html', products=wishlist_int)
コード例 #6
0
def login():
    if request.method == 'POST':
        username = request.form['username']
        password = request.form['password']
        db = get_db()
        error = None
        user = db.execute('SELECT * FROM user WHERE username = ?',
                          (username, )).fetchone()

        if user is None:
            error = 'Incorrect username'
        elif not check_password_hash(user['password'], password):
            error = 'Incorrect Password'

        if error is None:
            session.clear()
            session['user_id'] = user['id']
            return redirect(url_for('index'))

        flash(error)

    return render_template('auth/login.html')

    @bp.before_app_request
    def load_logged_in_user():
        user_id = session.get('user_id')

        if user_id is None:
            g.user = None
        else:
            g.user = get_db().execute('SELECT * FROM user WHERE id = ?',
                                      (user_id, )).fetchone()

    @bp.route('/logout')
    def logout():
        session.clear()
        return redirect(url_for('index'))

    def login_required(view):
        @functools.wrap(view)
        def wrapped_view(**kwargs):
            if g.user is None:
                return redirect(url_for('auth.login'))

            return view(**kwargs)

        return wrapped_view
コード例 #7
0
def login():
    if request.method == 'POST':
        username = request.form['username']
        password = request.form['password']
        db = get_db()
        error = None
        user= db.execute(
            'SELECT * FROM user WHERE username = ?', (username,)
        ).fetchone()

        if user is None:
            error = 'Incorrect username'
        elif not check_password_hash(user['password'],password):
            error = 'Incorrect Password'

        if error is None:
            session.clear()
            session['user_id'] = user['id']
            return redirect(url_for('index'))

        flash(error)

    return render_template('auth/login.html')
コード例 #8
0
ファイル: shop.py プロジェクト: saikhurana98/SHOR
def add_to_wishlist():
    _code = request.form['id']
    print(
        "Item code {} needs to be added to the user's wishlist".format(_code))
    if g.user is not None:
        db = get_db()
        wishlist = db.execute('SELECT wishlist FROM user WHERE id = 3')
        wishlist = wishlist.fetchall()
        wishlist = str(wishlist)
        wishlist = wishlist + format(_code)
        print("print 1 ", wishlist)
        print("print 1.5 id is {}".format(g.user['id']))
        wishlist2 = db.execute('UPDATE user SET wishlist = ? WHERE id = 3',
                               (wishlist, ))
        wishlist2 = wishlist2.fetchall()
        wishlist3 = db.execute(
            'SELECT wishlist FROM user WHERE id = 3').fetchall()

        print("print 2 ", str(wishlist3))
        return render_template('land/index.html')
    else:
        return redirect_url(url_for('auth.login'))
    #Validating the recieved values
    """
コード例 #9
0
ファイル: shop.py プロジェクト: saikhurana98/SHOR
def get_product(identity):
    product = get_db().execute('SELECT * FROM product WHERE id = (?);',
                               (str(identity))).fetchone()
    return product
コード例 #10
0
ファイル: shop.py プロジェクト: saikhurana98/SHOR
def contact():
    db = get_db()
    products = db.execute('SELECT * FROM product').fetchall()
    print(products)
    return render_template('shop/category.html', products=products)
コード例 #11
0
ファイル: shop.py プロジェクト: saikhurana98/SHOR
def add_product_to_cart():
    cursor = None
    try:
        _quantity = int(request.form['quantity'])
        _code = request.form['id']
        print("Code reaches here")
        #Validating the recieved values.
        if _quantity and _code and request.method == 'POST':
            print("1")
            db = get_db()
            print("2")
            row = db.execute('SELECT * FROM product WHERE id = {}'.format(
                _code)).fetchone()
            print("3")
            if row == None:
                print("999")
            print(row['code'])

            itemArray = {
                row['code']: {
                    'name': row['name'],
                    'code': row['code'],
                    'quantity': _quantity,
                    'price': row['price'],
                    'image': row['image'],
                    'total_price': _quantity * row['price']
                }
            }

            all_total_price = 0
            all_total_quantity = 0
            print("4")

            session.modified = True
            if 'cart_item' in session:
                print("5")
                print("in 5", session['cart_item'])
                if row['code'] in session['cart_item']:
                    print("6")
                    for key, value in session['cart_item'].items():
                        print('7')
                        if row['code'] == key:
                            print("8")
                            old_quantity = session['cart_item'][key][
                                'quantity']
                            total_quantity = old_quantity + _quantity
                            session['cart_item'][key][
                                'quantity'] = total_quantity
                            session['cart_item'][key][
                                'total_price'] = total_quantity * row['price']
                            print("9")
                else:
                    print("above 21", session['cart_item'])
                    print("itemarray above 21", itemArray)
                    session['cart_item'] = array_merge(session['cart_item'],
                                                       itemArray)
                    print("21")
                    print("after array merge ", session['cart_item'])

                print("22")
                print("in session ", session)
                print("in session", session['cart_item'])
                for key, value in session['cart_item'].items():
                    print("22.5")
                    individual_quantity = int(
                        session['cart_item'][key]['quantity'])
                    individual_price = float(
                        session['cart_item'][key]['total_price'])
                    all_total_quantity = all_total_quantity + individual_quantity
                    all_total_price = all_total_price + individual_price
                    print("23")
            else:
                session['cart_item'] = itemArray
                all_total_quantity = all_total_quantity + _quantity
                all_total_price = all_total_price + _quantity * row['price']
                print("25")

            session['all_total_quantity'] = all_total_quantity
            session['all_total_price'] = all_total_price
            return redirect(url_for('shop.cart'))

        else:
            return 'Error while adding item to cart'
    except Exception as e:
        print("Exception encountered!")
        print(e)
コード例 #12
0
def index():
    db = get_db()
    products = db.execute('SELECT * FROM product').fetchall()
    print(products)
    return render_template('land/index.html', products=products)