def login(): if request.method == 'GET': return render_template("auth/auth_login.html", login_type="Dashboard") user_password = request.form.get("passwordInput", None) user_email = request.form.get("emailInput", None) if user_password is None \ or user_email is None: return gpReturns.return_message("Error", "Try again.", 3, url_for("gpView_login.login")) resp = gpDb.get_user(email=user_email) if resp[0] is not True: return gpReturns.return_message("Error", resp[1], 3, url_for("gpView_login.login")) user = resp[1] user_hash = user['hash'] resp = gpEncryption.gpEncryption.verify_password(user_password, user_hash) if not resp: return gpReturns.return_message("Error", "Wrong email/password combination", 2, url_for("gpView_login.login")) userSession = gpSession.gpSession(session) userSession.login_user(user) userSession.update_ses(session) return gpReturns.return_message("Hello, {name}".format(name=user['name']), "You are logged in!", 2, url_for("gpView_dashboard.main"))
def user_assign(): user = session.get("user", None) if user is None: raise Exception("Logic error #2") if request.method == 'GET': assigned_devices = gpDb.get_gptrackers(user['uuid']) print(assigned_devices) return render_template("track/track_user_assign.html") gptrack_uuid = request.form.get("deviceUuidInput") gptrack_name = request.form.get("nameInput") if gptrack_uuid is None \ or gptrack_name is None: return gpReturns.return_message("Error", "Try again!", 3, url_for("gpView_track.user_assign")) gptrack_owner_uuid = user['uuid'] result = gpDb.register_gptracker(gptrack_uuid, gptrack_owner_uuid, gptrack_name) if result[0] is False: return gpReturns.return_message("Error", "{}".format(result[1]), 2, url_for("gpView_track.manage")) return gpReturns.return_message("GPTracker assigned!", "Redirecting to your dashboard!", 1, url_for("gpView_dashboard.main"))
def decorated_function(*args, **kwargs): adminSession = gpSession.gpSession(session) if adminSession.admin_username is None \ or adminSession.admin_password is None: return gpReturns.return_message("You don't have access to this page!", ":(", 3, url_for("gpView_admin.login")) if adminSession.admin_username != app_config.ADMIN_USERNAME \ or adminSession.admin_password != app_config.ADMIN_PASSWORD: return gpReturns.return_message("You don't have access to this page (anymore)!", 2, url_for("gpView_admin.login")) return f(*args, **kwargs)
def decorated_function(*args, **kwargs): userSession = gpSession.gpSession(session) if userSession.logged_in is False or userSession.logged_in is None: userSession.logout_user() userSession.update_ses(session) return gpReturns.return_message("You need to be logged in!", "Redirecting to login page", 1, url_for("gpView_login.login")) if gpDb.get_user(uuid=userSession.user['uuid'])[0] is False: userSession.logout_user() userSession.update_ses(session) return gpReturns.return_message("Your account is no longer valid!", "Try to login again!", 1, url_for("gpView_login.login")) return f(*args, **kwargs)
def users_edit_update(uuid): user_uuid = str(uuid) user_name = request.form.get("nameInput", None) user_email = request.form.get("emailInput", None) if user_name is None \ or user_email is None: return gpReturns.return_message("Error", "Try again", 2, url_for("gpView_admin.users")) resp = gpDb.update_user(user_uuid, user_name, user_email) return gpReturns.return_message(resp[0], resp[1], 2, url_for("gpView_admin.users"))
def update(device_uuid, key, value): resp = gpDb.get_gptracker(device_uuid) if resp[0] is not True: return gpReturns.return_message(False, "This tracker is not registered!") if key == "gps": gpDb.update_gptracker_data_gps(device_uuid, str(value)) return gpReturns.return_message(True, "Updated!") elif key == "hr": gpDb.update_gptracker_data_hr(device_uuid, str(value)) return gpReturns.return_message(True, "Updated!") return gpReturns.return_message( False, "This key ({key}) does not exist!".format(key=key))
def trackers_edit_update(uuid): gptracker_uuid = str(uuid) gptracker_name = request.form.get("nameInput", None) gptracker_owner_uuid = request.form.get("ownerUuidInput", None) if gptracker_name is None \ or gptracker_owner_uuid is None: return gpReturns.return_message("Error", "Try again", 2, url_for("gpView_admin.trackers")) result = gpDb.update_gptracker(gptracker_uuid, gptracker_name, gptracker_owner_uuid) return gpReturns.return_message(result[0], result[1], 2, url_for("gpView_admin.trackers"))
def trackers_add(): gptracker_uuid = request.form.get("uuidInput", None) gptracker_name = request.form.get("nameInput", None) gptracker_owner_uuid = request.form.get("ownerUuidInput", None) if gptracker_name is None \ or gptracker_uuid is None \ or gptracker_owner_uuid is None: return gpReturns.return_message("Error", "Try again", 2, url_for("gpView_admin.trackers")) resp = gpDb.create_gptrack(gptracker_uuid, gptracker_name, gptracker_owner_uuid) return gpReturns.return_message(resp[0], resp[1], 3, url_for("gpView_admin.trackers"))
def logout(): userSession = gpSession.gpSession(session) userSession.logout_admin() userSession.update_ses(session) return gpReturns.return_message("Logged out!", "", 1, url_for("gpView_admin.main"))
def users_edit(uuid): user = gpDb.get_user(uuid=uuid) if user[0] is not True: return gpReturns.return_message("Error", user[1], 2, url_for("gpView_admin.users")) user = user[1] return render_template("admin/users/admin_users_edit.html", user=user)
def manage_edit(uuid, action): gptracker_uuid = str(uuid) userSession = gpSession.gpSession(session) if userSession.user is None: raise Exception("Logic error #4") if action == 'unregister': result = gpDb.unregister_gptracker(gptracker_uuid) if result[0] is not True: return gpReturns.return_message("Error", result[1], 2, url_for("gpView_track.manage")) return gpReturns.return_message("Unregistered!", "Redirecting to manage page", 2, url_for("gpView_track.manage")) else: return gpReturns.return_message("Not implemented", "This function is not implemented!", 2, url_for("gpView_track.manage"))
def login(): if request.method == 'GET': return render_template("auth/auth_login.html", login_type="ADMIN") admin_password = request.form.get("passwordInput", None) admin_email = request.form.get("emailInput", None) if admin_email is None \ or admin_password is None: return gpReturns.return_message("Error", "Try again", 1, "") if admin_email == app_config.ADMIN_USERNAME: if admin_password == app_config.ADMIN_PASSWORD: adminSession = gpSession.gpSession(session) adminSession.login_admin(admin_email, admin_password) adminSession.update_ses(session) return gpReturns.return_message("Logged in!", "Haii admin :3", 2, url_for("gpView_admin.main")) return gpReturns.return_message("Failed!", "Try again :p", 1, "")
def trackers_edit_update_gps(uuid): print(request.url_rule.rule) gptracker_uuid = str(uuid) if "update_gps" in request.url_rule.rule: gptracker_data = request.form.get("gpsInput", None) else: gptracker_data = request.form.get("hrInput", None) if gptracker_data is None: return gpReturns.return_message("Error", "Try again", 2, url_for("gpView_admin.trackers")) if "update_gps" in request.url_rule.rule: result = gpDb.update_gptracker_data_gps(gptracker_uuid, gptracker_data) else: result = gpDb.update_gptracker_data_hr(gptracker_uuid, gptracker_data) return gpReturns.return_message(result[0], result[1], 2, url_for("gpView_admin.trackers"))
def decorated_function(*args, **kwargs): userSession = gpSession.gpSession(session) if userSession.user is None: raise Exception("Logic error #1") user_uuid = userSession.user['uuid'] trackers_list = gpDb.get_gptrackers(user_uuid) if trackers_list[0] is False: return gpReturns.return_message("You need to register an GPTracker", "Will redirect you to the GPTrack Register page", 2, url_for("gpView_track.user_assign")) return f(*args, **kwargs)
def get_reminders(device_uuid): resp = gpDb.get_gptracker(device_uuid) if resp[0] is not True: return gpReturns.return_to_arduino(False, "This tracker is not registered!") result = gpDb.get_device_reminders(device_uuid) if result[0] is not True: return gpReturns.return_message(False, "No reminders") return gpReturns.return_reminders(result[1])
def main(): gp_trackers = gpDb.get_gptrackers(session['user']['uuid']) if gp_trackers[0] is not True: return gpReturns.return_message( "Error", "There are no GPTrackers assigned to your account!", 1, "gpView_track.assign_user") unified = gpDb.make_unified_gptracker_data(gp_trackers[1]) return render_template("dashboard/dashboard.html", name=session['user']['name'], gp_trackers_unified=unified)
def register(): if request.method == 'GET': return render_template("auth/auth_register.html") user_password = request.form.get("passwordInput", None) user_email = request.form.get("emailInput", None) user_name = request.form.get("nameInput", None) if user_password is None \ or user_email is None \ or user_name is None: return gpReturns.return_message("Error", "Try again.", 3, url_for("gpView_login.register")) resp = gpDb.add_user(user_name, user_email, user_password) if resp[0] is not True: return gpReturns.return_message("Error", resp[1], 3, url_for("gpView_login.register")) return gpReturns.return_message("Ok!", "Account created!", 3, url_for("gpView_login.login"))
def trackers_edit(uuid): tracker = gpDb.get_gptracker(uuid) tracker_data = gpDb.get_gptracker_data(uuid) if tracker[0] is not True: return gpReturns.return_message("Error", tracker[1], 2, url_for("gpView_admin.trackers")) if tracker_data[0] is not True: tracker_data[1] = {"gps": None, "hr": None} tracker = tracker[1] tracker_data = tracker_data[1] return render_template("admin/trackers/admin_trackers_edit.html", tracker=tracker, tracker_data=tracker_data)
def reminders(): if request.method == 'GET': reminders = gpDb.get_reminders(uuid=session['user']['uuid']) paired_devices = gpDb.get_gptrackers(session['user']['uuid']) if paired_devices[0] is not True: return gpReturns.return_message( "Something went wrong", "Assign GP tracker ofs", 1, url_for("gpView_dashboard.reminders")) if reminders[0] is not True: print("There are no reminders!") reminders[1] = [] #return gpReturns.return_message("Something went wrong.", "Try again", 1, url_for("gpView_dashboard.reminders")) return render_template("dashboard/reminders.html", rem=reminders[1], paired_devices=paired_devices[1]) reminder_content = request.form.get("contentInput", None) reminder_time = request.form.get("timeInput", None) reminder_creator_uuid = session['user']['uuid'] reminder_device_uuid = request.form.get("deviceRadio", None) if reminder_time is None \ or reminder_content is None \ or reminder_device_uuid is None: return gpReturns.return_message("Error", "Try again.", 1, url_for("gpView_dashboard.reminders")) resp = gpDb.create_reminder(reminder_content, reminder_time, reminder_creator_uuid, reminder_device_uuid) if resp[0] is not True: return gpReturns.return_message("Error", resp[1], 2, url_for("gpView_dashboard.main")) return gpReturns.return_message("Reminder added!", "Redirecting to reminders!", 1, url_for("gpView_dashboard.reminders"))
def manage(): user = session.get("user", None) if user is None: raise Exception("Logic error #3") gp_trackers = gpDb.get_gptrackers(user['uuid']) if gp_trackers[0] is not True: return gpReturns.return_message("Error", "There are no gptrackers assigned!", 2, url_for("gpView_track.user_assign")) unified = gpDb.make_unified_gptracker_data(gp_trackers[1]) return render_template("track/track_manage.html", gp_trackers_unified=unified, edit_url="/track/manage/edit")
def test_no_reminders(): return gpReturns.return_message(False, "No reminders")
def logout(): userSession = gpSession.gpSession(session) userSession.logout_user() userSession.update_ses(session) return gpReturns.return_message("Logged out!", "Redirecting to login page", 1, url_for("gpView_login.login"))
def users_delete(uuid): resp = gpDb.remove_user(uuid) return gpReturns.return_message(resp[0], resp[1], 2, url_for("gpView_admin.users"))
def wipe_this_shit(): gpDb.drop_all_dbs() return gpReturns.return_message("Database is wiped!", "You can start from scratch!", 2, url_for("map"))
def decorated_function(*args, **kwargs): if app_config.ADMIN_PANEL_ENABLED: return f(*args, **kwargs) return gpReturns.return_message("Panel is disabled", "You can't use it!", 60, "")
def decorated_function(*args, **kwargs): if gpSession.gpSession(session).logged_in is True: return gpReturns.return_message("You need to be logged out!", "Redirecting to dashboard", 2, url_for("gpView_dashboard.main")) return f(*args, **kwargs)
def test_reminders(): resp = gpDb.get_all_reminders() if resp[0] is not True: return gpReturns.return_message(False, "No reminders") return gpReturns.return_reminders(resp[1])
def trackers_delete(uuid): resp = gpDb.remove_gptrack(uuid) return gpReturns.return_message(resp[0], resp[1], 2, url_for("gpView_admin.trackers"))
def get_name(device_uuid): resp = gpDb.get_gptracker(device_uuid) if resp[0] is not True: return gpReturns.return_message(False, "This tracker does not exist!") return gpReturns.return_message(True, resp[1]['name'])