From: Mark Wooding Date: Sat, 30 Mar 2013 14:46:31 +0000 (+0000) Subject: httpauth.py: Abstract out setting the various cookie attributes. X-Git-Tag: 1.0.1~1 X-Git-Url: https://git.distorted.org.uk/~mdw/chopwood/commitdiff_plain/60b6f5b35c3602f4bea942ceaaaee7528b74356c httpauth.py: Abstract out setting the various cookie attributes. We'll want to use them elsewhere. --- diff --git a/httpauth.py b/httpauth.py index e29686c..4a41e4f 100644 --- a/httpauth.py +++ b/httpauth.py @@ -227,6 +227,16 @@ def check_auth(token, nonce = None): ## Done. return user +def bake_cookie(value): + """ + Return a properly baked authentication-token cookie with the given VALUE. + """ + return CGI.cookie('chpwd-token', value, + httponly = True, + secure = CGI.SSLP, + path = CFG.SCRIPT_NAME, + max_age = (CFG.SECRETLIFE - CFG.SECRETFRESH)) + ###-------------------------------------------------------------------------- ### Authentication commands. @@ -258,11 +268,6 @@ def cmd_auth(u, pw): else: t = mint_token(u) CGI.redirect(CGI.action('list', u), - set_cookie = CGI.cookie('chpwd-token', t, - httponly = True, - secure = CGI.SSLP, - path = CFG.SCRIPT_NAME, - max_age = (CFG.SECRETLIFE - - CFG.SECRETFRESH))) + set_cookie = bake_cookie(t)) ###----- That's all, folks --------------------------------------------------