def login(user_email, user_password) -> m_LogicReturn: if v.value_empty(user_email) \ or v.value_empty(user_password): return m_LogicReturn.f_error_msg("Post data is missing!") if not v.verify_email(user_email): return m_LogicReturn.f_error_msg("E-mail is invalid!") v_pass = v.verify_password(user_password) if not v_pass.success: return m_LogicReturn.f_error_msg(v_pass.content) db_resp = db_User().get_user( m_UserEntries.email, user_email ) if not db_resp.success: return m_LogicReturn.f_error_msg("Wrong email/password combination") _User = db_resp.addon_data _User: m_User if not Encryption.verify_password( user_password, _User.password_hash): return m_LogicReturn.f_error_msg("Wrong email/password combination") if not _User.verified: return m_LogicReturn.f_error_msg("User did not verify via email.") logic_resp = SessionLogic.login(_User) if not logic_resp.success: return m_LogicReturn.f_error_msg(logic_resp.content) return m_LogicReturn.f_success_msg("Logged in!")
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 facebook_login(access_token, name, userid) -> m_LogicReturn: if v.value_empty(access_token) \ or v.value_empty(name) \ or v.value_empty(userid): return m_LogicReturn.f_error_msg("missing data!") logic_resp = SocialsLogic.fb_verify_access_token(access_token) if not logic_resp: return m_LogicReturn.f_error_msg("invalid access token") db_resp = db_User().get_user( m_UserEntries.facebook_user_id, userid ) if not db_resp.success: logic_resp = AuthLogic.facebook_register(name, userid) if not logic_resp.success: return m_LogicReturn.f_error_msg(logic_resp.content) db_resp = db_User().get_user( m_UserEntries.facebook_user_id, userid ) _User = db_resp.addon_data _User: m_User logic_resp = SessionLogic.login(_User) if not logic_resp.success: return m_LogicReturn.f_error_msg(logic_resp.content) return m_LogicReturn.f_success_msg("Logged in!")
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 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 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 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 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 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 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 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 update_user_data(_user_dict: dict,form_data) -> m_LogicReturn: #using if type(_user_dict) != dict: return m_LogicReturn.f_error_msg("Session type is invalid") logic_resp = UserLogic.user_data_missing(_user_dict) if not logic_resp.success: return m_LogicReturn.f_error_msg(logic_resp.content) missing_list = logic_resp.addon_data for i in missing_list: form_entry = form_data.get(f"{i}Input", None) if form_entry is not None and len(form_entry) > 0: _user_dict[i] = form_entry new_user = m_User.fromDict(_user_dict) db_resp = DbUser().update_user(new_user) if not db_resp.success: return m_LogicReturn.f_error_msg( db_resp.content) if not SessionLogic.update_session_using_db().success: return m_LogicReturn.f_error_msg( "Updating session gaat fout!") return m_LogicReturn.f_success_msg("Updated user data!")
def google_login(google_token_id, user_email, client_id, avatar_link) -> m_LogicReturn: if v.value_empty(google_token_id) \ or v.value_empty(user_email) \ or v.value_empty(client_id) \ or v.value_empty(avatar_link): return m_LogicReturn.f_error_msg("Data is missing!") if not v.verify_email(user_email): return m_LogicReturn.f_error_msg("E-mail is invalid!") logic_resp = SocialsLogic.verify_token_id(google_token_id, client_id) if not logic_resp.success: return m_LogicReturn.f_error_msg("invalid id token") google_user_id = logic_resp.addon_data db_resp = db_User().get_user( m_UserEntries.google_user_id, google_user_id ) if not db_resp.success: logic_resp = AuthLogic.google_register( google_user_id, user_email, avatar_link) if not logic_resp.success: return m_LogicReturn.f_error_msg(logic_resp.content) db_resp = db_User().get_user( m_UserEntries.google_user_id, google_user_id ) _User = db_resp.addon_data _User: m_User logic_resp = SessionLogic.login(_User) if not logic_resp.success: return m_LogicReturn.f_error_msg(logic_resp.content) return m_LogicReturn.f_success_msg("Logged in!")
def decorated_function(*args, **kwargs): debug.print_v("on update_session") debug.print_v("Updating session...") SessionLogic.update_session_using_db() return f(*args, **kwargs)
def logout() -> m_LogicReturn: return SessionLogic.logout()