From 60b6f5b35c3602f4bea942ceaaaee7528b74356c Mon Sep 17 00:00:00 2001 Message-Id: <60b6f5b35c3602f4bea942ceaaaee7528b74356c.1715150657.git.mdw@distorted.org.uk> From: Mark Wooding Date: Sat, 30 Mar 2013 14:46:31 +0000 Subject: [PATCH] httpauth.py: Abstract out setting the various cookie attributes. Organization: Straylight/Edgeware From: Mark Wooding We'll want to use them elsewhere. --- httpauth.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) 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 -------------------------------------------------- -- [mdw]