From fd9a2266ecb5f354ee5b131dd9dd90128d7858f5 Mon Sep 17 00:00:00 2001 From: Paolo Date: Wed, 13 Mar 2019 10:24:19 +0100 Subject: [PATCH] Added new public method loginLDAP to AuthLib --- application/libraries/AuthLib.php | 33 +++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/application/libraries/AuthLib.php b/application/libraries/AuthLib.php index 7f5dd1078..adc286c9c 100644 --- a/application/libraries/AuthLib.php +++ b/application/libraries/AuthLib.php @@ -154,6 +154,39 @@ class AuthLib } } + /** + * Login a user with the given username and password using LDAP + */ + public function loginLDAP($username, $password) + { + $loginUP = $this->_checkLDAPAuthentication($username, $password); + if (isSuccess($loginUP)) + { + $this->_ci->PersonModel->resetQuery(); // Reset an eventually already built query + + // Retrieves user data from DB using the UID + $personResult = $this->_ci->PersonModel->getByUid($username); + if (hasData($personResult)) + { + $person = getData($personResult)[0]; + + // Stores used data into the authentication object and then into a success object + $loginUP = success( + $this->_createAuthObj($person->person_id, $person->vorname, $person->nachname, $username), + AUTH_SUCCESS + ); + + $this->_storeAuthObj(getData($loginUP)); + } + elseif (isError($personResult)) // blocking error + { + $loginUP = $personResult; // to be displayed + } + } + + return $loginUP; + } + //------------------------------------------------------------------------------------------------------------------ // Private methods