def collect(): expectedFields = ['image', 'timestamp', 'video_id', 'user_id'] if not request.json or not all(field in request.json for field in expectedFields): abort(400) if not userExists(request.json['user_id']): response = json.loads(face(request.json['image'])) if len(response) == 0: return json.dumps({'success': True}), 200, { 'ContentType': 'application/json' } attributes = response[0]['faceAttributes'] insertUser(request.json['user_id'], attributes['age'], attributes['gender']) response = json.loads(emotions(request.json['image'])) if len(response) == 0: return json.dumps({'success': True}), 200, { 'ContentType': 'application/json' } scores = response[0]['scores'] insertMetric(request.json['video_id'], request.json['user_id'], request.json['timestamp'], scores['anger'], scores['contempt'], scores['disgust'], scores['fear'], scores['happiness'], scores['neutral'], scores['sadness'], scores['surprise']) return json.dumps({'success': True}), 200, { 'ContentType': 'application/json' }
def adm(): if request.method == 'POST': username = request.form['username'] password = request.form['password'] hashed_password = hashlib.sha224(password.encode('utf-8')).hexdigest() print(hashed_password) insertUser(username, hashed_password) return redirect('/?registered=True') else: return render_template('admin.html')
def loginPage(): ''' This Method returns login page on a GET Request and registers user into the database if Google Oauth is used to login into the System ''' if(request.method=='GET'): return render_template("login.html") else: name=request.form['name'] email=request.form['email'] db.insertUser(name,email) session['email']=email return "OK"
def checkregisterManager(): if request.method == "POST": fname = request.form['fname'] uname = request.form['uname'] password = request.form['password'] email = request.form['email'] lname = request.form['lname'] cpassword = request.form['cpassword'] confcode = request.form['code'] dsID = request.form['dsID'] error1 = "your password is messed up bro" error2 = "email contains non-alphanumeric characters" arr = re.split(r'[@.]', email) if password != cpassword: return render_template("registerManager5.html", error=error1) elif (len(arr) != 3) or (arr[0].isalnum() and arr[1].isalnum() and arr[2].isalnum()) / 1 != 1: return render_template("registerManager5.html", error=error2) else: user_type = 'manager' sysid = 1 #manager tag is 1 in system information reg = db.systeminfoManager(sysid, confcode) if reg == 1: return render_template("registerManager5.html", error="Code incorrect.") reg = db.insertUser(uname, password, user_type, email, fname, lname) if reg == 1: return render_template("registerManager5.html", error="Username is Taken.") reg = db.insertManager(uname, dsID) return render_template('login1.html') return render_template('registerManager5.html', error="something wrong")
def POST(self): rel1 = False rel3 = False web.header('Content-Type','application/json') dat = web.data() input = json.loads(dat) act = input['action'] print "data: "+act if act == 'Relay 1 on' : ser.write('1') rel1 = True rv = {'status' : 'True', 'message' : 'Relay 1 is ON!'} return json.dumps(rv) elif act == 'Relay 1 off' : ser.write('!') rel1 = False rv = {'status':'True', 'message': 'Relay 1 is OFF!'} return json.dumps(rv) elif act == 'Relay 2 on' : ser.write('2') #rel2 = True rv = {'status':'True', 'message':'Relay 2 is ON!'} return json.dumps(rv) elif act == 'Relay 3 on' : ser.write('3') rel3 = True rv = {'status': 'True', 'message' : 'Relay 3 is ON!' } return json.dumps(rv) elif act == 'Relay 3 off' : ser.write('#') rel3 = False rv = {'status' : 'True', 'message' : 'Relay 3 is OFF!'} return json.dumps(rv) elif act == 'CHECK' : ser.write('5') sta = ser.readline() stat = int(sta,2) if stat == 0 : rel1=False; #rel2=False; rel3=False; elif stat == 1 : rel1=False; #rel2=False; rel3=True; elif stat == 2 : rel1=True; #rel2=True; rel3=False; elif stat == 3 : rel1=True; #rel2=True; rel3=True; '''elif stat == 4 : rel1=True; rel2=False; rel3=False; elif stat == 5 : rel1=True; rel2=False; rel3=True; elif stat == 6 : rel1=True; rel2=True; rel3=False; elif stat == 7 : rel1=True; rel2=True; rel3=True;''' rv = {'status':'True', 'message' : stat} return json.dumps(rv) elif act == 'loginF': idata = input['data'] image = open('imageFromPhone.jpg','wb') image.write(idata.decode('base64')) image.close() image = cv2.imread('imageFromPhone.jpg') recog = fileH.trainRecog() [label , dist] = fileH.recognize(image,recog) rv = {} if label == -1: rv = {'status': 'False'} else: conn = db.Connect() [status,uname,pswd] = db.checkFace(conn,label) conn.close() rv = {'status':str(status),'uname':uname,'pswd':pswd} #rv = {'status':'True', 'message' : 'label : '+str(label)+'\ndist : '+str(dist)} return json.dumps(rv) elif act == 'login': uname = input['username'] pswd = input['password'] conn = db.Connect() if db.checkUser(conn,uname,pswd): print "User Exists!" flag = True for names in self.users: if names == uname : flag = False break else: flag = True if flag : self.users.append(uname) rv={'stat':'True'} conn.close() return json.dumps(rv) else: rv={'stat':'False'} conn.close() return json.dumps(rv) elif act == 'logout': uname = input['username'] flag = False for name in self.users: if name == uname: self.users.remove(name) flag = True break else: flag = False rv={'stat':'abc'} ser.write('4') if flag: rv={'stat':'True'} else: rv={'stat':'False'} return json.dumps(rv) elif act == 'getUsers': conn = db.Connect() usernames = db.getUsers(conn) conn.close() rv={'users':usernames} return json.dumps(rv) elif act == 'register': flag = input['pic'] uname = input['uname'] pswd = input['pswd'] name = input['name'] #logging.warning(str(flag)+' '+uname+' '+pswd+' '+name) if flag == 'False': #logging.warning('Entered False') try: #logging.warning('Entered Try') conn = db.Connect() db.insertUser(conn,uname,pswd,name,'') conn.commit() conn.close() rv={'stat':'True'} return json.dumps(rv) except: #logging.warning('Entered Except') rv={'stat':'False'} return json.dumps(rv) elif flag == 'True': im1 = input['img1'] im2 = input['img2'] im3 = input['img3'] im4 = input['img4'] path = fileH.getPath() im = open('image.jpg','wb') im.write(im1.decode('base64')) im.close() img = cv2.imread('image.jpg') fileH.saveFace(img,path) im = open('image.jpg','wb') im.write(im2.decode('base64')) im.close() img = cv2.imread('image.jpg') fileH.saveFace(img,path) im = open('image.jpg','wb') im.write(im3.decode('base64')) im.close() img = cv2.imread('image.jpg') fileH.saveFace(img,path) im = open('image.jpg','wb') im.write(im4.decode('base64')) im.close() img = cv2.imread('image.jpg') fileH.saveFace(img,path) fileH.createCSV() face = fileH.getLabel() logging.warning('label '+str(face)) con = db.Connect() db.insertUser(con,uname,pswd,name,face) con.commit() con.close() #fileH.trainRecog() rv={'stat':'True'} return json.dumps(rv) else : rv={'message':'Invalid Request'} return json.dumps(rv)
#Insert Health and Safety Issues print("\nInserting Health and Safety Issues") for entry in hasIssues: db.insertHealthAndSafetyIssue(entry) printTable(db, tables[3]) #Insert fine payments print("\nInserting Fine Payments") for entry in finePayments: db.insertFinePayment(entry) printTable(db, tables[4]) #Insert Users print("\nInserting Users") for entry in users: db.insertUser(entry) printTable(db, tables[5]) #============================================================# #Update #============================================================# print("\nUpdating Tables") #Updating Parking Permits ID = 2 print("\nParking Permits") print("Updating Approved") print("Before:", db.retrieve(tables[0], "Permit_Number", 2)) db.updateParkingPermit("Approved", "Approved", 2) print("After:", db.retrieve(tables[0], "Permit_Number", 2)) #Updating Parking Violations ID = 3
def oauth_callback(): msgstr = "" #get state and code. Code will need to be verified with the wow.login function #state will be trimmed and used as the Discord UID state = request.args.get('state') code = request.args.get('code') UID = "" if state is not None: UID = state[3:] else: UID = "" state = "" if code is None: code = "" #post code to token url access_token = wow.login(code) #function returns either success with the token or some error message if access_token.startswith("success token="): # Not finished #read token response from login function and save access_token token = access_token[14:] #check_token to get expiry success, data = wow.checktoken(token) if success: username = data[0] exp = data[1] btag = data[2] #userinfo to get UID #bUID is blizzard UserID = username in this instance #save bUID, access_token, expiry, scope, and game data = [username, token, exp, 'scope.wow', 'wow'] #save UID, and id in users #get id from DB where UID = bUID #saveWowAccountData returns bID which is a unique id from the db server # it returns this value ONLY if this is a new account newuser, bid = db.saveWowAccountData(data) #if it returned an ID from the DB, we need to save the account data with the discord UID if newuser is True: db.insertUser(UID, bid) #query list of characters and save in wowCharacters characters = wow.listCharacters(access_token=token) updatedCharacters = [] for char in characters: char["bid"] = bid char["UID"] = UID updatedCharacters.append(char) result = db.saveCharacters(updatedCharacters) if result is True: #update userCharacters! msgstr = "You have successfully linked your Discord and World of Warcraft accounts. We were able to save all your character data. If you wish to add data for a different World of Warcraft account, you will need to run the register command again using a different discord profile. Please close this window to start using the bot and add characters to the watch list for Mythic Plus key runs." else: msgstr = "You appear to have successfully linked your Discord and World of Warcraft accounts, but we were unable to save your character data. I'm not sure how we got here, but here we are. Please contact a developer to investigate this incident. <br><br>BID=" + bid + "<br><br>Please use the above information when contacting the developer." #eventually......... we'll get here. return render_template('main.html', name="Hello " + btag + "!", message=msgstr + " Also your token is " + token) else: #there was some error, tell the user so they can hopefully report it. :P return render_template('main.html', name="Uh oh!", message="There was an error: " + access_token)
def checkregisterBuyer(): if request.method == "POST": uname = request.form['uname'] fname = request.form['fname'] lname = request.form['lname'] password = request.form['password'] email = request.form['email'] street = request.form['street'] houseNo = request.form['houseNo'] city = request.form['city'] lname = request.form['lname'] phone = request.form['phone'] cpassword = request.form['cpassword'] state = request.form['state'] zipp = request.form['zip'] payment = request.form['payment'] routingNo = request.form['routingNo'] accNo = request.form['accNo'] dsID = request.form['dsID'] error1 = "your password is messed up bro" error2 = "phone has incorrect number of digits" error3 = "zip code has incorrect number of digits" error4 = "email has improper format" error5 = "C'mon brug you messed up your account number" error6 = "Lmao try dat routing number again" error7 = "phone has correct number of digits, m**********r" arr = re.split(r'[@.]', email) if password != cpassword: return render_template("registerBuyer3.html", error=error1) elif (len(str(phone))) == 10: return render_template("registerBuyer3.html", error=error7) elif (len(str(phone))) != 9: #10: return render_template("registerBuyer3.html", error=error2) elif (len(str(zipp))) != 5: return render_template("registerBuyer3.html", error=error3) elif (len(arr) != 3) or (arr[0].isalnum() and arr[1].isalnum() and arr[2].isalnum()) / 1 != 1: return render_template("registerBuyer3.html", error=error4) elif (len(str(routingNo))) != 9: #10: return render_template("registerBuyer3.html", error=error5) elif (len(str(accNo))) != 9: #10: return render_template("registerBuyer3.html", error=error6) else: '''query = "SELECT MAX(id) FROM Address;" response = db.cursor.execute(query) db.cursor.fetchall()''' global AddID AddID = AddID + 1 user_type = 'buyer' reg = db.insertUser(uname, password, user_type, email, fname, lname) if reg == 1: return render_template("registerBuyer3.html", error="Username is Taken.") reg = db.insertPayment(uname, payment, accNo, routingNo) if reg == 1: return render_template("registerBuyer3.html", error="Payment name already Used.") else: query = "INSERT INTO Payments(username,payment_name,account_number,routing_number)"\ "VALUES (%s,%s,%s,%s);" db.cursor.execute(query, (uname, payment, accNo, routingNo)) db.conn.commit() reg = db.insertAddress(AddID, houseNo, street, state, city, zipp) reg = db.insertBuyer(uname, phone, AddID, payment, dsID) return render_template('login1.html') return render_template('registerBuyer3.html', error="something wrong")
def dbInsertUser(email, password, username, karma=0): user = User(email, password, username, karma) insertUser(user)
import db username = "******" password = "******" if __name__ == "__main__": db.createUser() print "Successfully create user table." db.createCraft() print "Successfully create craft table." db.insertUser(username, password) print "Successfully insert user." db.insertCraft() print "All done.Now you can run Shakespeare.py."
def new_user(): userName = input("Enter a username: "******"Enter a password: "******"Enter the Full Name:") insertUser(userName, password, full_name)
def dbInsertUser(email,password,username,karma = 0): user = User(email,password,username,karma) insertUser(user)
if (type == "instructor"): if (not (len(str(ID)) == 6)): print("ID must be 6 digits") else: inputValid = True username = input("Username: "******"Password: "******"student"): student = Student(name, ID, username, password) elif (type == "instructor"): instructor = Instructor(name, ID, username, password) db.insertUser(student, type) elif (decision == "2"): multipleStu = False while (not multipleStu): stuID = input("ID: ") aName = input("Assignment Name: ") mark = input("Mark: ") db.updateMarks(stuID, aName, mark) moreInput = input("Input another (y/n): ") if (moreInput == "n"): multipleStu = True elif (decision == "3"): assignName = input("Assignment name: ") db.autoMarkCAssignment(assignName)