Hi guys,

I slightly changed the LDAP backend to serve better my needs and I thought
somebody might find this useful. Only change is that user email address can
be now obtained from LDAP server rather than created from
[EMAIL PROTECTED](as in my case username and email address is completely
different).

Tom

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"reviewboard" group.
To post to this group, send email to reviewboard@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/reviewboard?hl=en
-~----------~----~----~----~------~----~------~--~---

Index: accounts/backends.py
===================================================================
--- accounts/backends.py	(revision 1613)
+++ accounts/backends.py	(working copy)
@@ -104,8 +104,13 @@
 
                 first_name = passwd[0][1]['givenName'][0]
                 last_name = passwd[0][1]['sn'][0]
-                email = u'[EMAIL PROTECTED]' % (username, settings.LDAP_EMAIL_DOMAIN)
 
+                if settings.LDAP_EMAIL_DOMAIN:
+                    email = u'[EMAIL PROTECTED]' % (username, settings.LDAP_EMAIL_DOMAIN)
+                else: 
+                    if settings.LDAP_EMAIL_ATTRIBUTE:
+                        email = passwd[0][1][settings.LDAP_EMAIL_ATTRIBUTE][0]
+
                 user = User(username=username,
                             password='',
                             first_name=first_name,
Index: admin/siteconfig.py
===================================================================
--- admin/siteconfig.py	(revision 1613)
+++ admin/siteconfig.py	(working copy)
@@ -28,6 +28,7 @@
     'auth_ldap_anon_bind_uid':    'LDAP_ANON_BIND_UID',
     'auth_ldap_anon_bind_passwd': 'LDAP_ANON_BIND_PASSWD',
     'auth_ldap_email_domain':     'LDAP_EMAIL_DOMAIN',
+    'auth_ldap_email_attribute':  'LDAP_EMAIL_ATTRIBUTE',
     'auth_ldap_tls':              'LDAP_TLS',
     'auth_ldap_base_dn':          'LDAP_BASE_DN',
     'auth_ldap_uid_mask':         'LDAP_UID_MASK',
Index: admin/forms.py
===================================================================
--- admin/forms.py	(revision 1613)
+++ admin/forms.py	(working copy)
@@ -87,8 +87,15 @@
 
     auth_ldap_email_domain = forms.CharField(
         label=_("E-Mail Domain"),
-        help_text=_("This is appened to the login username as the users email "
-                    "address."))
+        help_text=_("Email can be either created using email domain (which is appended to " 
+                    "the login username)."),
+        required=False)
+                    
+    auth_ldap_email_attribute = forms.CharField(
+        label=_("Email LDAP attribute"),
+        help_text=_("Or email is obtained from LDAP server (email is contained in specified "
+                    "LDAP object attribute). Example: mail"),
+        required=False)
 
     auth_ldap_tls = forms.BooleanField(
         label=_("Use TLS for authentication"),
@@ -142,6 +149,7 @@
         if not can_enable_ldap:
             self.disabled_fields['auth_ldap_uri'] = True
             self.disabled_fields['auth_ldap_email_domain'] = True
+            self.disabled_fields['auth_ldap_email_attribute'] = True
             self.disabled_fields['auth_ldap_tls'] = True
             self.disabled_fields['auth_ldap_base_dn'] = True
             self.disabled_fields['auth_ldap_uid_mask'] = True
@@ -243,6 +251,7 @@
                 'fields':  ('auth_ldap_uri',
                             'auth_ldap_base_dn',
                             'auth_ldap_email_domain',
+                            'auth_ldap_email_attribute',
                             'auth_ldap_tls',
                             'auth_ldap_uid_mask',
                             'auth_ldap_anon_bind_uid',

Reply via email to