예제 #1
0
파일: user.py 프로젝트: L29/PlantZo
def edit_address():
    if request.method == 'POST':
        data = request.get_json()
        cur = mysql.cursor(buffered=True)
        cur.execute("UPDATE users SET address = %s where uid = %s", (
            data['address'],
            data['uid'],
        ))
        mysql.commit()
        cur.close()
        return 'Success'
예제 #2
0
def cart_delete():
    if request.method == 'POST':
        data = request.get_json()
        cur = mysql.cursor(buffered=True)
        cur.execute("DELETE FROM cart where uid = %s and pid = %s", (
            data['uid'],
            data['pid'],
        ))
        mysql.commit()
        cur.close()
        return "Success"

    return "Success"
예제 #3
0
def cart():
    if request.method == 'GET':
        token = request.headers.get('Authorization').replace("Bearer ", "")
        print(token)
        payload = jwt.decode(token,
                             app.config.get('JWT_SECRET_KEY'),
                             algorithms=['HS256'])
        auth = payload['sub']

        cur = mysql.cursor(buffered=True)
        cur.execute(
            "SELECT * FROM cart c, product p where c.uid = %s and p.pid = c.pid",
            (auth['uid'], ))
        #cur.execute("SELECT * FROM cart where uid = %s", (auth['uid'],))
        row_headers = [x[0] for x in cur.description]
        rv = cur.fetchall()
        json_data = []
        for result in rv:
            json_data.append(dict(zip(row_headers, result)))
        res = json.loads(json.dumps(json_data))
        return jsonify(res)

    elif request.method == 'POST':
        data = request.get_json()
        cur = mysql.cursor(buffered=True)
        cur.execute("SELECT * FROM cart where uid = %s and pid = %s", (
            data['uid'],
            data['pid'],
        ))
        if cur.rowcount == 1:
            rv = cur.fetchone()
            quantity = int(rv[2]) + int(data['itemQuantity'])
            print(quantity)
            cur.execute(
                "UPDATE cart SET total = %s where uid = %s and pid = %s", (
                    quantity,
                    data['uid'],
                    data['pid'],
                ))
            mysql.commit()
            return "Success"

        cur.execute("INSERT INTO cart (uid, pid, total) VALUES (%s, %s, %s)",
                    (data['uid'], data['pid'], int(data['itemQuantity'])))
        mysql.commit()
        return 'Success'

    return 'Success'
예제 #4
0
파일: user.py 프로젝트: L29/PlantZo
def comment():
    if request.method == 'POST':
        data = request.get_json()
        print(data)
        cur = mysql.cursor(buffered=True)
        cur.execute(
            "INSERT INTO comment (uid, pid, rating, comment) VALUES (%s, %s, %s, %s)",
            (
                data['uid'],
                data['pid'],
                data['currentValue'],
                data['textArea'],
            ))
        mysql.commit()
        cur.close()
        return "Success give comment"

    return "Success"
예제 #5
0
def inpaid():
    if request.method == 'POST':
        cur = mysql.cursor(buffered=True)
        data = request.get_json()
        uid = data['uid']
        pids = data['pids']
        total = data['checkoutItemsTotal']
        date = (time.strftime('%Y-%m-%d %H:%M:%S'))
        ticket = random.randint(1000000, 2000000000)
        for i in range(len(pids)):
            cur.execute(
                "INSERT INTO history (`uid`, `pid`, `total_cost`, `date`, `ticket`) VALUES (%s, %s, %s, %s, %s)",
                (uid, pids[i], total, date, ticket))
            mysql.commit()

    return jsonify({
        "transaction_id": ticket,
        "date": (time.strftime('%Y-%m-%d %H:%M:%S'))
    })
예제 #6
0
파일: user.py 프로젝트: L29/PlantZo
def edit_profile():
    if request.method == 'POST':
        cur = mysql.cursor(buffered=True)
        data = dict(request.form)
        if (request.files):
            #handle image
            profile = request.files['profile_image']
            bg = request.files['background_image']
            bg_temp = bg.filename.split(".")
            profile_temp = profile.filename.split(".")
            profile.filename = data['uid'] + "_profile." + profile_temp[1]
            bg.filename = data['uid'] + "_background." + bg_temp[1]
            print(bg.filename, profile.filename)
            if profile.filename == '' and bg.filename == '':
                return "No Selected File"
            if profile and allowed_file(
                    profile.filename) and bg and allowed_file(bg.filename):
                profilename = secure_filename(profile.filename)
                bgname = secure_filename(bg.filename)
                profile.save(
                    os.path.join(app.config['UPLOAD_FOLDER'], profilename))
                bg.save(os.path.join(app.config['UPLOAD_FOLDER'], bgname))

        cur.execute("SELECT password FROM users where uid = %s",
                    (data['uid'], ))
        rv = cur.fetchone()
        new_password = bcrypt.generate_password_hash(
            data['newPassword']).decode('utf-8')
        if bcrypt.check_password_hash(rv[0], data['oldPassword']):
            cur.execute(
                "UPDATE users SET first_name = %s, last_name = %s, password = %s, address = %s where uid = %s",
                (data['firstName'], data['lastName'], new_password,
                 data['address'], data['uid']))
            mysql.commit()
            print("Success")
        else:
            print("missmatch")
            return "Password missmatch!"

        return "Success"
예제 #7
0
	def update_target_moisture(self, target_moisture):
		cursor.execute('update planter set target_moisture = {} where planter_id = {}'.format(target_moisture, self.planter_id))
		mysql.commit()
예제 #8
0
	def update_run_time(self, run_time):
		cursor.execute('update planter set run_time = {} where planter_id = {}'.format(run_time, self.planter_id))
		mysql.commit()
예제 #9
0
	def water_logging(self, run_time, run_speed):
		log_curs.execute('insert into water_log (planter_id, run_time, run_speed) values ({}, {}, {})'.format(self.planter_id, run_time, run_speed))
		mysql.commit()
예제 #10
0
	def update_cons_days_watered(self, days):
		cursor.execute('update planter set cons_days_watered = {} where planter_id = {}'.format(days, self.planter_id))
		mysql.commit()