diff --git a/src/Lib/Authenticate.php b/src/Lib/Authenticate.php index 2dc5641..29f5977 100644 --- a/src/Lib/Authenticate.php +++ b/src/Lib/Authenticate.php @@ -30,16 +30,16 @@ class Authenticate { ) { $this->session = $session; $this->cookie = $cookie; - $this->authenticationEvent = $authenticationEvent ?: function(bool $authenticated, string $message, ? User $user) : void {} ; + $this->authenticationEvent = $authenticationEvent ?: function(bool $authenticated, string $message, ? User $user, array $data = []) : bool {return false;} ; } public function rememberMe(\Ulmus\Repository $repository) : ? User { $logUser = function(int $id) use ($repository) { - if ( null === ( $user = $repository->loadOne($id) ) ) { + if ( null === ( $user = $repository->loadFromPk($id) ) ) { throw new \Exception("User not found."); } - + $user->logged = true; return $user; @@ -71,12 +71,12 @@ class Authenticate { $this->user = $repository->loadOne() ?: $repository->instanciateEntity(); } catch(Exception\EmptyDatasetException $e) { - call_user_func_array($this->authenticationEvent, [ false, 'userNotFound', $this->user ]); - - return $repository->instanciateEntity(); + if ( ! call_user_func_array($this->authenticationEvent, [ false, 'userNotFound', $this->user ]) ) { + return $repository->instanciateEntity(); + } } - if ( $this->user->isLoaded() && $this->user->verifyPassword($password) ) { + if ( $this->user->isLoaded() && ( call_user_func_array($this->authenticationEvent, [ false, 'verifyPassword', $this->user, [ 'password' => $password ] ]) || $this->user->verifyPassword($password) ) ) { $this->user->logged = true; if ( $this->session ) {