Ops sorry, here the code ... 

 

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> *Overload of the Auth_user table : ## Auth custom fields 
> auth.settings.everybody_group_id = 1 
> auth.settings.extra_fields['auth_user']= [     Field('username', 
> type='string', label=T('Username')),     Field('f_role', type='integer', 
> default=2, label=T('Role')),     Field('f_group', type='integer', 
> default=20, label=T('Group'), writable=False, readable=False),     
> Field('f_jobtitle', length=30, default='',label=T('Job title')),     
> Field('f_description', length=255, default='Description of your 
> duties',label=T('Description')),     Field('f_organization', length=30, 
> default='',label=T('Organization')),     Field('f_departement', length=30, 
> default='',label=T('Departement')),     Field('f_office', length=50, 
> default='',label=T('Office')),     Field('f_unit', type='string', 
> label=T('Unit')),         Field('f_address', type='string', 
> label=T('Address')),     Field('f_zipcode', type='string', label=T('Postal 
> Code')),     Field('f_city', type='string', label=T('City')),     
> Field('f_country', db.t_countries, label=T('Country')),     
> Field('f_phone', type='string', label=T('Phone')),     Field('f_fax', 
> type='string', label=T('Fax')),     Field('f_mobile', type='string', 
> label=T('Mobile')),     Field('f_nationality', db.t_countries, 
> label=T('Nationality')),     Field('f_www', length=30, 
> default='Organization website',label=T('Website')),     Field('f_info', 
> type='text', default='Other useful info not expressed in the above fields', 
> readable=False, label=T('Info')), ]Definition of a new  register method :*
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> *if not session.USR:     session.USR="" def register():     #Istantiate 
> the form     db.auth_user['f_avatar'].readable = 
> db.auth_user['f_avatar'].writable = False     form=auth.register()     
> #Importing and setup libraries     from selmdap_settings import *     
> import sys     try:         import ldap         import ldap.modlist as 
> modlist         ldap.set_option(ldap.OPT_REFERRALS, 0)        
>  ldap.set_option(ldap.OPT_PROTOCOL_VERSION, 3) #MS integration        
>  ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER)#MS 
> integration     except Exception, e:         logging.error('missing ldap, 
> try "easy_install python-ldap"')         #raise e     #If form submitted 
>     if form.process().accepted:         response.flash = 'form accepted' 
>         #Create a new user account in Active Directory and assigns it to 
> differents groups         # LDAP connection         try:             con = 
> ldap.initialize(LDAP_SERVER)            
>  con.set_option(ldap.OPT_X_TLS,ldap.OPT_X_TLS_DEMAND)#MS integration        
>      con.set_option( ldap.OPT_X_TLS_DEMAND, True )#MS integration        
>      con.set_option( ldap.OPT_DEBUG_LEVEL, 255 )#MS integration            
>  con.simple_bind_s(BIND_DN, BIND_PASS)         except ldap.LDAPError, 
> error_message:             session.flash = T("Error connecting to LDAP 
> server: %s" % error_message)             redirect(URL('result'))            
>  # Lets build our user: Disabled to start (514)         user_dn = 'cn=' + 
> form.vars.first_name + ' ' + form.vars.last_name + ',' + BASE_DN         
> user_attrs = {}         user_attrs['objectClass'] = ['top', 'person', 
> 'organizationalPerson', 'user']         user_attrs['cn'] = 
> form.vars.first_name + ' ' + form.vars.last_name         #-- Account 
> Property Page         user_attrs['userPrincipalName'] = session.USR + '@' + 
> DOMAIN         user_attrs['sAMAccountName'] = session.USR         
> user_attrs['userAccountControl'] = '514'         #-- General Property Page 
>         user_attrs['givenName'] = form.vars.first_name         
> user_attrs['sn'] = form.vars.last_name         user_attrs['initials'] = '' 
>         user_attrs['displayName'] = form.vars.first_name + ' ' + 
> form.vars.last_name         user_attrs['description'] = 
> form.vars.f_description         user_attrs['physicalDeliveryOfficeName'] = 
> form.vars.f_office         user_attrs['mail'] = form.vars.email         
> user_attrs['telephonenumber'] = form.vars.f_phone         
> user_attrs['otherTelephone'] = ''         user_attrs['wWWHomePage'] = 
> form.vars.f_www         user_attrs['url'] = ''         #-- Address Property 
> Page         user_attrs['streetAddress'] = form.vars.f_address         
> user_attrs['postOfficeBox'] = ''         user_attrs['l'] = form.vars.f_city 
>         #user_attrs['st'] = form.vars.stateoffice         
> user_attrs['postalcode'] = form.vars.f_zipcode         user_attrs['c'] = 
> form.vars.f_country         #-- Organization Property Page         
> user_attrs['title'] = form.vars.f_jobtitle         user_attrs['department'] 
> = form.vars.f_departement         user_attrs['company'] = 
> form.vars.f_organization         #-- Telephones Property Page         
> user_attrs['homephone'] = ''         user_attrs['otherhomephone'] = '' 
>         user_attrs['pager'] = ''         user_attrs['otherpager'] = '' 
>         user_attrs['mobile'] = form.vars.f_mobile         
> user_attrs['othermobile'] = ''         user_attrs['ipPhone'] = 
> form.vars.f_IM         user_attrs['facsimiletelephonenumber'] = 
> form.vars.f_fax         user_attrs['otherfacsimiletelephonenumber'] = '' 
>         user_attrs['ipphone'] = ''         user_attrs['otheripphone'] = '' 
>         user_attrs['info'] = form.vars.f_info         user_ldif = 
> modlist.addModlist(user_attrs)         # Prepare the password         
> unicode_pass = unicode('\"' + str(form.vars.password_two) + '\"', 
> 'iso-8859-1')         password_value = unicode_pass.encode('utf-16-le') 
>         add_pass = [(ldap.MOD_REPLACE, 'unicodePwd', [password_value])] 
>         # 512 will set user account to enabled         mod_acct = 
> [(ldap.MOD_REPLACE, 'userAccountControl', '512')]         # New group 
> membership         add_member = [(ldap.MOD_ADD, 'member', user_dn)]         
>      # Add the new user account         try:             con.add_s(user_dn, 
> user_ldif)         except ldap.LDAPError, error_message:             
> session.flash = T("Error adding new user: %s" % error_message)             
> redirect(URL('result'))              ## Add the password         try: 
>             con.modify_s(user_dn, add_pass)         except ldap.LDAPError, 
> error_message:             session.flash =  T("Error setting password: %s" 
> % error_message)             redirect(URL('result'))              ## Change 
> the account back to enabled         try:             con.modify_s(user_dn, 
> mod_acct)         except ldap.LDAPError, error_message:             
> session.flash =  T("Error enabling user: %s" % error_message)             
> redirect(URL('result'))              ## Add user to their primary group 
>         try:             con.modify_s(GROUP_DN, add_member)         except 
> ldap.LDAPError, error_message:             session.flash =  T("Error adding 
> user to group: %s" % error_message)             redirect(URL('result'))    
>           ## Add user to their secondary group         try:             
> con.modify_s(ADMIN_DN, add_member)         except ldap.LDAPError, 
> error_message:             session.flash =  T("Error adding user to group 
> Administrators: %s" % error_message)             redirect(URL('result'))    
>      ## Add user to their third group         #try:         #   
>  con.modify_s(DOMAIN_ADMIN_DN, add_member)         #except ldap.LDAPError, 
> error_message:         #    session.flash =  T("Error adding user to group 
> Administrators: %s" % error_message)         #    redirect(URL('result')) 
>         con.unbind_s()         response.flash =  "Form filled and submitted 
> successfully"     return dict(form=form)*
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to