[Mpuls-commits] r3880 - in base/trunk: . mpulsweb/controllers mpulsweb/lib

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Mon Oct 4 15:36:46 CEST 2010


Author: bh
Date: 2010-10-04 15:36:44 +0200 (Mon, 04 Oct 2010)
New Revision: 3880

Modified:
   base/trunk/ChangeLog
   base/trunk/mpulsweb/controllers/auth.py
   base/trunk/mpulsweb/lib/base.py
Log:
Make the name of the authorization cookie configurable.  This
makes it possible to run several mpuls applications on the same
host on different ports and to log in to all of them at the same
time using the same browser.  This is very useful for development.

* mpulsweb/controllers/auth.py (AuthController.loginAction)
(AuthController.logout): Use auth_cookie_name to determine the
cookie name instead of using a hard-wired name.

* mpulsweb/lib/base.py (auth_cookie_name): New.  Return the name
of the authorization cookie.
(BaseController.__before__): Use auth_cookie_name to determine the
cookie name instead of using a hard-wired name.


Modified: base/trunk/ChangeLog
===================================================================
--- base/trunk/ChangeLog	2010-10-04 13:31:33 UTC (rev 3879)
+++ base/trunk/ChangeLog	2010-10-04 13:36:44 UTC (rev 3880)
@@ -1,3 +1,19 @@
+2010-10-04  Bernhard Herzog  <bh at intevation.de>
+
+	Make the name of the authorization cookie configurable.  This
+	makes it possible to run several mpuls applications on the same
+	host on different ports and to log in to all of them at the same
+	time using the same browser.  This is very useful for development.
+
+	* mpulsweb/controllers/auth.py (AuthController.loginAction)
+	(AuthController.logout): Use auth_cookie_name to determine the
+	cookie name instead of using a hard-wired name.
+
+	* mpulsweb/lib/base.py (auth_cookie_name): New.  Return the name
+	of the authorization cookie.
+	(BaseController.__before__): Use auth_cookie_name to determine the
+	cookie name instead of using a hard-wired name.
+
 2010-10-04  Torsten Irländer <torsten.irlaender at intevation.de>
 
 	* mpulsweb/lib/renderer.py: Issue893: Added numebering of entries in

Modified: base/trunk/mpulsweb/controllers/auth.py
===================================================================
--- base/trunk/mpulsweb/controllers/auth.py	2010-10-04 13:31:33 UTC (rev 3879)
+++ base/trunk/mpulsweb/controllers/auth.py	2010-10-04 13:36:44 UTC (rev 3880)
@@ -4,7 +4,7 @@
 from pylons import request, response, tmpl_context as c
 from pylons.controllers.util import redirect_to
 
-from mpulsweb.lib.base import BaseController, render, session
+from mpulsweb.lib.base import BaseController, render, session, auth_cookie_name
 from mpulsweb.lib.security import checkLogin, generateID, userIdentity
 
 log = logging.getLogger(__name__)
@@ -19,7 +19,7 @@
         session.delete()
         session.save()
         session.invalidate()
-        response.delete_cookie('mpuls_auth')
+        response.delete_cookie(auth_cookie_name())
         return render('/auth/logout.mako')
 
     def login(self):
@@ -40,7 +40,7 @@
                 # Does only work work with enabled ssl. secure means that the
                 # cookie will only be sent over a secure connection.
                 #response.set_cookie('mpuls_auth', shared, secure=True)
-                response.set_cookie('mpuls_auth', shared)
+                response.set_cookie(auth_cookie_name(), shared)
 
                 redirect_to("/")
             else:

Modified: base/trunk/mpulsweb/lib/base.py
===================================================================
--- base/trunk/mpulsweb/lib/base.py	2010-10-04 13:31:33 UTC (rev 3879)
+++ base/trunk/mpulsweb/lib/base.py	2010-10-04 13:36:44 UTC (rev 3880)
@@ -70,6 +70,14 @@
 log = logging.getLogger(__name__)
 
 
+def auth_cookie_name():
+    """Return the name of authorization cookie.
+    The name is taken from the config setting mpuls.app.auth_cookie_name
+    and defaults to 'mpuls_auth'.
+    """
+    return config.get("mpuls.app.auth_cookie_name", "mpuls_auth")
+
+
 # Added own render_mako function which addes custom translation functions
 def render_mako(template_name, extra_vars=None, cache_key=None, 
                 cache_type=None, cache_expire=None):
@@ -135,9 +143,10 @@
         try:
             storedHash = session['AUTH']
             try:
-                shared = request.cookies['mpuls_auth']
+                shared = request.cookies[auth_cookie_name()]
             except KeyError:
-                log.error("Cannot find mpuls_auth cookie -> HTTPUnauthorized")
+                log.error("Cannot find %s cookie -> HTTPUnauthorized",
+                          auth_cookie_name())
                 raise HTTPUnauthorized(detail=COOKIE_NOT_FOUND)
 
             if storedHash != md5.new(shared + userIdentity()).digest():



More information about the Mpuls-commits mailing list