feat: option to turn the app private (fix #2)

This commit is contained in:
Mylloon 2023-12-22 14:45:56 +01:00
parent ac1854bf3a
commit d3bcb3f63e
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
4 changed files with 18 additions and 7 deletions

View file

@ -6,10 +6,11 @@ personal diary with txt style, can be private!
## environment variables
| name | description | required |
| :-----------: | :-----------: | :------: |
| `TD_USERNAME` | user name | no |
| `TD_USERPASS` | user password | yes |
| name | description | required |
| :-----------: | :-----------: | :-------------: |
| `TD_USERNAME` | user name | no |
| `TD_USERPASS` | user password | yes |
| `TD_PRIVATE` | user password | empty = `false` |
## volumes (docker)

View file

@ -10,11 +10,15 @@ router = Blueprint(name, __name__)
@router.route("/")
def index() -> str:
"""index page"""
posts = []
if not Config.private or (Config.private and Config.is_logged()):
posts = [p.split("/")[-1][:-4] for p in get_posts()]
return render_template(
"index.html",
config=Config,
page_name=name,
posts=[p.split("/")[-1][:-4] for p in get_posts()],
posts=posts,
)

View file

@ -10,8 +10,10 @@ router = Blueprint(name, __name__)
@router.route(f"/{name}/<int:file>")
def read(file: int) -> str:
"""read page"""
filename = post_filename(file)
content = get_post(filename)
content = None
if not Config.private or (Config.private and Config.is_logged()):
filename = post_filename(file)
content = get_post(filename)
return render_template(
"read.html",

View file

@ -4,6 +4,7 @@ from flask import session
VAR_USERNAME = "TD_USERNAME"
VAR_USERPASS = "TD_USERPASS"
VAR_PRIVATE = "TD_PRIVATE"
class User:
@ -34,6 +35,9 @@ class Config:
# data location
data_dir = "data"
# turn posts private
private = True if VAR_PRIVATE in envar else False
@staticmethod
def is_logged() -> bool:
"""where the info about connection is stored"""