[Checkins] SVN: megrok.login/trunk/src/megrok/login/loginform.py Add login form page replacement code.

Uli Fouquet uli at gnufix.de
Wed Feb 9 06:48:51 EST 2011


Log message for revision 120231:
  Add login form page replacement code.
  

Changed:
  A   megrok.login/trunk/src/megrok/login/loginform.py

-=-
Added: megrok.login/trunk/src/megrok/login/loginform.py
===================================================================
--- megrok.login/trunk/src/megrok/login/loginform.py	                        (rev 0)
+++ megrok.login/trunk/src/megrok/login/loginform.py	2011-02-09 11:48:51 UTC (rev 120231)
@@ -0,0 +1,40 @@
+##############################################################################
+#
+# Copyright (c) 2008 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""A login form page.
+"""
+from zope.authentication.interfaces import IUnauthenticatedPrincipal
+
+class LoginForm(object):
+    """Mix-in class to implement login form logic"""
+    
+    def __call__(self):
+        request = self.request
+        principal = request.principal
+
+        unauthenticated = IUnauthenticatedPrincipal.providedBy(principal)
+        self.unauthenticated = unauthenticated
+        
+        camefrom = request.get('camefrom')
+        if isinstance(camefrom, list):
+            # this can happen on python2.6, as it changed the
+            # behaviour of cgi.FieldStorage a bit.
+            camefrom = camefrom[0]
+        self.camefrom = camefrom
+        
+        if (not unauthenticated) and ('SUBMIT' in request):
+            # authenticated by submitting
+            request.response.redirect(camefrom or '.')
+            return ''
+        
+        return self.index() # call template



More information about the checkins mailing list