def addtocart(user, id): db = get_dbincart() error = None if get(id, user) is not None: error = 'Product is already in Cart.' if error is None: db.execute('INSERT INTO incart (product_id,cart_id) VALUES (?,?)', (id, getuser_id(user)['id'])) db.commit() db.close() error = "Added to cart" return error
def register(): if request.method == 'POST': Pattern = re.compile("(0/91)?[7-9][0-9]{9}") username = request.form['username'] password = request.form['password'] email = request.form['email'] card_number = request.form['card_number'] card_expire_date = request.form['card_expire_date'] address = request.form['address'] phone_number = request.form['phone_number'] error = None if not username: error = 'Username is required.' elif not password: error = 'Password is required.' elif not email: error = 'Email is required.' # elif not validate_email(email): # error = 'Invalid Email' elif not phone_number: error = 'Phone Number is required.' elif not Pattern.match(phone_number): error = 'Invalid Phone Number' elif not card_number: error = 'Card Number is required.' elif not card_expire_date: error = 'Card Expire Date is required.' elif not address: error = 'Address is required.' elif db_user.getuser_id(username) is not None: error = 'Username {} is already registered.'.format(username) elif db_user.getuser_id_from_email(email) is not None: error = 'Email {} is already registered.'.format(email) if error is None: user = { 'username': username, 'email': email, 'password': generate_password_hash(password), 'card_number': card_number, 'card_expire_date': card_expire_date, 'address': address, 'phone_number': phone_number } db_user.register_user(user) return redirect(url_for('login.login')) flash(error) return render_template('auth/register.html')
def getincart(user): return get_db().execute( 'SELECT product_id FROM order_id WHERE user_id = ?', (getuser_id(user)['id'], )).fetchall()
def getcount(user): return get_db().execute('SELECT COUNT(*) FROM order_id WHERE user_id = ?', (getuser_id(user)['id'], )).fetchone()
def delete_incart(user, id): db = get_dbincart() db.execute('DELETE FROM incart WHERE (product_id,cart_id) = (?,?)', (id, getuser_id(user)['id'])) db.commit() db.close()
def getcount(user): return get_dbincart().execute( 'SELECT COUNT(*) FROM incart WHERE cart_id = ?', (getuser_id(user)['id'], )).fetchone()
def get(id, user): return get_dbincart().execute( 'SELECT * FROM incart WHERE (product_id,cart_id) = (?,?)', (id, getuser_id(user)['id'])).fetchone()