diff --git a/src/Lib/Authenticate.php b/src/Lib/Authenticate.php index e86726f..2dc5641 100644 --- a/src/Lib/Authenticate.php +++ b/src/Lib/Authenticate.php @@ -68,7 +68,7 @@ class Authenticate { } try { - $this->user = $repository->loadOne(); + $this->user = $repository->loadOne() ?: $repository->instanciateEntity(); } catch(Exception\EmptyDatasetException $e) { call_user_func_array($this->authenticationEvent, [ false, 'userNotFound', $this->user ]); @@ -76,7 +76,7 @@ class Authenticate { return $repository->instanciateEntity(); } - if ( $this->user && $this->user->verifyPassword($password) ) { + if ( $this->user->isLoaded() && $this->user->verifyPassword($password) ) { $this->user->logged = true; if ( $this->session ) { @@ -90,9 +90,8 @@ class Authenticate { call_user_func_array($this->authenticationEvent, [ true, 'success', $this->user ]); } else { - $this->user = $repository->instanciateEntityCollection(); $this->user->logged = false; - + call_user_func_array($this->authenticationEvent, [ false, 'invalidPassword', $this->user ]); }