Commits

Graham Higgins  committed 4fb8d4d Merge

merge

  • Participants
  • Parent commits 2f375d9, e55a6df

Comments (0)

Files changed (2)

File shabti/templates/auth_repozewhat/+package+/lib/auth/__init__.py_tmpl

-from repoze.what.plugins.quickstart import setup_sql_auth
-from repoze.who.plugins.friendlyform import FriendlyFormPlugin
-from {{package}}.model import User, Group, Permission, Session
-
-# Bind values to the variables that will be provided to 
-# :func:`setup_sql_auth`. This is a good example of the 
-# difference between the ``.ini`` config file approach
-# and this one, i.e. of effecting the configuration within
-# the friendly confines of an executable Python source file.
-# Otherwise, the model entity classes would have to be 
-# expressed as strings, to be later turned into real
-# references to the object's class.
-
-user_name = 'username'
-user_class = User
-group_class = Group
-permission_class = Permission
-dbsession = Session
-translations={'user_name': 'username',
-            'users': 'users',
-            'group_name': 'name',
-            'groups': 'groups',
-            'permission_name': 'name',
-            'permissions': 'permissions',
-            'validate_password': 'validate_password' }
-
-# Bind values to the variables that will be provided to 
-# :class:`FriendlyRedirectingFormPlugin` and create an
-# instance of same.
-# ATM, an actual (configured) instance is required, ya 
-# can't just supply the class name.
-
-loginform = FriendlyFormPlugin(
-    '/login/index',                           # arg - login_form_url
-    login_handler_path = '/login_handler',    # arg - login_handler_path
-    logout_handler_path = '/logout_handler',  # arg - logout_handler_path
-    rememberer_name = 'cookie',               # arg - rememberer_name
-    post_login_url = '/login/welcome_back',   # The URL/path to the post-login 
-                                              # page, if any.
-    post_logout_url = '/login/see_you_later', # The URL/path to the post-logout 
-                                              # page, if any.
-    )
-
-def add_auth(app, skip_authentication):
-    """Add authentication and authorization middleware to the ``app``."""
-    return setup_sql_auth(app,
-            user_class, 
-            group_class, 
-            permission_class, 
-            dbsession, 
-            form_plugin=loginform, 
-            form_identifies=True, 
-            cookie_secret='secretsquirrel', 
-            cookie_name='authtkt', 
-            login_url='/login/index', 
-            #login_handler='/login/signin', 
-            post_login_url='/login/welcome_back', 
-            #logout_handler='/login/signout', 
-            post_logout_url='/login/see_you_later', 
-            login_counter_name='__tries', 
-            translations=translations,
-            skip_authentication=skip_authentication)
-
-def get_user():
-    from pylons import request
-    """Return the current user's database object."""
-    if 'repoze.who.identity' in request.environ:
-        return request.environ.get('repoze.who.identity')['user']
-    else:
-        return None
-    

File shabti/templates/auth_repozewho/+package+/lib/auth/__init__.py_tmpl

 import logging
 log = logging.getLogger(__name__)
 
-# Bind values to the variables that will be provided to 
-# :func:`setup_sql_auth`. This is a good example of the 
+# Bind values to the variables that will be provided to
+# :func:`setup_sql_auth`. This is a good example of the
 # difference between the ``.ini`` config file approach
 # and this one, i.e. of effecting the configuration within
 # the friendly confines of an executable Python source file.
-# Otherwise, the model entity classes would have to be 
+# Otherwise, the model entity classes would have to be
 # expressed as strings, to be later turned into real
 # references to the object's class.
 # The "translations" dictionary maps the repoze identity
 # model User Group, Permission and password validation
-# function to the field names and function that are actually 
+# function to the field names and function that are actually
 # used in the standard Shabti elixir identity model.
 
 user_name = 'username'
 permission_class = Permission
 dbsession = Session
 translations={'user_name': 'username',
-              'users': 'users',
-              'group_name': 'name',
-              'groups': 'groups',
-              'permission_name': 'name',
-              'permissions': 'permissions',
-              'validate_password': 'validate_password' }
+            'users': 'users',
+            'group_name': 'name',
+            'groups': 'groups',
+            'permission_name': 'name',
+            'permissions': 'permissions',
+            'validate_password': 'validate_password' }
+
+loginform = FriendlyFormPlugin(
+    '/login/index',                           # arg - login_form_url
+    login_handler_path = '/login_handler',    # arg - login_handler_path
+    logout_handler_path = '/logout_handler',  # arg - logout_handler_path
+    rememberer_name = 'cookie',               # arg - rememberer_name
+    post_login_url = '/login/welcome_back',   # The URL/path to the post-login
+                                              # page, if any.
+    post_logout_url = '/login/see_you_later', # The URL/path to the post-logout
+                                              # page, if any.
+    )
+
+# Bind values to the variables that will be provided to
+# :class:`FriendlyRedirectingFormPlugin` and create an
+# instance of same.
+# ATM, an actual (configured) instance is required, ya
+# can't just supply the class name.
 
 
 def add_auth(app, skip_authentication):
             group_class,
             permission_class,
             dbsession,
-            # form_plugin=loginform, --not required
+            form_plugin=loginform,
             form_identifies=True,
             cookie_secret='secretsquirrel',
             cookie_name='authtkt',
             login_url='/login/index',
             post_login_url='/login/welcome_back',
             post_logout_url='/login/see_you_later',
-            login_counter_name='__logins',
+            login_counter_name='__tries',
             translations=translations,
             skip_authentication=skip_authentication)
 
         return request.environ.get('repoze.who.identity')['user']
     else:
         return None
-    
+