[Mpuls-commits] r4030 - base/trunk/mpulsweb/lib

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Oct 26 18:26:30 CEST 2010


Author: torsten
Date: 2010-10-26 18:26:30 +0200 (Tue, 26 Oct 2010)
New Revision: 4030

Modified:
   base/trunk/mpulsweb/lib/security.py
Log:
* mpulsweb/lib/security.py: Added new function which tries to fetch the name of the db to login from submitted form parameter.


Modified: base/trunk/mpulsweb/lib/security.py
===================================================================
--- base/trunk/mpulsweb/lib/security.py	2010-10-26 16:23:54 UTC (rev 4029)
+++ base/trunk/mpulsweb/lib/security.py	2010-10-26 16:26:30 UTC (rev 4030)
@@ -44,7 +44,7 @@
 
 from webob.exc import HTTPUnauthorized
 
-from pylons import request, config, g
+from pylons import request, config, g, h
 
 from mpulsweb.lib.db import DB, db, enter, leave
 
@@ -258,7 +258,24 @@
     """
     return config.get('mpuls.db.name')
 
+def get_dbname_from_formparam():
+    """Return the name of the database name from the submitted
+    "DB_NAME_FROM_LIST" param on the login page. Further submitted dbname must
+    be defined in the dblist json file.
+    """
+    dbname = request.params.get('DB_NAME_FROM_LIST') or session.get('DB_NAME_FROM_LIST')
+    if dbname:
+        # Check if the name is part of the db list
+        dblist = h.get_db_selectionlist()
+        if dbname in dblist.keys():
+            session['DB_NAME_FROM_LIST'] = dbname
+            session.save()
+            return dbname 
+        return None
+    else:
+        return None
 
+
 def getDbName():
     """Return the KA-specific part of the database name.
     The value is taken from HTTP-Headers containing information from the
@@ -266,7 +283,11 @@
     those headers are not set, the value is taken from the configuration
     using get_dbname_from_config().
     """
-    dbname = get_dbname_from_http_header()
+    dbname = get_dbname_from_formparam()
+    if not dbname:
+        log.info("Could not determine database name from Request params,"
+                 " falling back to HTTP header ")
+        dbname = get_dbname_from_http_header()
 
     if not dbname:
         log.info("Could not determine database name from HTTP header,"



More information about the Mpuls-commits mailing list