mirror of
https://gitlab.com/octospacc/TelegramIndex-Fork.git
synced 2025-06-05 22:09:12 +02:00
add redirection memory
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
{% endif %}
|
||||
<form class="mt-8 space-y-6" action="/login" method="POST">
|
||||
<input type="hidden" name="remember" value="true">
|
||||
<input type="hidden" name="redirect_to" value="{{redirect_to}}">
|
||||
<div class="rounded-md shadow-sm -space-y-px">
|
||||
<div>
|
||||
<label for="email-address" class="sr-only">Username</label>
|
||||
|
@@ -13,25 +13,27 @@ class LoginView:
|
||||
|
||||
async def login_post(self, req):
|
||||
post_data = await req.post()
|
||||
redirect_to = post_data.get("redirect_to") or "/"
|
||||
location = req.app.router["login_page"].url_for()
|
||||
if redirect_to != "/":
|
||||
location = location.update_query({"redirect_to": redirect_to})
|
||||
|
||||
if "username" not in post_data:
|
||||
loc = location.with_query({"error": "Username missing"})
|
||||
loc = location.update_query({"error": "Username missing"})
|
||||
raise web.HTTPFound(location=loc)
|
||||
|
||||
if "password" not in post_data:
|
||||
loc = location.with_query({"error": "Password missing"})
|
||||
loc = location.update_query({"error": "Password missing"})
|
||||
raise web.HTTPFound(location=loc)
|
||||
|
||||
authenticated = (post_data["username"] == req.app["username"]) and (
|
||||
post_data["password"] == req.app["password"]
|
||||
)
|
||||
if not authenticated:
|
||||
loc = location.with_query({"error": "Wrong Username or Passowrd"})
|
||||
loc = location.update_query({"error": "Wrong Username or Passowrd"})
|
||||
raise web.HTTPFound(location=loc)
|
||||
|
||||
resp = web.Response(
|
||||
status=302, headers={"Location": str(req.app.router["home"].url_for())}
|
||||
)
|
||||
resp = web.Response(status=302, headers={"Location": redirect_to})
|
||||
now = time.time()
|
||||
resp.set_cookie(
|
||||
name="_tgindex_session",
|
||||
|
@@ -18,6 +18,9 @@ def middleware_factory():
|
||||
]:
|
||||
cookies = request.cookies
|
||||
url = request.app.router["login_page"].url_for()
|
||||
if str(request.rel_url) != "/":
|
||||
url = url.with_query(redirect_to=str(request.rel_url))
|
||||
|
||||
if any(x not in cookies for x in ("_tgindex_session", "_tgindex_secret")):
|
||||
raise HTTPFound(url)
|
||||
|
||||
|
Reference in New Issue
Block a user