/shabti/templates/auth_repozewho/+package+/lib/auth/__init__.py_tmpl
https://bitbucket.org/gawel/shabti · Unknown · 77 lines · 68 code · 9 blank · 0 comment · 0 complexity · 22a8afc579d31771b8fb9592fcf823d0 MD5 · raw file
- from repoze.what.plugins.quickstart import setup_sql_auth
- from repoze.who.plugins.friendlyform import FriendlyFormPlugin
- from {{package}}.model import User, Group, Permission, Session
- from pylons import request
- 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
- # 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.
- # The "translations" dictionary maps the repoze identity
- # model User Group, Permission and password validation
- # function to the field names and function that are actually
- # used in the standard Shabti elixir identity model.
- 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' }
- 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):
- """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',
- post_login_url='/login/welcome_back',
- post_logout_url='/login/see_you_later',
- login_counter_name='__tries',
- translations=translations,
- skip_authentication=skip_authentication)
- def get_user():
- """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