diff options
author | Evan Prodromou <evan@status.net> | 2009-11-07 12:22:20 -0500 |
---|---|---|
committer | Evan Prodromou <evan@status.net> | 2009-11-07 12:22:20 -0500 |
commit | af5b2fff12d12b0e79edfbe7d5c28ec7fef196f3 (patch) | |
tree | 13d0d92d99cc678cd0a0ad1488ab0ea16a633ca5 /plugins/Ldap/LdapPlugin.php | |
parent | 1319002e1519fafb0e82fbfd2d2723abdb3112e7 (diff) | |
parent | b522c401e66e5b5d7e000c1bf25fd4b4a4d0558f (diff) |
Merge branch '0.9.x' of git@gitorious.org:statusnet/mainline into 0.9.x
Diffstat (limited to 'plugins/Ldap/LdapPlugin.php')
-rw-r--r-- | plugins/Ldap/LdapPlugin.php | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/plugins/Ldap/LdapPlugin.php b/plugins/Ldap/LdapPlugin.php index ec2b7977d..755562f54 100644 --- a/plugins/Ldap/LdapPlugin.php +++ b/plugins/Ldap/LdapPlugin.php @@ -46,7 +46,60 @@ class LdapPlugin extends Plugin { if(ldap_check_password($nickname, $password)){ $authenticated = true; + //stop handling of other events, because we have an answer return false; } + if(common_config('ldap','authoritative')){ + //a false return stops handler processing + return false; + } + } + + function onAutoRegister($nickname) + { + $user = User::staticGet('nickname', $nickname); + if (! is_null($user) && $user !== false) { + common_log(LOG_WARNING, "An attempt was made to autoregister an existing user with nickname: $nickname"); + return; + } + + $attributes=array(); + $config_attributes = array('nickname','email','fullname','homepage','location'); + foreach($config_attributes as $config_attribute){ + $value = common_config('ldap', $config_attribute.'_attribute'); + if($value!==false){ + array_push($attributes,$value); + } + } + $entry = ldap_get_user($nickname,$attributes); + if($entry){ + $registration_data = array(); + foreach($config_attributes as $config_attribute){ + $value = common_config('ldap', $config_attribute.'_attribute'); + if($value!==false){ + if($config_attribute=='email'){ + $registration_data[$config_attribute]=common_canonical_email($entry->getValue($value,'single')); + }else if($config_attribute=='nickname'){ + $registration_data[$config_attribute]=common_canonical_nickname($entry->getValue($value,'single')); + }else{ + $registration_data[$config_attribute]=$entry->getValue($value,'single'); + } + } + } + //set the database saved password to a random string. + $registration_data['password']=common_good_rand(16); + $user = User::register($registration_data); + //prevent other handlers from running, as we have registered the user + return false; + } + } + + function onChangePassword($nickname,$oldpassword,$newpassword,&$errormsg) + { + //TODO implement this + $errormsg = _('Sorry, changing LDAP passwords is not supported at this time'); + + //return false, indicating that the event has been handled + return false; } } |