diff options
author | Piotr Dobrowolski <admin@tastycode.pl> | 2017-04-21 17:28:01 +0200 |
---|---|---|
committer | Piotr Dobrowolski <admin@tastycode.pl> | 2017-04-21 17:28:01 +0200 |
commit | 1c16ee9d74540c327edd1315cb075f6a1b6b80e4 (patch) | |
tree | 5d29c2273fd626f438166f6ff25ccfd941db233e | |
parent | 5e12ab2b39dfa78a7b4c58ebd6565e0151edffe2 (diff) | |
download | bitvend-1c16ee9d74540c327edd1315cb075f6a1b6b80e4.tar.gz bitvend-1c16ee9d74540c327edd1315cb075f6a1b6b80e4.tar.bz2 bitvend-1c16ee9d74540c327edd1315cb075f6a1b6b80e4.tar.xz bitvend-1c16ee9d74540c327edd1315cb075f6a1b6b80e4.zip |
auth: Full capability caching
-rw-r--r-- | bitvend/auth.py | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/bitvend/auth.py b/bitvend/auth.py index f0d8d0a..f7486fe 100644 --- a/bitvend/auth.py +++ b/bitvend/auth.py @@ -40,20 +40,20 @@ def cap_check(capability, user=None): return False user = user or current_user.get_id() + cached_cap = session.get('_caps', {}).get(capability, (False, 0)) - if session.get('_caps', {}).get(capability, 0) > time.time(): - return True + if cached_cap[1] > time.time(): + return cached_cap[0] allowed = requests.get( 'https://capacifier.hackerspace.pl/%s/%s' % (capability, user) ).status_code == 200 - if allowed: - if '_caps' not in session: - session['_caps'] = {} + if '_caps' not in session: + session['_caps'] = {} - session['_caps'][capability] = \ - time.time() + current_app.config.get('CAP_TTL', 3600) + session['_caps'][capability] = \ + (allowed, time.time() + current_app.config.get('CAP_TTL', 3600)) return allowed |