feat: option to turn the app private (fix #2)
This commit is contained in:
parent
ac1854bf3a
commit
d3bcb3f63e
4 changed files with 18 additions and 7 deletions
|
@ -6,10 +6,11 @@ personal diary with txt style, can be private!
|
||||||
|
|
||||||
## environment variables
|
## environment variables
|
||||||
|
|
||||||
| name | description | required |
|
| name | description | required |
|
||||||
| :-----------: | :-----------: | :------: |
|
| :-----------: | :-----------: | :-------------: |
|
||||||
| `TD_USERNAME` | user name | no |
|
| `TD_USERNAME` | user name | no |
|
||||||
| `TD_USERPASS` | user password | yes |
|
| `TD_USERPASS` | user password | yes |
|
||||||
|
| `TD_PRIVATE` | user password | empty = `false` |
|
||||||
|
|
||||||
## volumes (docker)
|
## volumes (docker)
|
||||||
|
|
||||||
|
|
|
@ -10,11 +10,15 @@ router = Blueprint(name, __name__)
|
||||||
@router.route("/")
|
@router.route("/")
|
||||||
def index() -> str:
|
def index() -> str:
|
||||||
"""index page"""
|
"""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(
|
return render_template(
|
||||||
"index.html",
|
"index.html",
|
||||||
config=Config,
|
config=Config,
|
||||||
page_name=name,
|
page_name=name,
|
||||||
posts=[p.split("/")[-1][:-4] for p in get_posts()],
|
posts=posts,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -10,8 +10,10 @@ router = Blueprint(name, __name__)
|
||||||
@router.route(f"/{name}/<int:file>")
|
@router.route(f"/{name}/<int:file>")
|
||||||
def read(file: int) -> str:
|
def read(file: int) -> str:
|
||||||
"""read page"""
|
"""read page"""
|
||||||
filename = post_filename(file)
|
content = None
|
||||||
content = get_post(filename)
|
if not Config.private or (Config.private and Config.is_logged()):
|
||||||
|
filename = post_filename(file)
|
||||||
|
content = get_post(filename)
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
"read.html",
|
"read.html",
|
||||||
|
|
|
@ -4,6 +4,7 @@ from flask import session
|
||||||
|
|
||||||
VAR_USERNAME = "TD_USERNAME"
|
VAR_USERNAME = "TD_USERNAME"
|
||||||
VAR_USERPASS = "TD_USERPASS"
|
VAR_USERPASS = "TD_USERPASS"
|
||||||
|
VAR_PRIVATE = "TD_PRIVATE"
|
||||||
|
|
||||||
|
|
||||||
class User:
|
class User:
|
||||||
|
@ -34,6 +35,9 @@ class Config:
|
||||||
# data location
|
# data location
|
||||||
data_dir = "data"
|
data_dir = "data"
|
||||||
|
|
||||||
|
# turn posts private
|
||||||
|
private = True if VAR_PRIVATE in envar else False
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def is_logged() -> bool:
|
def is_logged() -> bool:
|
||||||
"""where the info about connection is stored"""
|
"""where the info about connection is stored"""
|
||||||
|
|
Loading…
Reference in a new issue