def post(self): parser = reqparse.RequestParser() parser.add_argument("guess") parser.add_argument("actual") parser.add_argument("username") args = parser.parse_args() guess = args["guess"] actual = args["actual"] logged_by = args["username"] with databasecontrol.usedatabase(DBconfig) as cursor: _SQL = "INSERT INTO Log " _SQL += "(guess,actual,logged_by) " _SQL += "VALUES (%s,%s,%s)" cursor.execute(_SQL, ( guess, actual, logged_by, )) cursor.close() with databasecontrol.usedatabase(DBconfig) as cursor: _SQL = "SELECT first_name,vehicle_registration,email " _SQL += "FROM MainCarpark " _SQL += "WHERE vehicle_registration=%s" cursor.execute(_SQL, (actual, )) data = cursor.fetchone() cursor.close() if data: with databasecontrol.usedatabase(DBconfig) as cursor: _SQL = "INSERT INTO Infraction " _SQL += "(vehicle_registration,logged_by) " _SQL += "VALUES (%s,%s)" cursor.execute(_SQL, ( actual, logged_by, )) cursor.close() # send email: name, email, reg try: name = data[0] reg = data[1] email = data[2] send_verification_email(name, email, reg) except Exception: return jsonify(registration=actual, infraction=True) return jsonify(registration=actual, infraction=True) return jsonify(registration=actual, infraction=False)
def getAllInfractions(): with databasecontrol.usedatabase(DBconfig) as cursor: _SQL = "SELECT Infraction.vehicle_registration,last_name,first_name,email,time,logged_by " _SQL += "FROM Infraction " _SQL += "INNER JOIN MainCarpark " _SQL += "ON Infraction.vehicle_registration = MainCarpark.vehicle_registration " _SQL += "ORDER by Infraction.vehicle_registration, time" cursor.execute(_SQL,) all_data = cursor.fetchall() cursor.close() with databasecontrol.usedatabase(DBconfig) as cursor: _SQL = "SELECT Infraction.vehicle_registration,last_name,first_name,email,time,logged_by " _SQL += "FROM Infraction " _SQL += "INNER JOIN MainCarpark " _SQL += "ON Infraction.vehicle_registration = MainCarpark.vehicle_registration " _SQL += "WHERE time >= CURDATE() " _SQL += "ORDER by vehicle_registration, time" cursor.execute(_SQL,) today_data = cursor.fetchall() cursor.close() with databasecontrol.usedatabase(DBconfig) as cursor: _SQL = "SELECT Infraction.vehicle_registration,last_name,first_name,email,time,logged_by " _SQL += "FROM Infraction " _SQL += "INNER JOIN MainCarpark " _SQL += "ON Infraction.vehicle_registration = MainCarpark.vehicle_registration " _SQL += "WHERE time >= DATE_SUB(CURDATE(), INTERVAL DAYOFMONTH(CURDATE())-1 DAY) " _SQL += "ORDER by vehicle_registration, time" cursor.execute(_SQL,) month_data = cursor.fetchall() cursor.close() with databasecontrol.usedatabase(DBconfig) as cursor: _SQL = "SELECT Infraction.vehicle_registration,last_name,first_name,email,COUNT(Infraction.vehicle_registration) " _SQL += "FROM Infraction,MainCarpark " _SQL += "WHERE Infraction.vehicle_registration=MainCarpark.vehicle_registration " _SQL += "GROUP by Infraction.vehicle_registration " _SQL += "HAVING COUNT(Infraction.vehicle_registration) > 1 " _SQL += "ORDER by COUNT(Infraction.vehicle_registration)" cursor.execute(_SQL,) repeat_data = cursor.fetchall() cursor.close() return render_template('view_infractions.html', all_data=all_data, today_data=today_data, month_data=month_data, repeat_data=repeat_data, the_title='All Logged Infractions')
def getAllInfractions(): with databasecontrol.usedatabase(DBconfig) as cursor: _SQL = "SELECT Infraction.vehicle_registration,last_name,first_name,email,time,logged_by " _SQL += "FROM Infraction " _SQL += "INNER JOIN MainCarpark " _SQL += "ON Infraction.vehicle_registration = MainCarpark.vehicle_registration " _SQL += "ORDER by Infraction.vehicle_registration, time" cursor.execute(_SQL, ) all_data = cursor.fetchall() cursor.close() with databasecontrol.usedatabase(DBconfig) as cursor: _SQL = "SELECT Infraction.vehicle_registration,last_name,first_name,email,time,logged_by " _SQL += "FROM Infraction " _SQL += "INNER JOIN MainCarpark " _SQL += "ON Infraction.vehicle_registration = MainCarpark.vehicle_registration " _SQL += "WHERE time >= CURDATE() " _SQL += "ORDER by vehicle_registration, time" cursor.execute(_SQL, ) today_data = cursor.fetchall() cursor.close() with databasecontrol.usedatabase(DBconfig) as cursor: _SQL = "SELECT Infraction.vehicle_registration,last_name,first_name,email,time,logged_by " _SQL += "FROM Infraction " _SQL += "INNER JOIN MainCarpark " _SQL += "ON Infraction.vehicle_registration = MainCarpark.vehicle_registration " _SQL += "WHERE time >= DATE_SUB(CURDATE(), INTERVAL DAYOFMONTH(CURDATE())-1 DAY) " _SQL += "ORDER by vehicle_registration, time" cursor.execute(_SQL, ) month_data = cursor.fetchall() cursor.close() with databasecontrol.usedatabase(DBconfig) as cursor: _SQL = "SELECT Infraction.vehicle_registration,last_name,first_name,email,COUNT(Infraction.vehicle_registration) " _SQL += "FROM Infraction,MainCarpark " _SQL += "WHERE Infraction.vehicle_registration=MainCarpark.vehicle_registration " _SQL += "GROUP by Infraction.vehicle_registration " _SQL += "HAVING COUNT(Infraction.vehicle_registration) > 1 " _SQL += "ORDER by COUNT(Infraction.vehicle_registration)" cursor.execute(_SQL, ) repeat_data = cursor.fetchall() cursor.close() return render_template('view_infractions.html', all_data=all_data, today_data=today_data, month_data=month_data, repeat_data=repeat_data, the_title='All Logged Infractions')
def authenticate_user(username, password): with databasecontrol.usedatabase(DBconfig) as cursor: _SQL = "SELECT password FROM AdminStaff WHERE username=%s" cursor.execute(_SQL, (username,)) data = cursor.fetchone() cursor.close() if data: encrypted_password = data[0] return check_password_hash(encrypted_password, password) return False
def authenticate_user(username, password): with databasecontrol.usedatabase(DBconfig) as cursor: _SQL = "SELECT password FROM AdminStaff WHERE username=%s" cursor.execute(_SQL, (username, )) data = cursor.fetchone() cursor.close() if data: encrypted_password = data[0] return check_password_hash(encrypted_password, password) return False
def display_all_registered_vehicles() -> 'html': with databasecontrol.usedatabase(DBconfig) as cursor: _SQL = "Select first_name,last_name,vehicle_registration,email " _SQL += "FROM MainCarpark " _SQL += "ORDER by last_name" cursor.execute(_SQL,) all_vehicles = cursor.fetchall() cursor.close() return render_template('view_all_vehicles.html', all_vehicles=all_vehicles, the_title='View All Registered Vehicles')
def display_all_registered_vehicles() -> 'html': with databasecontrol.usedatabase(DBconfig) as cursor: _SQL = "Select first_name,last_name,vehicle_registration,email " _SQL += "FROM MainCarpark " _SQL += "ORDER by last_name" cursor.execute(_SQL, ) all_vehicles = cursor.fetchall() cursor.close() return render_template('view_all_vehicles.html', all_vehicles=all_vehicles, the_title='View All Registered Vehicles')
def post(self): parser = reqparse.RequestParser() parser.add_argument('username') parser.add_argument('old_password') parser.add_argument('new_password') args = parser.parse_args() username = args['username'] old_password = args["old_password"] new_password = args["new_password"] with databasecontrol.usedatabase(DBconfig) as cursor: _SQL = "SELECT password " _SQL += "FROM Staff " _SQL += "WHERE username=%s" cursor.execute(_SQL, (username, )) data = cursor.fetchone() cursor.close() if data and not check_password_hash(data[0], old_password): reason = "Username or passsword do not match" return jsonify(username=username, success=False, reason=reason) if data and check_password_hash(data[0], new_password): reason = "New password is the same as the old password" return jsonify(username=username, success=False, reason=reason) encrypted_password = generate_password_hash(new_password) with databasecontrol.usedatabase(DBconfig) as cursor: _SQL = "UPDATE Staff " _SQL += "SET password=%s " _SQL += "WHERE username=%s" cursor.execute(_SQL, ( encrypted_password, username, )) cursor.close() return jsonify(username=username, success=True)
def process_register() -> 'html': username = request.form['username'] password = request.form['password'] email = request.form['email'] encrypted_password = generate_password_hash(password) with databasecontrol.usedatabase(DBconfig) as cursor: _SQL = "INSERT INTO Staff " _SQL += "(username, password,email) " _SQL += "VALUES (%s,%s,%s)" cursor.execute(_SQL, (username, encrypted_password,email,)) cursor.close() return render_template('register_staff_verify.html', username=username, email=email, the_title='Register Staff Success')
def process_register_vehicle() -> 'html': first_name = request.form['first_name'] last_name = request.form['last_name'] vehicle_registration = request.form['vehicle_registration'] email = request.form['email'] with databasecontrol.usedatabase(DBconfig) as cursor: _SQL = "INSERT INTO MainCarpark " _SQL += "(last_name,first_name,vehicle_registration,email) " _SQL += "VALUES (%s,%s,%s,%s)" cursor.execute(_SQL, (last_name,first_name,vehicle_registration,email,)) cursor.close() return render_template('register_vehicle_verify.html', first_name=first_name, last_name=last_name, vehicle_registration=vehicle_registration, email=email, the_title='Register Vehicle Success')
def post(self): parser = reqparse.RequestParser() parser.add_argument("username") parser.add_argument("password") args = parser.parse_args() username = args["username"] password = args["password"] with databasecontrol.usedatabase(DBconfig) as cursor: _SQL = "SELECT password " _SQL += "FROM Staff " _SQL += "WHERE username=%s" cursor.execute(_SQL, (username, )) data = cursor.fetchone() cursor.close() if data and check_password_hash(data[0], password): return jsonify(username=username, success=True) return jsonify(username=username, success=False)
def process_register() -> 'html': username = request.form['username'] password = request.form['password'] email = request.form['email'] encrypted_password = generate_password_hash(password) with databasecontrol.usedatabase(DBconfig) as cursor: _SQL = "INSERT INTO Staff " _SQL += "(username, password,email) " _SQL += "VALUES (%s,%s,%s)" cursor.execute(_SQL, ( username, encrypted_password, email, )) cursor.close() return render_template('register_staff_verify.html', username=username, email=email, the_title='Register Staff Success')
def process_register_vehicle() -> 'html': first_name = request.form['first_name'] last_name = request.form['last_name'] vehicle_registration = request.form['vehicle_registration'] email = request.form['email'] with databasecontrol.usedatabase(DBconfig) as cursor: _SQL = "INSERT INTO MainCarpark " _SQL += "(last_name,first_name,vehicle_registration,email) " _SQL += "VALUES (%s,%s,%s,%s)" cursor.execute(_SQL, ( last_name, first_name, vehicle_registration, email, )) cursor.close() return render_template('register_vehicle_verify.html', first_name=first_name, last_name=last_name, vehicle_registration=vehicle_registration, email=email, the_title='Register Vehicle Success')