Commits

Anonymous committed 5cb0d56

Small change to tidyfilter and csauthenticate

  • Participants
  • Parent commits 3ecb0ca
  • Branches cherrypy

Comments (0)

Files changed (2)

File lib/csauthenticate.py

 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 """
 
-import time, whrandom
+import time, random
 from cherrypy import cpg
 
 from aspect import Aspect, STOP, CONTINUE
     sessionIdCookieName = "CherrySessionId"
     timeout = 60 # in minutes
 
+    def notLoggedIn(self, message):
+        return STOP, self.loginScreen(message, cpg.request.browserUrl)
+
     def _before(self, methodName, method):
         # If the method is not exposed, don't do anything
         if not getattr(method, 'exposed', None):
 
         cpg.request.login = ''
         # If the method is one of these 4, do not try to find out who is logged in
-        if methodName in ["loginScreen", "logoutScreen", "doLogin", "doLogout"]:
+        if methodName in ["loginScreen", "logoutScreen", "doLogin", "doLogout", "notLoggedIn"]:
             return CONTINUE, None
 
         # Check if a user is logged in:
         #   - If they are, set request.login with the right value
         #   - If not, return the login screen
         if not cpg.request.simpleCookie.has_key(self.sessionIdCookieName):
-            return STOP, self.loginScreen(self.noCookieMessage, cpg.request.browserUrl)
+            # return STOP, self.loginScreen(self.noCookieMessage, cpg.request.browserUrl)
+            return self.notLoggedIn(self.noCookieMessage)
         sessionId = cpg.request.simpleCookie[self.sessionIdCookieName].value
         now=time.time()
 
         # Check that session exists and hasn't timed out
         timeout=0
         if not cpg.request.sessionMap.has_key(sessionId):
-            return STOP, self.loginScreen(self.noCookieMessage, cpg.request.browserUrl)
+            # return STOP, self.loginScreen(self.noCookieMessage, cpg.request.browserUrl)
+            return self.notLoggedIn(self.noCookieMessage)
         else:
             login, expire = cpg.request.sessionMap[sessionId]
             if expire < now: timeout=1
                 cpg.request.sessionMap[sessionId] = login, expire
 
         if timeout:
-            return STOP, self.loginScreen(self.timeoutMessage, cpg.request.browserUrl)
+            # return STOP, self.loginScreen(self.timeoutMessage, cpg.request.browserUrl)
+            return self.notLoggedIn(self.timeoutMessage)
 
         cpg.request.login = login
         return CONTINUE, None
         choice="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
         while 1:
             sessionId=""
-            for dummy in range(20): sessionId += whrandom.choice(choice)
+            for dummy in range(20): sessionId += random.choice(choice)
             if sessionId not in sessionIdList: return sessionId
 
     def doLogin(self, login, password, fromPage):
         cpg.response.simpleCookie[self.sessionIdCookieName]['version'] = 1
         cpg.request.login = ''
         cpg.response.headerMap['Status'] = 302
-        cpg.response.headerMap['Location'] = 'logoutScreen' # TBCTBC: may not be the right URL
+        cpg.response.headerMap['Location'] = 'logoutScreen'
         return ""
     doLogout.exposed = True
 
         <html><body>
             Message: %s
             <form method="post" action="doLogin">
-                Login: <input type=text name=login value="%s" size=10><br>
-                Password: <input type=password name=password size=10><br>
-                <input type=hidden name=fromPage value="%s"><br>
-                <input type=submit>
+                Login: <input type=text name=login value="%s" size=10/><br/>
+                Password: <input type=password name=password size=10/><br/>
+                <input type=hidden name=fromPage value="%s"/><br/>
+                <input type=submit/>
             </form>
         </body></html>
         """ % (message, login, fromPage)

File lib/filter/tidyfilter.py

 import os, cgi
 from basefilter import BaseOutputFilter
 from cherrypy import cpg
+import HTMLParser
 
 class TidyFilter(BaseOutputFilter):
     """
         # so we just collect the body and work with it.
         originalBody = ''.join(cpg.response.body)
         cpg.response.body = [originalBody]
+        p = HTMLParser.HTMLParser()
+        p.feed(originalBody)
         
         fct = cpg.response.headerMap.get('Content-Type', '')
         ct = fct.split(';')[0]