def findlock_delete(fl_uuid): debug.print_v(f"on findlock_delete with fl_uuid:{fl_uuid}") logic_resp = ViewAdminLogic.findlock_delete(fl_uuid) if not logic_resp.success: debug.print_e(logic_resp.content) return Returns.return_message("Something went wrong!", logic_resp.content, 2,r.custom_findlock(fl_uuid)) return Returns.return_message("Deleted!", "", 1, r.findlocks.route_path)
def user_delete(u_uuid): debug.print_v(f"user_delete on u_uuid:{u_uuid}") logic_resp = ViewAdminLogic.user_delete(u_uuid) if not logic_resp.success: debug.print_e(logic_resp.content) return Returns.return_message("Something went wrong!", logic_resp.content, 2, r.custom_user(u_uuid)) #fix me in de toekomst return Returns.return_message("Deleted!", "User has been deleted!", 0, r.users.route_path)
def findlock_add_gps(fl_uuid): if request.method == 'GET': return render_template('admin/findlock_add_gps.html') debug.print_v(f"on findlock_add_gps with fl_uuid:{fl_uuid} | form_data: {request.form}" ) logic_resp = ViewAdminLogic.add_gps_loc_to_findlock(fl_uuid, request.form) if not logic_resp.success: return Returns.return_message("Something went wrong!", logic_resp.content, 2,r.custom_findlock(fl_uuid)) return Returns.return_message("Added!", "ok!",2, r.custom_findlock(fl_uuid))
def logout(): debug.print_v("on logout()") logic_resp = ViewAuthLogic.logout() if not logic_resp.success: return Returns.return_message("Something went wrong!", "Can't logout!", 2, "") return Returns.return_message("You are logged out!", "Redirecting to main page", 2, rLanding.index.route_path)
def verify(confirm_token): debug.print_v("on verify()") logic_resp = ViewAuthLogic.verify_confirm_code(confirm_token) if not logic_resp.success: return Returns.return_message("Something went wrong!", logic_resp.content, 2, rLanding.index.route_path) return Returns.return_message("Ok!", logic_resp.content, 2, r.index.route_path)
def decorated_function(*args, **kwargs): logic_resp = SessionLogic.get() if not logic_resp.success: return Returns.return_message("Error connecting to the database!", "Try again later!", 5, rLanding.index.route_path) _session = logic_resp.addon_data _session: m_Session if not _session.User.is_admin: return Returns.return_message("You are not allowed to do this!", "^", 2, rAuth.logout.route_path) return f(*args, **kwargs)
def add_friend(): if request.method == 'GET': return render_template("webapp/user/confirm.html") logic_resp = SessionLogic.get() if not logic_resp.success: return Returns.return_message("Something went wrong!", logic_resp.content, 2, r.index.route_path) _session = logic_resp.addon_data _session: m_Session print(request.form) logic_resp = ViewUserLogic.add_friend(_session, request.form) if not logic_resp.success: return Returns.return_message("Failed to add a friend!", logic_resp.content, 2, r.index.route_path) return Returns.return_message("Friend added!", logic_resp.content, 2, r.index.route_path)
def user(u_uuid): debug.print_v(f"on user with u_uuid:{u_uuid}") logic_resp = ViewAdminLogic.get_user_info(u_uuid) if not logic_resp.success: return Returns.return_message("Something went wrong!", logic_resp.content, 2, r.custom_user(u_uuid)) _user = logic_resp.addon_data _user: m_User logic_resp = ViewAdminLogic.get_user_entries() if not logic_resp.success: return Returns.return_message("Something went wrong!", logic_resp.content, 2, r.custom_user(u_uuid)) _user_entries = logic_resp.addon_data return render_template('admin/user.html', user=_user, user_dict=_user.toDict(),user_entries=_user_entries)
def fingerprints_screen(d_uuid): logic_resp = SessionLogic.get() if not logic_resp.success: return Returns.return_message("Something went wrong!", logic_resp.content, 2, r.index.route_path) _session = logic_resp.addon_data _session: m_Session logic_resp = ViewUserLogic.get_allowed_users_for_findlock(d_uuid) if not logic_resp.success: return Returns.return_message("Something went wrong!", logic_resp.content, 2, r.index.route_path) list_of_names = logic_resp.addon_data return render_template("webapp/user/fingerprint.html", list_of_names=list_of_names)
def decorated_function(*args, **kwargs): debug.print_v("on needs_to_be_guest()") logic_resp = SessionLogic.get() if not logic_resp.success: debug.print_e(f"needs_to_be_guest: {logic_resp.content}") return Returns.return_message("Error connecting to the database!", "Please try again later!", 5, rLanding.index.route_path) User_Session = logic_resp.addon_data User_Session: m_Session if User_Session.logged_in: debug.print_w(f"needs_to_be_guest: already registered") return Returns.return_message("You are already registered!", "", 0, rUser.index.route_path) return f(*args, **kwargs)
def findlock(fl_uuid): debug.print_v(f"on findlock with fl_uuid:{fl_uuid}") logic_resp = ViewAdminLogic.get_findlock_info(fl_uuid) if not logic_resp.success: return Returns.return_message("Something went wrong!", logic_resp.content, 2, r.findlocks.route_path) _findlock = logic_resp.addon_data _findlock: m_Findlock logic_resp = ViewAdminLogic.get_findlock_entries() if not logic_resp.success: return Returns.return_message("Something went wrong!", logic_resp.content, 2, r.findlocks.route_path) _findlock_entries = logic_resp.addon_data return render_template('admin/findlock.html', findlock=_findlock, findlock_dict=_findlock.toDict(),findlock_entries=_findlock_entries)
def settings_screen(): logic_resp = SessionLogic.get() if not logic_resp.success: return Returns.return_message("Something went wrong!", logic_resp.content, 2, r.index.route_path) _session = logic_resp.addon_data _session: m_Session return render_template("webapp/user/settings.html", session=_session)
def new_device(): logic_resp = SessionLogic.get() if not logic_resp.success: return Returns.return_message("Something went wrong!", logic_resp.content, 2, r.index.route_path) _session = logic_resp.addon_data _session: m_Session if request.method == 'GET': return render_template('user/new_device.html') logic_resp = ViewUserLogic.pair_with_findlock( _session, request.form ) if not logic_resp.success: return Returns.return_message("Something went wrong!", logic_resp.content, 2, r.index.route_path) return Returns.return_message("Paired!", "Nice!", 2, r.index.route_path)
def register(): debug.print_v("on register()") if request.method == 'GET': debug.print_v("Sending html page back (GET)") return render_template('webapp/auth/register.html') logic_resp = ViewAuthLogic.register(request.form) if not logic_resp.success: debug.print_e(logic_resp.content) return Returns.return_message("Something went wrong!", logic_resp.content, 2, rAuth.index.route_path) return Returns.return_message( "Message", "You are registered. please activate your account via email!", 5, rAuth.index.route_path)
def index(): logic_resp = SessionLogic.get() if not logic_resp.success: return Returns.return_message("Something went wrong!", logic_resp.content, 2, r.index.route_path) _session = logic_resp.addon_data _session: m_Session logic_resp = ViewUserLogic.user_data_is_missing(_session) if logic_resp.success: # account misses some data return redirect(r.update.route_path) logic_resp = ViewUserLogic.get_user_findlocks(_session) if not logic_resp.success: return Returns.return_message("Failed!", logic_resp.content, 2, rAuth.logout.route_path) print(logic_resp.addon_data) return render_template("webapp/user/profile.html", Session=_session, findlocks=logic_resp.addon_data, findlocks_n=len(logic_resp.addon_data))
def update(): logic_resp = SessionLogic.get() if not logic_resp.success: return Returns.return_message("Something went wrong!", logic_resp.content, 2, r.index.route_path) _session = logic_resp.addon_data _session: m_Session if request.method == 'POST': logic_resp = ViewUserLogic.update_user_data(_session, request.form) if not logic_resp.success: return Returns.return_message("Something went wrong!", logic_resp.content, 2, r.index.route_path) return redirect(r.index.route_path) logic_resp = ViewUserLogic.user_data_is_missing(_session) if not logic_resp.success: return Returns.return_message("Something went wrong", logic_resp.content, 2, r.index.route_path) return render_template('user/fill_in_data.html', missing_data=logic_resp.addon_data)
def device(d_uuid): logic_resp = SessionLogic.get() if not logic_resp.success: return Returns.return_message("Something went wrong!", logic_resp.content, 2, r.index.route_path) _session = logic_resp.addon_data _session: m_Session logic_resp = ViewUserLogic.user_allowed_to_use_findlock(_session, d_uuid) if not logic_resp.success: return Returns.return_message("Something went wrong!", logic_resp.content, 2,r.index.route_path) logic_resp = ViewUserLogic.get_findlock_info(d_uuid) if not logic_resp.success: return Returns.return_message("Something went wrong!", logic_resp.content, 2, r.index.route_path) _findlock = logic_resp.addon_data _findlock: m_Findlock #return render_template("user/device.html", findlock=_findlock, session=_session) return render_template("webapp/user/home.html", findlock=_findlock, session=_session)
def index(): debug.print_v("on index()") if request.method == 'GET': debug.print_v("Sending html page back (GET)") return render_template('webapp/auth.html', AuthRoutes=rAuth) logic_resp = ViewAuthLogic.login(request.form) if not logic_resp.success: debug.print_e(logic_resp.content) return Returns.return_message("Something went wrong!", logic_resp.content, 2, r.index.route_path) print(request.args.get("redirectUri", None)) #check if redirectUri is here redirect_override_url = request.args.get("redirectUri", None) redirect_to = redirect_override_url if redirect_override_url is not None else rUser.index.route_path return Returns.return_message("Message", logic_resp.content, 1, redirect_to)
def decorated_function(*args, **kwargs): logic_resp = SessionLogic.get() if not logic_resp.success: return Returns.return_message("Error connecting to the database!", "Please try again later!", 5, rLanding.index.route_path) User_Session = logic_resp.addon_data User_Session: m_Session if not User_Session.logged_in: login_path = rAuth.index.route_path if request.path != rAuth.logout.route_path: login_path += f"?redirectUri={request.path}" return Returns.return_message("You need to be logged in!", "^", 2, login_path) if User_Session.User is None: return Returns.return_message("user session is corrupted!", "Please try again!", 2, rAuth.index.route_path) return f(*args, **kwargs)
def users(): debug.print_v("on users") logic_resp_users = ViewAdminLogic.get_list_of_users() logic_resp_entries = ViewAdminLogic.get_list_of_user_entries() if not logic_resp_users.success: return Returns.return_message( "Something went wrong!", logic_resp_users.content, 2, r.index.route_path ) return render_template('admin/users.html', Users=logic_resp_users.addon_data, UsersEntries=logic_resp_entries )
def findlock_update(fl_uuid): logic_resp = ViewAdminLogic.findlock_update(fl_uuid, request.form) if not logic_resp.success: return Returns.return_message("Something went wrong!", logic_resp.content, 2, r.custom_findlock(fl_uuid)) return Returns.return_message("Updated!", "Findlock data has been updated!", 2, r.custom_findlock(fl_uuid))
def user_update(u_uuid): logic_resp = ViewAdminLogic.user_update(u_uuid, request.form) if not logic_resp.success: return Returns.return_message("Something went wrong!", logic_resp.content, 2, r.users.route_path) return Returns.return_message("Updated!", "User data has been updated!", 2, r.custom_user(u_uuid))
def user_send_mail(u_uuid): logic_resp = ViewAdminLogic.user_send_mail(u_uuid, request.form) if not logic_resp.success: return Returns.return_message("Something went wrong!", logic_resp.content, 2, r.custom_user(u_uuid)) return Returns.return_message("Email sent!", "", 2, r.custom_user(u_uuid))
def wipe_action(col): logic_resp = ViewAdminLogic.wipe_collection(col) if not logic_resp.success: return Returns.return_message("Something went wrong!", logic_resp.content, 2, r.index.route_path) return Returns.return_message("Executed.", logic_resp.content, 2, r.index.route_path)