Web2py - Howto Auto Convert Uppercase Username

I want all users who are logged in to change their name (converted) to uppercase in DB records or before it gets to DB.

I am currently using LDAP. Thus, people can freely use the signs:

['PREACTIVE', 'Preactive', 'preactive', 'PREactive', 'preACTIVE']

They will each get a new version of Auth_User.id # and a DB for db.auth_membership.id for each option, although LDAP doesn't care about the case. With over 100 users with each user having ~ 20 entries for each AD group makes it really a mess.

Here is the code I'm currently using:

    ## create all tables needed by auth if not custom tables
    auth.define_tables(username=True)

    auth.settings.create_user_groups=False

    # all we need is login
    auth.settings.actions_disabled=['register','change_password','request_reset_password','retrieve_username','profile']

    # you don't have to remember me
    auth.settings.remember_me_form = True

    # ldap authentication and not save password on web2py
    from gluon.contrib.login_methods.ldap_auth import ldap_auth
    auth.settings.login_methods = [ldap_auth(mode='ad',
       manage_groups= True,
       db = db,
       manage_user = True,
       username_attrib = 'sAMAccountName',
       user_firstname_attrib = 'cn:1',
       user_lastname_attrib = 'sn',
       user_mail_attrib = 'mail',
       group_name_attrib = 'cn',
       group_member_attrib = 'member',
       group_filterstr = 'objectClass=Group',
       server='corp.server.com',
       base_dn='DC=corp,DC=server,DC=com')]

      

Link to: { http://www.web2pyslices.com/slice/show/1468/how-to-set-up-web2py-ldap-with-windows-active-directory

, http://www.web2pyslices.com/slice/show/1715/authentication-and-group-control-with-active-directory-ldap

, http://www.web2pyslices.com/slice/show/1476/ldap-auth-with-allowed-groups-and-manage-groups

}

Database view (CSV):

auth_user.id,auth_user.first_name,auth_user.last_name,auth_user.email,auth_user.username,auth_user.password,auth_user.registration_key,auth_user.reset_password_key,auth_user.registration_id
1,Pre,Active,p@gmail.com,Preactive,,,,Preactive
2,Pre,Active,p@gmail.com,PREACTIVE,,,,PREACTIVE
3,Pre,Active,p@gmail.com,PREactive,,,,PREactive
4,Pre,Active,p@gmail.com,preACTIVE,,,,preACTIVE

      

EDIT1: Added this to db.py to try to grab vars before it gets to DB I / O. But it creates two records in the DB. One upper case, not associated with LDAP groups, etc. And the second, which has to do with what the user actually entered into the association with LDAP groups.

def login_upper(form):
    form.vars.username = form.vars.username.upper()
    return form

auth.settings.login_onvalidation = login_upper
auth.settings.profile_onvalidation = login_upper

      

EDIT2:

Edit1 Abandoned.

Modified code in ldap_auth.py (note that I need to restart web2py.exe to see the changes made to. \ Web2Py \ gluon \ contrib \ login_methods *)

    if ldap_mode == 'ad':
        # Microsoft Active Directory
        if '@' not in username:
            domain = []
            for x in ldap_basedn.split(','):
                if "DC=" in x.upper():
                    domain.append(x.split('=')[-1])
            username = "%s@%s" % (username, '.'.join(domain))
        username_bare = username.split("@")[0].upper()
        con.set_option(ldap.OPT_PROTOCOL_VERSION, 3)

      

was:   username_bare = username.split("@")[0]

Now:   username_bare = username.split("@")[0].upper()

and when the user logs into the revised entry to which the AD groups are bound, but the current user logged into the web2py sessions is the case sensitive entry that hit the DB.

EDIT3:

It looks like I can't change after Auth () starts manipulating the data in the username field. So I need to figure out how to change the login form variables before calling Auth (). So all subsequent fields will follow the same case and not create additional DB records ....... Connecting to Code Testing and Googling .....

Edit4: (FINAL)

FIXED IT !!!!

def user():
    if request.args(0) == 'login' and request.post_vars.username:
        request.post_vars.username = request.vars.username = request.post_vars.username.upper() # changes field to all uppercase
    return dict(form=auth())

      

Now user can enter their name but they like (caSewiSe) and it will catch and convert before hitting Auth and only one entry in db.auth_user.id

Thanks to a post in 2012 from Marin Pranjic:  https://groups.google.com/forum/#!topic/web2py/Tdse7GDwJ28

RESOLVED !!!!!!

+3


source to share


1 answer


Edit4: Fixed issue: Solution

def user():
    if request.args(0) == 'login' and request.post_vars.username:
        request.post_vars.username = request.vars.username = request.post_vars.username.upper() # changes field to all uppercase
    return dict(form=auth())

      



So this was part of what IanAuld said, but it was WHERE if it was key.

+2


source







All Articles