Switch to shorter login_wall

all_pages_sign_in was too long
This commit is contained in:
Scoder12
2020-07-28 12:21:27 -07:00
parent 03535d3e8d
commit a9026f77e8
3 changed files with 27 additions and 17 deletions
-15
View File
@@ -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."
+23
View File
@@ -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."
+4 -2
View File
@@ -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()