def pull_project(endpoint, values): """When a request contains a project_id value, transform it directly into a project by checking the credentials stored in the session. With administration credentials, one can access any project. If not, redirect the user to an authentication form """ if endpoint == "authenticate": return if not values: values = {} project_id = values.pop("project_id", None) if project_id: project = Project.query.get(project_id) if not project: raise Redirect303(url_for(".create_project", project_id=project_id)) is_admin = session.get("is_admin") if session.get(project.id) or is_admin: # add project into kwargs and call the original function g.project = project else: # redirect to authentication page raise Redirect303(url_for(".authenticate", project_id=project_id))
def demo(): """ Authenticate the user for the demonstration project and redirect him to the bills list for this project. Create a demo project if it doesn't exists yet (or has been deleted) If the demo project is deactivated, one is redirected to the create project form """ is_demo_project_activated = current_app.config["ACTIVATE_DEMO_PROJECT"] project = Project.query.get("demo") if not project and not is_demo_project_activated: raise Redirect303(url_for(".create_project", project_id="demo")) if not project and is_demo_project_activated: project = Project( id="demo", name="demonstration", password=generate_password_hash("demo"), contact_email="*****@*****.**", default_currency="EUR", ) db.session.add(project) db.session.commit() session[project.id] = True return redirect(url_for(".list_bills", project_id=project.id))
def admin_auth(*args, **kws): is_admin_auth_bypassed = False if bypass is not None and current_app.config.get(bypass[0]) == bypass[1]: is_admin_auth_bypassed = True is_admin = session.get("is_admin") if is_admin or is_admin_auth_bypassed: return f(*args, **kws) raise Redirect303(url_for(".admin", goto=request.path))
def demo(): """ Authenticate the user for the demonstration project and redirects to the bills list for this project. Create a demo project if it doesn't exists yet (or has been deleted) If the demo project is deactivated, redirects to the create project form. """ is_demo_project_activated = current_app.config["ACTIVATE_DEMO_PROJECT"] project = Project.query.get("demo") if not project and not is_demo_project_activated: raise Redirect303(url_for(".create_project", project_id="demo")) if not project and is_demo_project_activated: project = Project.create_demo_project() session[project.id] = True return redirect(url_for(".list_bills", project_id=project.id))