Browse Source

Added LDAP user email on account creation (#1244)

CauseFX 5 years ago
parent
commit
4f2a18f92f
1 changed files with 12 additions and 1 deletions
  1. 12 1
      api/functions/auth-functions.php

+ 12 - 1
api/functions/auth-functions.php

@@ -322,8 +322,19 @@ if (function_exists('ldap_connect')) {
 				$provider = $ad->connect();
 				//prettyPrint($provider);
 				if ($provider->auth()->attempt($username, $password)) {
+					try {
+						// Try and get email from LDAP server
+						$accountDN = ((empty($GLOBALS['authBackendHostPrefix'])) ? null : $GLOBALS['authBackendHostPrefix']) . $username . ((empty($GLOBALS['authBackendHostSuffix'])) ? null : $GLOBALS['authBackendHostSuffix']);
+						$record = $provider->search()->findByDnOrFail($accountDN);
+						$email = $record->getFirstAttribute('mail');
+					} catch (Adldap\Models\ModelNotFoundException $e) {
+						// Record wasn't found!
+						$email = null;
+					}
 					// Passed.
-					return true;
+					return array(
+						'email' => $email
+					);
 				} else {
 					// Failed.
 					return false;