def get_card_options(userid): query = f"SELECT stripe_id FROM stripe WHERE id = \'{userid}\'" data = inter.execute_read_query(query) if data: customer_id = data[0][0] customer = stripe.Customer.retrieve(f"{customer_id}") return customer["sources"]
def update_user(col_name): idval = request.form['id'] if inter.user_exists(idval, 'id'): replace = request.form[f"{col_name}"] if col_name == "password": replace = inter.encrypt_password(replace) query = f"UPDATE users SET {col_name} = \'{replace}\' WHERE id = \'{idval}\'" print(query) if inter.execute_query(query): query = f"SELECT * FROM users WHERE id = \'{idval}\'" resp = inter.execute_read_query(query) if resp: key_list = [ "username", "id", "recovery_key", "email", "sender", "street", "city", "state", "zip", "country", "password" ] full_resp = dict(zip(key_list, resp[0])) stripe_id = pay.get_customer_id(full_resp["id"]) full_resp["stripe_id"] = stripe_id payment_options = pay.get_payment_options( full_resp["stripe_id"]) full_resp["payment_options"] = payment_options print(full_resp) response = app.response_class(response=json.dumps(full_resp), status=200, mimetype='application/json') return response return app.response_class(status=404)
def user(): user_name = request.form['username'] if request.method == 'POST': if inter.user_exists(user_name): return app.response_class(status=409) max_id = inter.execute_read_query("SELECT COUNT(*) FROM users") idval = max_id[0][0] + 1 email = request.form['email'] sender_name = request.form['sender_name'] sender_street = request.form['sender_street'] sender_city = request.form['sender_city'] sender_state = request.form['sender_state'] sender_zip = request.form['sender_zip'] sender_country = request.form['sender_country'] unencrypted_pw = request.form['password'] encrypted = inter.encrypt_password(unencrypted_pw) quer1 = f"INSERT INTO users VALUES (\'{user_name}\', \'{idval}\', \'000000\', " quer2 = f"\'{email}\', \'{sender_name}\', \'{sender_street}\'," quer3 = f"\'{sender_city}\', \'{sender_state}\', \'{sender_zip}\'," quer4 = f"\'{sender_country}\', \'{encrypted}\')" query = " ".join([quer1, quer2, quer3, quer4]) if inter.execute_query(query) and pay.new_user(idval, email): print("user added") return app.response_class(status=200) elif request.method == 'DELETE': if not inter.user_exists(user_name): return app.response_class(status=404) query = f"DELETE FROM users WHERE username = \'{user_name}\'" if inter.execute_query(query): return app.response_class(status=200) else: return app.response_class(status=400)
def getdatabase(): query = "SELECT * FROM users" resp = inter.execute_read_query(query) print(resp) return app.response_class(status=200, response=json.dumps(resp), mimetype='application/json')
def get_customer_id(userid): print("\n\n\nhere\n\n\n") print(userid) query = f"SELECT stripe_id FROM stripe WHERE id = \'{userid}\'" data = inter.execute_read_query(query) print(data) if data: return data[0][0] else: return False
def get_package(user_id): query = f"SELECT shipid FROM labels WHERE \"userid\" = {user_id}" packages = inter.execute_read_query(query) print(packages) resp = [] for package in packages: print(package) shipment = easypost.Shipment.retrieve(package[0]) ship_dict = get_ship_dict(shipment) resp.append(ship_dict) return resp
def identify_user(): print("here!!!\n\n\n") email = request.form['email'] username = request.form['username'] if inter.user_exists(email, "email"): resp = inter.execute_read_query( f"SELECT * FROM users WHERE email = \'{email}\'") key_list = [ "username", "id", "recoverid", "email", "sender", "street", "city", "state", "zip", "country", "password" ] full_resp = dict(zip(key_list, resp[0])) if username == full_resp["username"]: response = app.response_class(response=json.dumps(full_resp), status=200, mimetype='application/json') return response else: return app.response_class(status=409) else: return app.response_class(status=404)
def validate(): username = request.form['username'] input_pw = request.form['password'] if inter.password_match(username, input_pw): query = f"SELECT * FROM users WHERE username = \'{username}\'" resp = inter.execute_read_query(query) if resp: key_list = [ "username", "id", "recovery_id", "email", "sender", "street", "city", "state", "zip", "country", "password" ] full_resp = dict(zip(key_list, resp[0])) stripe_id = pay.get_customer_id(full_resp["id"]) full_resp["stripe_id"] = stripe_id payment_options = pay.get_payment_options(full_resp["stripe_id"]) full_resp["payment_options"] = payment_options response = app.response_class(response=json.dumps(full_resp), status=200, mimetype='application/json') return response else: return app.response_class(status=404) else: return app.response_class(status=406)