def add_user(): conn = None cursor = None try: _name = request.form['inputName'] _email = request.form['inputEmail'] _password = request.form['inputPassword'] # validate the received values if _name and _email and _password and request.method == 'POST': #do not save password as a plain text _hashed_password = generate_password_hash(_password) # save edits sql = "INSERT INTO tbl_user(user_name, user_email, user_password) VALUES(%s, %s, %s)" data = ( _name, _email, _hashed_password, ) conn = mysql.connect() cursor = conn.cursor() cursor.execute(sql, data) conn.commit() flash('User added successfully!') return redirect('/') else: return 'Error while adding user' except Exception as e: print(e) finally: cursor.close() conn.close()
def update_user(): conn = None cursor = None try: _name = request.form['inputName'] _email = request.form['inputEmail'] _password = request.form['inputPassword'] _id = request.form['id'] # validate the received values if _name and _email and _password and _id and request.method == 'POST': #do not save password as a plain text _hashed_password = generate_password_hash(_password) print(_hashed_password) # save edits sql = "UPDATE tbl_user SET user_name=%s, user_email=%s, user_password=%s WHERE user_id=%s" data = ( _name, _email, _hashed_password, _id, ) conn = mysql.connect() cursor = conn.cursor() cursor.execute(sql, data) conn.commit() flash('User updated successfully!') return redirect('/') else: return 'Error while updating user' except Exception as e: print(e) finally: cursor.close() conn.close()
def customerLogin(cls, username, password): try: conn = mysql.connect() cursor = conn.cursor(pymysql.cursors.DictCursor) cursor.execute("SELECT * from customer where username = %s and password= %s", (username, password)) rows = cursor.fetchone() if rows is not None: sessionId = str(uuid.uuid4()) cursor.execute("update customer set session_id = %s where customer_id = %s", (sessionId, rows.get('customer_id'))) conn.commit() cursor.execute("SELECT * from customer where username = %s and password= %s", (username, password)) rows = cursor.fetchone() return rows else: return None except Exception as e: print(e) finally: cursor.close() conn.close()
def write(): data = request.get_json() if (data["tablename"] == "user" and data["action"] == "add"): sql = "INSERT INTO user(username, password) VALUES(%s, %s)" datas = (data["username"], data["password"]) conn = mysql.connect() cursor = conn.cursor() cursor.execute(sql, datas) conn.commit() response = jsonify('User added successfully!') return response, 201 elif (data["tablename"] == "user" and data["action"] == "delete"): conn = mysql.connect() cursor = conn.cursor() cursor.execute("DELETE FROM user WHERE username=%s", data["username"]) conn.commit() response = jsonify('User deleted successfully!') return response.text, 201 elif (data["tablename"] == "ride" and data["action"] == "add"): sql = "INSERT INTO ride(created_by, source, destination) VALUES(%s, %s, %s)" datas = (data["created_by"], data["source"], data["destination"]) conn = mysql.connect() cursor = conn.cursor() cursor.execute(sql, datas) conn.commit() response = jsonify('Ride created successfully!') return response, 201 elif (data["tablename"] == "join_ride" and data["action"] == "add"): sql = "INSERT INTO join_ride(rideid, associateduser) VALUES(%s, %s)" datas = (data["rideid"], data["username"]) conn = mysql.connect() cursor = conn.cursor() cursor.execute(sql, datas) conn.commit() response = jsonify('Ride joined successfully!') return response, 201 elif (data["tablename"] == "ride" and data["action"] == "delete"): conn = mysql.connect() cursor = conn.cursor() cursor.execute("DELETE FROM ride WHERE rideid=%s", data["rideid"]) conn.commit() response = jsonify('Ride deleted successfully!') return response, 201 else: return not_found() cursor.close() conn.close()
def update_user(): _name = request.form['inputName'] _email = request.form['inputEmail'] _password = request.form['inputPassword'] _conformpassword = request.form['inputconformpassword'] _gender = request.form['inputgender'] _mobileno = request.form['inputmobileno'] _address = request.form['inputaddress'] _id = request.form['id'] # validate the received values match_mob = re.search(r'((?:\(?\+?91\)?)?0?\d{10})', _mobileno) if match_mob: print(match_mob.group(0)) else: print("not valid") return "please enter correct mobile no" match = re.search(r'[\w.-]+@[\w.-]+.\w+', _email) if match: print("valid email :::", match.group()) else: print("not valid:::") return "please enter correct email id" if _password == _conformpassword: print("valid") else: print("not valid") return "please enter correct password" try: if _name and _email and _password and _conformpassword and _mobileno and _gender and _address and _id and request.method == 'POST': #do not save password as a plain text # _hashed_password = generate_password_hash(_password) # save edits sql = "UPDATE task2 SET user_name=%s, user_email=%s, user_password=%s, user_conformpassword=%s, user_mobileno=%s, user_gender=%s, user_address=%s WHERE user_id=%s" data = ( _name, _email, _password, _conformpassword, _mobileno, _gender, _address, _id, ) conn = mysql.connect() cursor = conn.cursor() cursor.execute(sql, data) conn.commit() flash('User updated successfully!') return redirect('/') else: return 'Error while updating user' except Exception as e: print(e) finally: cursor.close() conn.close()
def CustomerEnquiry(cls): try: conn = mysql.connect() cursor = conn.cursor(pymysql.cursors.DictCursor) cursor.execute("select * from query") row = cursor.fetchall() return row except Exception as e: print(e) finally: cursor.close()
def getAllImages(cls): try: conn = mysql.connect() cursor = conn.cursor(pymysql.cursors.DictCursor) cursor.execute("select image from room") row = cursor.fetchall() return row except Exception as e: print(e) finally: cursor.close()
def GetRoomID(cls): try: conn = mysql.connect() cursor = conn.cursor(pymysql.cursors.DictCursor) cursor.execute("select room_id from room") row = cursor.fetchall() return row except Exception as e: print(e) finally: cursor.close()
def delete_user(id): try: conn = mysql.connect() cursor = conn.cursor() cursor.execute("DELETE FROM task2 WHERE user_id=%s", (id, )) conn.commit() flash('User deleted successfully!') return redirect('/') except Exception as e: print(e) finally: cursor.close() conn.close()
def searchPackage(cls, searchText): try: conn = mysql.connect() cursor = conn.cursor(pymysql.cursors.DictCursor) query = "SELECT * FROM package WHERE MATCH (country, city, package_display_name, unique_url_name)AGAINST ('*" + searchText + "*' IN BOOLEAN MODE)" cursor.execute(query) rows = cursor.fetchall() return rows except Exception as e: print(e) finally: cursor.close() conn.close()
def getAllRoomsForUser(cls): try: conn = mysql.connect() cursor = conn.cursor(pymysql.cursors.DictCursor) cursor.execute("SELECT room_id,room_number,price,Average_Rating,availibility,facilities from room where availibility='Yes'") rows = cursor.fetchall() return rows except Exception as e: print(e) finally: cursor.close() conn.close()
def deleteCustomer(cls, customer_id): try: conn = mysql.connect() cursor = conn.cursor(pymysql.cursors.DictCursor) cursor.execute("DELETE from customer where customer_id=%s", customer_id) conn.commit() except Exception as e: print(e) finally: cursor.close() conn.close()
def changePassword(cls, email_id, otp, password): try: conn = mysql.connect() cursor = conn.cursor(pymysql.cursors.DictCursor) cursor.execute( "update employee e set password = %s where email = %s and otp= %s ", (password, email_id, otp)) conn.commit() except Exception as e: print(e) finally: cursor.close() conn.close()
def checkIfEmployeeExistWithEmailId(cls, emailId): try: conn = mysql.connect() cursor = conn.cursor(pymysql.cursors.DictCursor) cursor.execute("Select * from employee e where e.email=%s", emailId) rows = cursor.fetchone() return rows except Exception as e: print(e) finally: cursor.close() conn.close()
def getAllRoomsForAdmin(cls): try: conn = mysql.connect() cursor = conn.cursor(pymysql.cursors.DictCursor) cursor.execute("SELECT * from room") rows = cursor.fetchall() return rows except Exception as e: print(e) finally: cursor.close() conn.close()
def city(loc): try: conn = mysql.connect() cursor = conn.cursor(pymysql.cursors.DictCursor) cursor.execute("SELECT * FROM data WHERE city=%s",loc) row = cursor.fetchone() resp = jsonify(row) resp.status_code = 200 return resp except Exception as e: print(e) finally: cursor.close() conn.close()
def checkRoomWithNumber(cls, room_number): try: conn = mysql.connect() cursor = conn.cursor(pymysql.cursors.DictCursor) cursor.execute("SELECT * from room where room_number=%s", room_number) rows = cursor.fetchone() return rows except Exception as e: print(e) finally: cursor.close() conn.close()
def getAllDataForUser(cls): try: conn = mysql.connect() cursor = conn.cursor(pymysql.cursors.DictCursor) cursor.execute("SELECT * from room where availibility='Yes'") rows = cursor.fetchall() return rows except Exception as e: print(e) finally: cursor.close() conn.close()
def getHashPass(cls, username): try: conn = mysql.connect() cursor = conn.cursor(pymysql.cursors.DictCursor) cursor.execute("SELECT password from customer where username=%s", username) rows = cursor.fetchone() return rows except Exception as e: print(e) finally: cursor.close() conn.close()
def all(): try: conn = mysql.connect() cursor = conn.cursor(pymysql.cursors.DictCursor) cursor.execute("SELECT * FROM data") rows = cursor.fetchall() resp = jsonify(rows) resp.status_code = 200 return resp except Exception as e: print(e) finally: cursor.close() conn.close()
def searchCustomer(cls, searchText): try: conn = mysql.connect() cursor = conn.cursor(pymysql.cursors.DictCursor) query = "SELECT * FROM customer WHERE MATCH (name, email) AGAINST ('*" + searchText + "*' IN BOOLEAN MODE) ORDER BY created_on" cursor.execute(query) rows = cursor.fetchall() return rows except Exception as e: print(e) finally: cursor.close() conn.close()
def checkCustomerFromSessionID(cls,session_id): try: conn = mysql.connect() cursor = conn.cursor(pymysql.cursors.DictCursor) cursor.execute("SELECT * from customer where session_id=%s", session_id) rows = cursor.fetchone() return rows except Exception as e: print(e) finally: cursor.close() conn.close()
def getAllCustomersfromDB(cls): try: conn = mysql.connect() cursor = conn.cursor(pymysql.cursors.DictCursor) cursor.execute("SELECT * from customer c ORDER BY c.created_on") rows = cursor.fetchall() return rows except Exception as e: print(e) finally: cursor.close() conn.close()
def get(self): try: conn = mysql.connect() cursor = conn.cursor() #Execute SQL cursor.execute('SELECT * FROM books') #Dictionary object to contain headername bookResults = [dict((cursor.description[i][0], value)for i, value in enumerate(row)) for row in cursor.fetchall()] print (bookResults) return jsonify(bookResults) except Exception as e: return {'error': str(e)}
def users(): try: conn = mysql.connect() cursor = conn.cursor(pymysql.cursors.DictCursor) cursor.execute("SELECT * FROM task2") rows = cursor.fetchall() table = Results(rows) table.border = True return render_template('users.html', table=table) except Exception as e: print(e) finally: cursor.close() conn.close()
def getAllCustomersfromDB(cls): try: conn = mysql.connect() cursor = conn.cursor(pymysql.cursors.DictCursor) cursor.execute("SELECT customer_id,name,username,email,contact_no from customer") rows = cursor.fetchall() return rows except Exception as e: print(e) finally: cursor.close() conn.close()
def edit_view(id): try: conn = mysql.connect() cursor = conn.cursor(pymysql.cursors.DictCursor) cursor.execute("SELECT * FROM task2 WHERE user_id=%s", id) row = cursor.fetchone() if row: return render_template('edit.html', row=row) else: return 'Error loading #{id}'.format(id=id) except Exception as e: print(e) finally: cursor.close() conn.close()
def getAllEnquiries(cls): try: conn = mysql.connect() cursor = conn.cursor(pymysql.cursors.DictCursor) cursor.execute( "SELECT * from enquiry e ORDER BY e.created_on DESC") rows = cursor.fetchall() return rows except Exception as e: print(e) finally: cursor.close() conn.close()
def OTPCheck(cls, OTP): try: conn = mysql.connect() cursor = conn.cursor(pymysql.cursors.DictCursor) cursor.execute("SELECT * from customer WHERE OTP = %s", OTP) row = cursor.fetchone() return row except Exception as e: print(e) finally: cursor.close() conn.close()
def forgotPasswordCheck(cls, customer_id,email): try: conn = mysql.connect() cursor = conn.cursor(pymysql.cursors.DictCursor) cursor.execute("SELECT * from customer WHERE customer_id = %s and email=%s", (customer_id,email)) row = cursor.fetchone() return row except Exception as e: print(e) finally: cursor.close() conn.close()