platzky 0.3.3__py3-none-any.whl → 0.3.5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
platzky/admin/fake_login.py
CHANGED
|
@@ -8,7 +8,8 @@ environments as it bypasses proper authentication and authorization controls.
|
|
|
8
8
|
import os
|
|
9
9
|
from typing import Any, Callable
|
|
10
10
|
|
|
11
|
-
from flask import Blueprint, flash, redirect, session, url_for
|
|
11
|
+
from flask import Blueprint, flash, redirect, render_template_string, session, url_for
|
|
12
|
+
from flask_wtf import FlaskForm
|
|
12
13
|
from markupsafe import Markup
|
|
13
14
|
|
|
14
15
|
ROLE_ADMIN = "admin"
|
|
@@ -16,6 +17,17 @@ ROLE_NONADMIN = "nonadmin"
|
|
|
16
17
|
VALID_ROLES = [ROLE_ADMIN, ROLE_NONADMIN]
|
|
17
18
|
|
|
18
19
|
|
|
20
|
+
class FakeLoginForm(FlaskForm):
|
|
21
|
+
"""
|
|
22
|
+
Empty form class that inherits CSRF protection from FlaskForm.
|
|
23
|
+
|
|
24
|
+
Used specifically for the fake login functionality to enable
|
|
25
|
+
CSRF token validation on form submissions.
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
pass
|
|
29
|
+
|
|
30
|
+
|
|
19
31
|
def get_fake_login_html() -> Callable[[], str]:
|
|
20
32
|
"""Return a callable that generates HTML for fake login buttons."""
|
|
21
33
|
|
|
@@ -23,8 +35,11 @@ def get_fake_login_html() -> Callable[[], str]:
|
|
|
23
35
|
admin_url = url_for("admin.handle_fake_login", role="admin")
|
|
24
36
|
nonadmin_url = url_for("admin.handle_fake_login", role="nonadmin")
|
|
25
37
|
|
|
26
|
-
#
|
|
27
|
-
|
|
38
|
+
# Create a form instance to get the CSRF token
|
|
39
|
+
form = FakeLoginForm()
|
|
40
|
+
|
|
41
|
+
html = render_template_string(
|
|
42
|
+
"""
|
|
28
43
|
<div class="col-md-6 mb-4">
|
|
29
44
|
<div class="card">
|
|
30
45
|
<div class="card-header">
|
|
@@ -33,19 +48,24 @@ def get_fake_login_html() -> Callable[[], str]:
|
|
|
33
48
|
<div class="card-body">
|
|
34
49
|
<p class="text-danger"><strong>Warning:</strong> For development only</p>
|
|
35
50
|
<div class="d-flex justify-content-around">
|
|
36
|
-
<form method="post" action="{admin_url}" style="display: inline;">
|
|
37
|
-
|
|
51
|
+
<form method="post" action="{{ admin_url }}" style="display: inline;">
|
|
52
|
+
{{ form.csrf_token }}
|
|
38
53
|
<button type="submit" class="btn btn-primary">Login as Admin</button>
|
|
39
54
|
</form>
|
|
40
|
-
<form method="post" action="{nonadmin_url}" style="display: inline;">
|
|
41
|
-
|
|
55
|
+
<form method="post" action="{{ nonadmin_url }}" style="display: inline;">
|
|
56
|
+
{{ form.csrf_token }}
|
|
42
57
|
<button type="submit" class="btn btn-secondary">Login as Non-Admin</button>
|
|
43
58
|
</form>
|
|
44
59
|
</div>
|
|
45
60
|
</div>
|
|
46
61
|
</div>
|
|
47
62
|
</div>
|
|
48
|
-
"""
|
|
63
|
+
""",
|
|
64
|
+
form=form,
|
|
65
|
+
admin_url=admin_url,
|
|
66
|
+
nonadmin_url=nonadmin_url,
|
|
67
|
+
)
|
|
68
|
+
|
|
49
69
|
return Markup(html)
|
|
50
70
|
|
|
51
71
|
return generate_html
|
|
@@ -70,13 +90,15 @@ def setup_fake_login_routes(admin_blueprint: Blueprint) -> Blueprint:
|
|
|
70
90
|
|
|
71
91
|
@admin_blueprint.route("/fake-login/<role>", methods=["POST"])
|
|
72
92
|
def handle_fake_login(role: str) -> Any:
|
|
73
|
-
|
|
74
|
-
|
|
93
|
+
form = FakeLoginForm()
|
|
94
|
+
if form.validate_on_submit() and role in VALID_ROLES:
|
|
95
|
+
if role == ROLE_ADMIN:
|
|
96
|
+
session["user"] = {"username": ROLE_ADMIN, "role": ROLE_ADMIN}
|
|
97
|
+
else:
|
|
98
|
+
session["user"] = {"username": "user", "role": ROLE_NONADMIN}
|
|
75
99
|
return redirect(url_for("admin.admin_panel_home"))
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
else:
|
|
79
|
-
session["user"] = {"username": "user", "role": ROLE_NONADMIN}
|
|
100
|
+
|
|
101
|
+
flash(f"Invalid role: {role}. Must be one of: {', '.join(VALID_ROLES)}", "error")
|
|
80
102
|
return redirect(url_for("admin.admin_panel_home"))
|
|
81
103
|
|
|
82
104
|
return admin_blueprint
|
platzky/platzky.py
CHANGED
|
@@ -3,6 +3,7 @@ import urllib.parse
|
|
|
3
3
|
|
|
4
4
|
from flask import redirect, render_template, request, session
|
|
5
5
|
from flask_minify import Minify
|
|
6
|
+
from flask_wtf import CSRFProtect
|
|
6
7
|
|
|
7
8
|
from platzky.admin import admin
|
|
8
9
|
from platzky.blog import blog
|
|
@@ -107,6 +108,7 @@ def create_app_from_config(config: Config) -> Engine:
|
|
|
107
108
|
engine.register_blueprint(seo_blueprint)
|
|
108
109
|
|
|
109
110
|
Minify(app=engine, html=True, js=True, cssless=True)
|
|
111
|
+
CSRFProtect(app=engine)
|
|
110
112
|
return engine
|
|
111
113
|
|
|
112
114
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
platzky/__init__.py,sha256=IhL91rSWxIIJQNfVsqJ1d4yY5D2WyWcefo4Xv2aX_lo,180
|
|
2
2
|
platzky/admin/admin.py,sha256=nQq0IcBhrcX6S4gd71MejOcc2yizVv20UmF4ZRvZnBk,1019
|
|
3
|
-
platzky/admin/fake_login.py,sha256=
|
|
3
|
+
platzky/admin/fake_login.py,sha256=tGsdofPyI3P65pol_3Nbj5075xjA_CU090brnBVNjxg,3480
|
|
4
4
|
platzky/admin/templates/admin.html,sha256=4WdatUbuWakR3Yhrr7ClzKlUMXVcYdl_2kMBzW_faM0,813
|
|
5
5
|
platzky/admin/templates/login.html,sha256=oBNuv130iMTwXrtRnDUDcGIGvu0O2VsIbjQxw-Tjd7Y,380
|
|
6
6
|
platzky/admin/templates/module.html,sha256=WuQZxKQDD4INl-QF2uiKHf9Fmf2h7cEW9RLe1nWKC8k,175
|
|
@@ -21,7 +21,7 @@ platzky/engine.py,sha256=mweAkMG-DCei84rXfggukcsMyje4rj9rSk5v5AwnF04,1896
|
|
|
21
21
|
platzky/locale/en/LC_MESSAGES/messages.po,sha256=WaZGlFAegKRq7CSz69dWKic-mKvQFhVvssvExxNmGaU,1400
|
|
22
22
|
platzky/locale/pl/LC_MESSAGES/messages.po,sha256=sUPxMKDeEOoZ5UIg94rGxZD06YVWiAMWIby2XE51Hrc,1624
|
|
23
23
|
platzky/models.py,sha256=-IIlyeLzACeTUpzuzvzJYxtT57E6wRiERoRgXJYMMtY,1502
|
|
24
|
-
platzky/platzky.py,sha256=
|
|
24
|
+
platzky/platzky.py,sha256=o4gvQc6i_fJhMembJ2FXEbfHOgmFyGqub5hgQ6roxDc,3881
|
|
25
25
|
platzky/plugin/plugin.py,sha256=tV8aobIzMDJe1frKUAi4kLbrTAIS0FWE3oYpktSo6Ug,1633
|
|
26
26
|
platzky/plugin/plugin_loader.py,sha256=MeQ8LNbrOomwXgc1ISHuyhjZd2mzYKen70eDShWs-Co,3497
|
|
27
27
|
platzky/seo/seo.py,sha256=N_MmAA4KJZmmrDUh0hYNtD8ycOwpNKow4gVSAv8V3N4,2631
|
|
@@ -39,6 +39,6 @@ platzky/templates/post.html,sha256=GSgjIZsOQKtNx3cEbquSjZ5L4whPnG6MzRyoq9k4B8Q,1
|
|
|
39
39
|
platzky/templates/robots.txt,sha256=2_j2tiYtYJnzZUrANiX9pvBxyw5Dp27fR_co18BPEJ0,116
|
|
40
40
|
platzky/templates/sitemap.xml,sha256=iIJZ91_B5ZuNLCHsRtsGKZlBAXojOTP8kffqKLacgvs,578
|
|
41
41
|
platzky/www_handler.py,sha256=pF6Rmvem1sdVqHD7z3RLrDuG-CwAqfGCti50_NPsB2w,725
|
|
42
|
-
platzky-0.3.
|
|
43
|
-
platzky-0.3.
|
|
44
|
-
platzky-0.3.
|
|
42
|
+
platzky-0.3.5.dist-info/METADATA,sha256=oZaDnSFu_8RO8Cni_bey2UobtQu53XYDq-83Xbw1MS4,1727
|
|
43
|
+
platzky-0.3.5.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
|
44
|
+
platzky-0.3.5.dist-info/RECORD,,
|
|
File without changes
|