platzky 0.3.3__tar.gz → 0.3.4__tar.gz

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.
Files changed (44) hide show
  1. {platzky-0.3.3 → platzky-0.3.4}/PKG-INFO +1 -1
  2. {platzky-0.3.3 → platzky-0.3.4}/platzky/admin/fake_login.py +36 -14
  3. {platzky-0.3.3 → platzky-0.3.4}/platzky/platzky.py +2 -0
  4. {platzky-0.3.3 → platzky-0.3.4}/pyproject.toml +1 -1
  5. {platzky-0.3.3 → platzky-0.3.4}/README.md +0 -0
  6. {platzky-0.3.3 → platzky-0.3.4}/platzky/__init__.py +0 -0
  7. {platzky-0.3.3 → platzky-0.3.4}/platzky/admin/admin.py +0 -0
  8. {platzky-0.3.3 → platzky-0.3.4}/platzky/admin/templates/admin.html +0 -0
  9. {platzky-0.3.3 → platzky-0.3.4}/platzky/admin/templates/login.html +0 -0
  10. {platzky-0.3.3 → platzky-0.3.4}/platzky/admin/templates/module.html +0 -0
  11. {platzky-0.3.3 → platzky-0.3.4}/platzky/blog/__init__.py +0 -0
  12. {platzky-0.3.3 → platzky-0.3.4}/platzky/blog/blog.py +0 -0
  13. {platzky-0.3.3 → platzky-0.3.4}/platzky/blog/comment_form.py +0 -0
  14. {platzky-0.3.3 → platzky-0.3.4}/platzky/config.py +0 -0
  15. {platzky-0.3.3 → platzky-0.3.4}/platzky/db/README.md +0 -0
  16. {platzky-0.3.3 → platzky-0.3.4}/platzky/db/__init__.py +0 -0
  17. {platzky-0.3.3 → platzky-0.3.4}/platzky/db/db.py +0 -0
  18. {platzky-0.3.3 → platzky-0.3.4}/platzky/db/db_loader.py +0 -0
  19. {platzky-0.3.3 → platzky-0.3.4}/platzky/db/github_json_db.py +0 -0
  20. {platzky-0.3.3 → platzky-0.3.4}/platzky/db/google_json_db.py +0 -0
  21. {platzky-0.3.3 → platzky-0.3.4}/platzky/db/graph_ql_db.py +0 -0
  22. {platzky-0.3.3 → platzky-0.3.4}/platzky/db/json_db.py +0 -0
  23. {platzky-0.3.3 → platzky-0.3.4}/platzky/db/json_file_db.py +0 -0
  24. {platzky-0.3.3 → platzky-0.3.4}/platzky/engine.py +0 -0
  25. {platzky-0.3.3 → platzky-0.3.4}/platzky/locale/en/LC_MESSAGES/messages.po +0 -0
  26. {platzky-0.3.3 → platzky-0.3.4}/platzky/locale/pl/LC_MESSAGES/messages.po +0 -0
  27. {platzky-0.3.3 → platzky-0.3.4}/platzky/models.py +0 -0
  28. {platzky-0.3.3 → platzky-0.3.4}/platzky/plugin/plugin.py +0 -0
  29. {platzky-0.3.3 → platzky-0.3.4}/platzky/plugin/plugin_loader.py +0 -0
  30. {platzky-0.3.3 → platzky-0.3.4}/platzky/seo/seo.py +0 -0
  31. {platzky-0.3.3 → platzky-0.3.4}/platzky/static/blog.css +0 -0
  32. {platzky-0.3.3 → platzky-0.3.4}/platzky/static/styles.css +0 -0
  33. {platzky-0.3.3 → platzky-0.3.4}/platzky/templates/404.html +0 -0
  34. {platzky-0.3.3 → platzky-0.3.4}/platzky/templates/base.html +0 -0
  35. {platzky-0.3.3 → platzky-0.3.4}/platzky/templates/blog.html +0 -0
  36. {platzky-0.3.3 → platzky-0.3.4}/platzky/templates/body_meta.html +0 -0
  37. {platzky-0.3.3 → platzky-0.3.4}/platzky/templates/dynamic_css.html +0 -0
  38. {platzky-0.3.3 → platzky-0.3.4}/platzky/templates/feed.xml +0 -0
  39. {platzky-0.3.3 → platzky-0.3.4}/platzky/templates/head_meta.html +0 -0
  40. {platzky-0.3.3 → platzky-0.3.4}/platzky/templates/page.html +0 -0
  41. {platzky-0.3.3 → platzky-0.3.4}/platzky/templates/post.html +0 -0
  42. {platzky-0.3.3 → platzky-0.3.4}/platzky/templates/robots.txt +0 -0
  43. {platzky-0.3.3 → platzky-0.3.4}/platzky/templates/sitemap.xml +0 -0
  44. {platzky-0.3.3 → platzky-0.3.4}/platzky/www_handler.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: platzky
3
- Version: 0.3.3
3
+ Version: 0.3.4
4
4
  Summary: Not only blog engine
5
5
  License: MIT
6
6
  Requires-Python: >=3.10,<4.0
@@ -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
- # Rest of the code remains the same
27
- html = f"""
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
- <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
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
- <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
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
- if role not in VALID_ROLES:
74
- flash(f"Invalid role: {role}. Must be one of: {', '.join(VALID_ROLES)}", "error")
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
- if role == ROLE_ADMIN:
77
- session["user"] = {"username": ROLE_ADMIN, "role": ROLE_ADMIN}
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
@@ -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
  [tool.poetry]
2
2
  name = "platzky"
3
- version = "0.3.3"
3
+ version = "0.3.4"
4
4
  description = "Not only blog engine"
5
5
  authors = []
6
6
  license = "MIT"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes