mirror of
https://github.com/kennethreitz/replit-py.git
synced 2026-06-05 23:10:18 +00:00
Switch to shorter login_wall
all_pages_sign_in was too long
This commit is contained in:
@@ -1,15 +0,0 @@
|
||||
"""An example of the all_pages_sign_in() feature."""
|
||||
from replit import maqpy
|
||||
|
||||
app = maqpy.App(__name__)
|
||||
app.all_pages_sign_in(exclude=["/"])
|
||||
|
||||
|
||||
@app.route("/")
|
||||
def index() -> str:
|
||||
return "Some introduction " + maqpy.Link("check out my page", href="/page")
|
||||
|
||||
|
||||
@app.route("/page")
|
||||
def page() -> str:
|
||||
return "Hello, if you are reading this you signed in."
|
||||
@@ -0,0 +1,23 @@
|
||||
"""An example of the app.login_wall() feature."""
|
||||
from replit import maqpy
|
||||
|
||||
app = maqpy.App(__name__)
|
||||
|
||||
|
||||
def login_page() -> str:
|
||||
return "Hello, please sign in to access this page!\n" + maqpy.signin()
|
||||
|
||||
|
||||
# this is an example of the arguments, but the exclude kwarg already defaults to this
|
||||
# and there is a default handler as well.
|
||||
app.login_wall(exclude=["/"], handler=login_page)
|
||||
|
||||
|
||||
@app.route("/")
|
||||
def index() -> str:
|
||||
return "Some introduction " + maqpy.Link("check out my page", href="/page")
|
||||
|
||||
|
||||
@app.route("/page")
|
||||
def page() -> str:
|
||||
return f"Hello {maqpy.auth.name}, if you are reading this you signed in."
|
||||
@@ -72,12 +72,14 @@ class App(flask.Flask):
|
||||
|
||||
request_class = Request
|
||||
|
||||
def all_pages_sign_in(self, exclude: Set[str] = ("/",)) -> None:
|
||||
"""Require sign-in on all pages.
|
||||
def login_wall(self, exclude: Set[str] = ("/",), handler: Callable = None) -> None:
|
||||
"""Require users to be logged-in on all pages.
|
||||
|
||||
Args:
|
||||
exclude (Tuple[str]): The routes that should not require sign in.
|
||||
Defaults to just /.
|
||||
handler (Callable): The handler to call when the user is not signed in. If
|
||||
not provided, defaults to maqpy.signin()
|
||||
"""
|
||||
self._apsi_exclude = set(exclude) or set()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user