def new_drop(): FirstName = str(search_value('first_name', str(current_user.username))) LastName = str(search_value('last_name', current_user.username)) if request.method == 'POST': user = str(current_user.username) I_name = request.form["Item_name"] I_cost = request.form["Item_cost"] I_desc = request.form["Item_desc"] location = request.form["location"] url = request.form["main_image"] url2 = request.form["main2_image"] url3 = request.form["main3_image"] url4 = request.form["main4_image"] url5 = request.form["main5_image"] S_name = str(current_user.username) B_name = 'None' txid = newOrder(S_name, B_name, I_name, I_desc, I_cost, location) if url != "undefined": url_id = search_OrderValue('img_url', txid=txid) newImage(url_id, txid, user, url) if url2 != "undefined": url_id = search_OrderValue('img_url', txid=txid) newImage(url_id, txid, user, url2) if url3 != "undefined": url_id = search_OrderValue('img_url', txid=txid) newImage(url_id, txid, user, url3) if url4 != "undefined": url_id = search_OrderValue('img_url', txid=txid) newImage(url_id, txid, user, url4) if url5 != "undefined": url_id = search_OrderValue('img_url', txid=txid) newImage(url_id, txid, user, url5) return redirect(url_for('active_drops')) return render_template("new_drop.html", FirstName = FirstName,\ LastName = LastName)
def boxUse(chat_id): if request.method == 'POST': item = search_OrderValue('I_name', txid=chat_id) sub = request.form.get("submit") if sub == 'submit': confirm_msg = dropStatus(chat_id, current_user.username, msg=True) codeView = requestCode(chat_id, current_user.username) return render_template("boxUse.html", code = codeView, item = item,\ confirm_msg = confirm_msg) else: b_user = search_OrderValue('B_username', txid=chat_id) s_user = search_OrderValue('S_username', txid=chat_id) confirm_msg = dropStatus(chat_id, current_user.username, msg=True) stage = search_ChatValue('stage', chat_id) if stage == "Buyer Access" and current_user.username == b_user: code_msg = "Request Box Access Code" elif stage == "Seller Access" and current_user.username == s_user: code_msg = "Request Box Access Code" elif stage == "Buyer Access" and current_user.username == s_user: code_msg = "Item successfully dropped!" elif stage == "Seller Access" and current_user.username == b_user: code_msg = "Awaiting seller drop..." else: code_msg = 'Confirm transaction before requesting an access code.' item = search_OrderValue('I_name', txid=chat_id) return render_template("boxUse.html",code = code_msg, item = item,\ confirm_msg = confirm_msg, stage=stage)
def completeMoneyTransfer(txid): cost = search_OrderValue('cost', txid) b_user = search_OrderValue('B_username', txid) s_user = search_OrderValue('S_username', txid) b_bucks = searchBucks(b_user) - cost s_bucks = searchBucks(s_user) + cost updateBucks(b_user, b_bucks) updateBucks(s_user, s_bucks) return cost
def dropStatus(txid, user, msg = None, status = None): connect_codelog() drop_status = search_OrderValue('status', txid = txid) b_user = search_OrderValue('B_username', txid = txid) s_user = search_OrderValue('S_username', txid = txid) if drop_status == "Buyer_Seller_TX_Confirm": confirm_msg = "Sale Confirmed!" tx_status = "Buyer_Seller_TX_Confirm" elif drop_status == "ITEM RETURNED": confirm_msg = "The item has been successfully returned by the buyer." tx_status = "ITEM RETURNED" elif drop_status == "FALSE RETURN": confirm_msg = "The buyer attempted a false return, transaction completed." tx_status = "ITEM FALSE RETURNED" elif drop_status == "TRANSACTION COMPLETE": confirm_msg = "Transaction complete!" tx_status = "TRANSACTION COMPLETE" else: if user == b_user: if drop_status == "Buyer_TX_Confirm": confirm_msg = 'Awaiting seller confirmation.' tx_status = "Buyer_TX_Confirm" elif drop_status == "Seller_TX_Confirm": confirm_msg = 'Confirm Buy.' tx_status = "Buyer_Seller_TX_Confirm" elif drop_status == 'None': confirm_msg = 'Confirm Buy.' tx_status = 'Buyer_TX_Confirm' elif user == s_user: if drop_status == "Seller_TX_Confirm": confirm_msg = 'Awaiting buyer confirmation.' tx_status = 'Seller_TX_Confirm' elif drop_status == "Buyer_TX_Confirm": confirm_msg = 'Confirm Sale.' tx_status = "Buyer_Seller_TX_Confirm" elif drop_status == 'None': confirm_msg = 'Confirm Sale.' tx_status = 'Seller_TX_Confirm' if msg == True: return confirm_msg elif status == True: return tx_status
def buypage(txid): FirstName = str(search_value('first_name', str(current_user.username))) LastName = str(search_value('last_name', current_user.username)) if request.method == 'POST': SellerName = str(search_OrderValue('S_username', txid=txid)) sub = request.form.get("submit") if sub == 'submit': msg = request.form.get("message") newMsg(txid, current_user.username, SellerName, current_user.username, msg) confirmBuyer(current_user.username, txid) return (redirect(url_for('active_drops'))) else: url = [] img = search_allImages(search_OrderValue('img_url', txid=txid)) for item in img: try: img_url = item.url img_url = str(img_url) url.append(img_url) except IndexError: img_url = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOEAAADhCAMAAAAJbSJIAAAAMFBMVEXp7vG6vsHs8fS3u77Cxsnn7O/d4uXFyczN0dTKztHS19rk6ezi5+rX3N+9wcS1ubzIzxKwAAACWElEQVR4nO3b4XKiMBRAYUkUhQT6/m+7CK2GABJjdrl3e75/djo0p2FIGOF0AgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAczpRxdMa2rrkW0LQnmY2mtrYqwtpWYqLpvsr0jY0SEy+FJvA7sT66Z8E0JQOr6ixuEs00sKaAaRKPDloYT1LblVgrvBV5ml4KDuu/Lyz5zyroFxYOe6/M/ZeOQtNdrbV9e8loVFHo+mn9t8PV9cNDiTEbln/ubzL2XxoKw83J19tDlV9obrMtav/uJCoonO/B3x6r/MI6KrxtTaK57B1KkmBYXXQf1WwUDrcjq4nyC+u0QtMMv7eWKL/QR2fp+noxBq4myi9MutJ8B64lKihMWC0egSuJ8gsTVvwgcJmooXBv1zYLXCRqKNzZeUeBcaKKwvvdU7V197QIjBJ1FL64A14JnCdqKdyyGjhLVF64ERgm6i7cDAwSVRe+CHwmKiv0PvjwMvCRqKvQWeseH3YCfxJVFbr7D38SdwOrym0f6nCrw3LBuFMCpy2eokIXTk1CoLpC9xy5SwrUVujCsbuUQGWFbj72hD5lhW6vRnthVqCmwrxARYWZgXoKcwPVFGYHqimMv7egkEIhKKSQwuOFhedsXXQoScJhffgagoJCOYcqicJ3yCychtWWeM57fFrF+v0/+W+Zfrzc519Gn8bFRt6z+tEDGB+7invfYv4AxseCbzvk8AUnMefR4r/PuLMtpPcSAwfGt7cC2lpo312JxULyK6QAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA8Gv8AbboIxLMxQycAAAAAElFTkSuQmCC" url.append(img_url) item_name = search_OrderValue('I_name', txid=txid) location = search_OrderValue('Location', txid=txid) item_desc = search_OrderValue('description', txid=txid) item_cost = search_OrderValue('Cost', txid=txid) SellerName = search_OrderValue('S_username', txid=txid) date_init = date_time(search_OrderValue('date_initialized', txid=txid)) return render_template("buyPage(new).html", FirstName = FirstName, \ LastName = LastName, i_name = item_name,\ location = location, i_desc = item_desc, i_cost = item_cost,\ SellerName = SellerName, date_init = date_init, \ currentuser = current_user.username, txid = txid, url=url)
def transactionpage(chat_id): FirstName = str(search_value('first_name', str(current_user.username))) LastName = str(search_value('last_name', current_user.username)) request_code = url_for('confirmTX', chat_id=chat_id) code_msg = dropStatus(chat_id, current_user.username, msg=True) if search_OrderValue('status', txid=chat_id) == "Buyer_Seller_TX_Confirm": code_msg = 'Request Box Access Code' item_name = search_OrderValue('I_name', txid=chat_id) location = search_OrderValue('Location', txid=chat_id) item_desc = search_OrderValue('description', txid=chat_id) item_cost = search_OrderValue('Cost', txid=chat_id) buy_user = search_OrderValue('B_username', txid=chat_id) sell_user = search_OrderValue('S_username', txid=chat_id) date_init = date_time(search_OrderValue('date_initialized', txid=chat_id)) oldMsg = searchMsg(chat_id) oldMsgTime = [] oldMsgMsg = [] oldMsgSender = [] for item in oldMsg: try: oldMsgSender.append(item.Sender_username) oldMsgMsg.append(item.msg) oldMsgTime.append(date_time(item.msg_date)) except TypeError: oldMsgTime.append('<i>time not available</i>') return render_template('message.html', currentuser = \ str(current_user.username), FirstName=FirstName, LastName=LastName, \ chatid = chat_id, item_name=item_name, location = location, \ item_desc=item_desc, item_cost=item_cost, buy_user=buy_user, \ sell_user=sell_user, date_init=date_init, oldMsgMsg = oldMsgMsg, oldMsgSender=oldMsgSender,\ request_code = request_code, code_msg = code_msg, oldMsgTime=oldMsgTime)
def newBoxAssignment(txid, box_id): B_username = search_OrderValue('B_username', txid=txid) S_username = search_OrderValue('S_username', txid=txid) stage = 'Seller Access' date = None code = None status = None new_entry = ConnectData(TXID = txid, B_username = B_username, \ S_username = S_username, stage = stage, box_id = box_id, \ access_code = code, expiry_time = date, code_attempt = code, attempt_time = date, seller_close_date = date, \ buyer_close_date = date, door_status = status, scale_status = status, scale_delta = status) db.session.add(new_entry) db.session.commit() db.session.close()
def newBoxAssignment(txid, box_id): connect_codelog() conn=psycopg2.connect("dbname='SafeDrop_KeypadCode' user='******' password='******' host='localhost' port = '5432'") cur=conn.cursor() B_username = search_OrderValue('B_username', txid = txid) S_username = search_OrderValue('S_username', txid = txid) stage = 'Seller Access' date = None code = None status = None cur.execute("INSERT INTO codelog VALUES(default, %s, %s, %s, %s, %s, %s, %s,\ %s, %s, %s, %s, %s, %s, %s)", \ (txid, B_username, S_username, stage, box_id, code, date, code, date, date,\ date, status, status, status)) conn.commit() conn.close()
def confirmTX(chat_id): #dropStatus updates as per current values tx_status = dropStatus(chat_id, current_user.username, status=True) order_status = search_OrderValue('status', txid=chat_id) if order_status != "Buyer_Seller_TX_Confirm": statusUpdate(tx_status, chat_id) return redirect(url_for('transactionpage', chat_id=chat_id)) if order_status == "Buyer_Seller_TX_Confirm": newBoxAssignment(chat_id, "SafeDrop UBC Box 1") return redirect(url_for('boxUse', chat_id=chat_id))
def history(): FirstName = str(search_value('first_name', str(current_user.username))) LastName = str(search_value('last_name', current_user.username)) h_txid = search_allOrders(SUN=current_user.username, BUN=current_user.username) h_txids = [] b_names = [] s_names = [] h_item = [] h_price = [] h_location = [] h_date_open = [] h_date_close = [] h_status = [] h_txstatus = [] h_url = [] for item in h_txid: txid = str(item) h_txids.append(item.TXID) b_names.append(item.B_username) s_names.append(item.S_username) h_item.append(item.I_name) h_price.append(item.Cost) h_location.append(item.Location) h_date_open.append(item.date_initialized) h_date_close.append(item.date_resolved) h_txstatus.append(item.status) h_status.append(search_OrderValue('status', item.TXID)) h_url.append(item.img_url) currentuser = current_user.username return render_template('history.html', FirstName=FirstName, currentuser=currentuser, \ LastName = LastName, h_txids=h_txids, b_names=b_names, s_names=s_names,\ h_item=h_item, h_price=h_price, h_location=h_location, h_url=h_url,\ h_date_open=h_date_open, h_date_close=h_date_close,\ h_status=h_status, h_txstatus = h_txstatus)
def active_drops(): FirstName = str(search_value('first_name', str(current_user.username))) LastName = str(search_value('last_name', current_user.username)) s_txid = search_OrderValue('TXID', S_username=current_user.username) s_txids = [] s_names = [] s_other_user = [] s_price = [] s_location = [] s_date = [] s_return = [] a_txids = [] a_names = [] a_price = [] a_location = [] a_date = [] for item in s_txid: txid = str(item) if (search_OrderValue('status', txid=txid) != "TRANSACTION COMPLETE"): if (search_OrderValue('B_username', txid=txid)) != 'None': s_txids.append(txid) s_names.append(search_OrderValue('I_name', txid=txid)) s_other_user.append(search_OrderValue('B_username', txid=txid)) s_price.append(search_OrderValue('Cost', txid=txid)) s_location.append(search_OrderValue('Location', txid=txid)) s_date.append( date_time(search_OrderValue('date_initialized', txid=txid))) if (search_OrderValue('status', txid=txid) == "ITEM RETURNED"): s_return.append('waiting') else: s_return.append('else') else: txid = str(item) a_txids.append(txid) a_names.append(search_OrderValue('I_name', txid=txid)) a_price.append(search_OrderValue('Cost', txid=txid)) a_location.append(search_OrderValue('Location', txid=txid)) a_date.append( date_time(search_OrderValue('date_initialized', txid=txid))) b_txid = search_OrderValue('TXID', B_username=current_user.username) b_txids = [] b_names = [] b_other_user = [] b_price = [] b_location = [] b_date = [] for item in b_txid: txid = str(item) if (search_OrderValue('status', txid=txid) != "TRANSACTION COMPLETE"): b_txids.append(txid) b_names.append(search_OrderValue('I_name', txid=txid)) b_other_user.append(search_OrderValue('S_username', txid=txid)) b_price.append(search_OrderValue('Cost', txid=txid)) b_location.append(search_OrderValue('Location', txid=txid)) b_date.append( date_time(search_OrderValue('date_initialized', txid=txid))) currentuser = current_user.username return render_template('active_drops.html', FirstName=FirstName, \ LastName = LastName, s_txids=s_txids, b_txids = b_txids,\ s_names=s_names, b_names=b_names, s_other_user = s_other_user, \ s_price = s_price, s_location = s_location, s_date = s_date,\ b_other_user = b_other_user, b_price = b_price, b_location = b_location\ , b_date = b_date, a_price = a_price, a_location = a_location\ , a_date = a_date, a_txids=a_txids, a_names=a_names, s_return=s_return)