chiark / gitweb /
httpauth.py: Abstract out setting the various cookie attributes.
authorMark Wooding <mdw@distorted.org.uk>
Sat, 30 Mar 2013 14:46:31 +0000 (14:46 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Sat, 30 Mar 2013 14:57:04 +0000 (14:57 +0000)
We'll want to use them elsewhere.

httpauth.py

index e29686c..4a41e4f 100644 (file)
@@ -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 --------------------------------------------------