Module author: Gustavo Narea <me@gustavonarea.net>
Author: | Gustavo Narea. |
---|---|
Latest version: | 1.0rc2 |
Overview
The repoze.who SQLAlchemy plugin provides an authenticator and a metadata provider plugins for SQLAlchemy or Elixir-based models.
The minimum requirements repoze.who and SQLAlchemy and you can install it all by running:
easy_install repoze.who.plugins.sa
The development mainline is available at the following Subversion repository:
http://svn.repoze.org/whoplugins/whoalchemy/trunk/
repoze.who authenticator for SQLAlchemy models.
Example:
from repoze.who.plugins.sa import SQLAlchemyAuthenticatorPlugin
from yourcoolproject.model import User, DBSession
authenticator = SQLAlchemyAuthenticatorPlugin(User, DBSession)
This plugin assumes that the user name is kept in the user_name attribute of the users’ class, as well as that such a class has a method that verifies the user’s password against the password provided through the login form (it receives the password to be verified as the only argument and such method is assumed to be called validate_password).
If you don’t want to call the attributes above as user_name and/or validate_password, respectively, then you have to “translate” them as in the sample below:
# You have User.username instead of User.user_name:
authenticator.translations['user_name'] = 'username'
# You have User.verify_password instead of User.validate_password:
authenticator.translations['validate_password'] = 'verify_password'
Note
If you want to configure this authenticator from an ini file, use make_sa_authenticator().
Configure SQLAlchemyAuthenticatorPlugin.
Parameters: | |
---|---|
Returns: | The authenticator. |
Return type: | SQLAlchemyAuthenticatorPlugin |
Example from an *.ini file:
# ...
[plugin:sa_auth]
use = repoze.who.plugins.sa:make_sa_authenticator
user_class = yourcoolproject.model:User
dbsession = yourcoolproject.model:DBSession
# ...
Or, if you need translations:
# ...
[plugin:sa_auth]
use = repoze.who.plugins.sa:make_sa_authenticator
user_class = yourcoolproject.model:User
dbsession = yourcoolproject.model:DBSession
user_name_translation = username
validate_password_translation = verify_password
# ...
repoze.who metadata provider that loads the SQLAlchemy-powered object for the current user.
It loads the object into identity['user'].
Example:
from repoze.who.plugins.sa import SQLAlchemyUserMDPlugin
from yourcoolproject.model import User, DBSession
mdprovider = SQLAlchemyUserMDPlugin(User, DBSession)
This plugin assumes that the user name is kept in the user_name attribute of the users’ class. If you don’t want to call the attribute above as user_name, then you have to “translate” it as in the sample below:
# You have User.username instead of User.user_name:
mdprovider.translations['user_name'] = 'username'
Note
If you want to configure this plugin from an ini file, use make_sa_user_mdprovider().
Configure SQLAlchemyUserMDPlugin.
Parameters: | |
---|---|
Returns: | The metadata provider. |
Return type: | SQLAlchemyUserMDPlugin |
Example from an *.ini file:
# ...
[plugin:sa_md]
use = repoze.who.plugins.sa:make_sa_user_mdprovider
user_class = yourcoolproject.model:User
dbsession = yourcoolproject.model:DBSession
# ...
Or, if you need translations:
# ...
[plugin:sa_md]
use = repoze.who.plugins.sa:make_sa_user_mdprovider
user_class = yourcoolproject.model:User
dbsession = yourcoolproject.model:DBSession
user_name_translation = username
# ...
User existence checker for repoze.who.plugins.auth_tkt.AuthTktCookiePlugin.
Example:
from repoze.who.plugins.sa import SQLAlchemyUserChecker
from yourcoolproject.model import User, DBSession
checker = SQLAlchemyUserChecker(User, DBSession)
This plugin assumes that the user name is kept in the user_name attribute of the users’ class. If you don’t want to call it that way, then you have to “translate” it as in the sample below:
# You have User.username instead of User.user_name:
checker.translations['user_name'] = 'username'
The prefered place to ask questions is the Repoze mailing list or the #repoze IRC channel. Bugs reports and feature requests should be sent to the issue tracker of the Repoze project.