Hello,

Another option is to create an authenticator like this:
====
from repoze.who.plugins.sa import SQLAlchemyAuthenticatorPlugin
from sqlalchemy.orm.exc import NoResultFound, MultipleResultsFound

class UsernameOrEmailAuthenticator(SQLAlchemyAuthenticatorPlugin):

    def authenticate(self, environ, identity):
        # If an email address was provided instead of a user name,
        # replace it with the respective user name:
        if "@" in identity['login']:
            try:
                username = get_username_for_email(identity['login'])
            except (NoResultFound, MultipleResultsFound):
                return None
            else:
                identity['login'] = username

        return super(UsernameOrEmailAuthenticator, self).\
               authenticate(environ, identity)
====

For ideas on how to define get_username_for_email(), you may check 
_BaseSQLAlchemyPlugin:
http://svn.repoze.org/whoplugins/whoalchemy/trunk/repoze/who/plugins/sa.py

And pass it to the quickstart:
====
def add_auth(app, skip_authentication):
    sa_authn = UsernameOrEmailAuthenticator(User, Session)
    authenticators = [("username_or_email", sa_authn)]

    return setup_sql_auth(app, User, Group, Permission, Session,
        skip_authentication = skip_authentication,
        log_level = 'info',
        login_url = '/login',
        login_handler = '/authenticate',
        post_login_url = '/dashboard',
        logout_handler = '/logout',
        post_logout_url = '/login',
        cookie_secret = 'de9f2c7fd25e1b3afad3e85a0bd17d9b100db4b3',
        translations = {
            'user_name': 'username',
            'group_name': 'name',
            'permission_name': 'name'
        },
        use_default_authenticator=False,
        authenticators=authenticators,
====

HTH.
-- 
Gustavo Narea <xri://=Gustavo>.
| Tech blog: =Gustavo/(+blog)/tech  ~  About me: =Gustavo/about |
_______________________________________________
Repoze-dev mailing list
Repoze-dev@lists.repoze.org
http://lists.repoze.org/listinfo/repoze-dev

Reply via email to