Mercurial > hg > index.fcgi > www > www-1
diff pics3/pics_flask_app.py @ 130:06f97e38e1b2
pics3: add pin support
author | paulo |
---|---|
date | Thu, 20 Jan 2022 00:40:14 -0800 |
parents | d216dd8e63da |
children | 41a6e2d99f68 |
line diff
1.1 --- a/pics3/pics_flask_app.py Tue Jan 11 02:36:16 2022 -0800 1.2 +++ b/pics3/pics_flask_app.py Thu Jan 20 00:40:14 2022 -0800 1.3 @@ -11,6 +11,16 @@ 1.4 1.5 GCS_CLIENT = google.cloud.storage.Client() 1.6 GCS_BUCKET = GCS_CLIENT.get_bucket(os.environ.get("GCS_BUCKET")) 1.7 +PIN = os.environ.get("PIN") 1.8 + 1.9 + 1.10 +class PinFailError(Exception): 1.11 + def __str__(self): 1.12 + return "PIN FAIL!" 1.13 + 1.14 +class PinSetupError(Exception): 1.15 + def __str__(self): 1.16 + return "PIN SETUP ERROR!" 1.17 1.18 1.19 class PicsDialect(csv.Dialect): 1.20 @@ -105,6 +115,11 @@ 1.21 (root, header, body) = _get_standard_html_doc("Pictures") 1.22 header.script('', type="text/javascript", src=flask.url_for("static", filename="lazyload.js")) 1.23 1.24 + if not PIN: 1.25 + raise PinSetupError 1.26 + elif flask.request.cookies.get("lahat") != PIN: 1.27 + raise PinFailError 1.28 + 1.29 pics_dirs = [] 1.30 pics_dirs_index_blob = GCS_BUCKET.get_blob("pics/index.tsv") 1.31 if pics_dirs_index_blob: