]> git.mxchange.org Git - friendica-addons.git/blobdiff - ldapauth/ldapauth.php
Merge pull request #534 from tobiasd/20180218-en
[friendica-addons.git] / ldapauth / ldapauth.php
old mode 100755 (executable)
new mode 100644 (file)
index 39be691..d06874b
  *
  * ...etc.
  */
-
-require_once('include/user.php');
-
+use Friendica\Core\Addon;
 use Friendica\Core\Config;
+use Friendica\Model\User;
 
 function ldapauth_install()
 {
-       register_hook('authenticate', 'addon/ldapauth/ldapauth.php', 'ldapauth_hook_authenticate');
+       Addon::registerHook('authenticate', 'addon/ldapauth/ldapauth.php', 'ldapauth_hook_authenticate');
 }
 
 function ldapauth_uninstall()
 {
-       unregister_hook('authenticate', 'addon/ldapauth/ldapauth.php', 'ldapauth_hook_authenticate');
+       Addon::unregisterHook('authenticate', 'addon/ldapauth/ldapauth.php', 'ldapauth_hook_authenticate');
 }
 
 function ldapauth_hook_authenticate($a, &$b)
@@ -91,7 +90,7 @@ function ldapauth_authenticate($username, $password)
        $ldap_autocreateaccount_emailattribute = Config::get('ldapauth', 'ldap_autocreateaccount_emailattribute');
        $ldap_autocreateaccount_nameattribute  = Config::get('ldapauth', 'ldap_autocreateaccount_nameattribute');
 
-       if (!((strlen($password)) && (function_exists('ldap_connect')) && (strlen($ldap_server)))) {
+       if (!(strlen($password) && function_exists('ldap_connect') && strlen($ldap_server))) {
                logger("ldapauth: not configured or missing php-ldap module");
                return false;
        }
@@ -178,12 +177,13 @@ function ldap_autocreateaccount($ldap_autocreateaccount, $username, $password, $
                $results = get_existing_account($username);
                if (empty($results)) {
                        if (strlen($email) > 0 && strlen($name) > 0) {
-                               $arr = array('username' => $name, 'nickname' => $username, 'email' => $email, 'password' => $password, 'verified' => 1);
-                               $result = create_user($arr);
-                               if ($result['success']) {
+                               $arr = ['username' => $name, 'nickname' => $username, 'email' => $email, 'password' => $password, 'verified' => 1];
+
+                               try {
+                                       User::create($arr);
                                        logger("ldapauth: account " . $username . " created");
-                               } else {
-                                       logger("ldapauth: account " . $username . " was not created ! : " . implode($result));
+                               } catch (Exception $ex) {
+                                       logger("ldapauth: account " . $username . " was not created ! : " . $ex->getMessage());
                                }
                        } else {
                                logger("ldapauth: unable to create account, no email or nickname found");