Mercurial > hg > index.fcgi > www > www-1
changeset 130:06f97e38e1b2
pics3: add pin support
author | paulo |
---|---|
date | Thu, 20 Jan 2022 00:40:14 -0800 |
parents | bd8a61f9162f |
children | 221d6ea7c6c8 |
files | pics3/flask_run_dev.sh pics3/pics_flask_app.py |
diffstat | 2 files changed, 16 insertions(+), 0 deletions(-) [+] |
line diff
1.1 --- a/pics3/flask_run_dev.sh Tue Jan 11 02:36:16 2022 -0800 1.2 +++ b/pics3/flask_run_dev.sh Thu Jan 20 00:40:14 2022 -0800 1.3 @@ -1,5 +1,6 @@ 1.4 #!/bin/sh 1.5 1.6 +export PIN=testpin 1.7 export GOOGLE_APPLICATION_CREDENTIALS=dev.key.json 1.8 export GCS_BUCKET=dev.pauloang.com 1.9 export FLASK_APP=pics_flask_app.py
2.1 --- a/pics3/pics_flask_app.py Tue Jan 11 02:36:16 2022 -0800 2.2 +++ b/pics3/pics_flask_app.py Thu Jan 20 00:40:14 2022 -0800 2.3 @@ -11,6 +11,16 @@ 2.4 2.5 GCS_CLIENT = google.cloud.storage.Client() 2.6 GCS_BUCKET = GCS_CLIENT.get_bucket(os.environ.get("GCS_BUCKET")) 2.7 +PIN = os.environ.get("PIN") 2.8 + 2.9 + 2.10 +class PinFailError(Exception): 2.11 + def __str__(self): 2.12 + return "PIN FAIL!" 2.13 + 2.14 +class PinSetupError(Exception): 2.15 + def __str__(self): 2.16 + return "PIN SETUP ERROR!" 2.17 2.18 2.19 class PicsDialect(csv.Dialect): 2.20 @@ -105,6 +115,11 @@ 2.21 (root, header, body) = _get_standard_html_doc("Pictures") 2.22 header.script('', type="text/javascript", src=flask.url_for("static", filename="lazyload.js")) 2.23 2.24 + if not PIN: 2.25 + raise PinSetupError 2.26 + elif flask.request.cookies.get("lahat") != PIN: 2.27 + raise PinFailError 2.28 + 2.29 pics_dirs = [] 2.30 pics_dirs_index_blob = GCS_BUCKET.get_blob("pics/index.tsv") 2.31 if pics_dirs_index_blob: