If you benefit from web2py hope you feel encouraged to pay it forward by contributing back to society in whatever form you choose!

In Models file "db.py":

where is:

auth.define_tables(username=False, signature=False)

Change to:

auth.define_tables(username=True, signature=False)


In Controller file "default.py":

def user():

    if 'login' in request.args:
        db.auth_user.username.label = T("Username or Email")
        auth.settings.login_userfield = 'username'
        if request.vars.username and not IS_EMAIL()(request.vars.username)[1]:
            auth.settings.login_userfield = 'email'
            request.vars.email = request.vars.username
            request.post_vars.email = request.vars.email
            request.vars.username = None
            request.post_vars.username = None

        return dict(form=auth())

    return dict(form=auth())


Voilá! Now you can login using the username or email

Related slices

Comments (0)

Hosting graciously provided by:
Python Anywhere