44use ProspectOne \UserModule \Entity \User ;
55use ProspectOne \UserModule \Exception \LogicException ;
66use ProspectOne \UserModule \Interfaces \UserInterface ;
7+ use ProspectOne \UserModule \Model \UserModel ;
78use Zend \Authentication \Adapter \AdapterInterface ;
89use Zend \Authentication \Result ;
910use Zend \Crypt \Password \Bcrypt ;
@@ -60,6 +61,11 @@ class AuthAdapterService implements AdapterInterface
6061 */
6162 protected $ currentUser ;
6263
64+ /**
65+ * @var UserModel
66+ */
67+ private $ userModel ;
68+
6369 /**
6470 * @return UserInterface
6571 */
@@ -122,6 +128,14 @@ protected function setAuthHeader(string $authHeader): AuthAdapterService
122128 return $ this ;
123129 }
124130
131+ /**
132+ * @return UserModel
133+ */
134+ private function getUserModel (): UserModel
135+ {
136+ return $ this ->userModel ;
137+ }
138+
125139 /**
126140 * AuthAdapterService constructor.
127141 * @param $entityManager
@@ -130,15 +144,18 @@ protected function setAuthHeader(string $authHeader): AuthAdapterService
130144 * @param string $headerValue
131145 * @param string $email
132146 * @param string $userEntityClassName
147+ * @param UserModel $userModel
133148 */
134- public function __construct ($ entityManager , Bcrypt $ bcrypt , bool $ headerAuthEnabled , ?string $ headerValue = "" , ?string $ email = "" , $ userEntityClassName )
149+ public function __construct ($ entityManager , Bcrypt $ bcrypt , bool $ headerAuthEnabled , ?string $ headerValue = "" , ?string $ email = "" ,
150+ $ userEntityClassName , UserModel $ userModel )
135151 {
136152 $ this ->entityManager = $ entityManager ;
137153 $ this ->bcrypt = $ bcrypt ;
138154 $ this ->headerAuthEnabled = $ headerAuthEnabled ;
139155 $ this ->authHeader = $ headerValue ;
140156 $ this ->email = $ email ;
141157 $ this ->userEntityClassName = $ userEntityClassName ;
158+ $ this ->userModel = $ userModel ;
142159 }
143160
144161 /**
@@ -188,8 +205,7 @@ public function setPassword($password)
188205 */
189206 public function authenticate ()
190207 {
191- /** @var UserInterface $user */
192- $ user = $ this ->getUserByEmail ($ this ->email );
208+ $ user = $ this ->getUserModel ()->getUserByEmail ($ this ->getEmail ());
193209 return $ this ->validateUser ($ user );
194210 }
195211
@@ -300,8 +316,8 @@ public function getUserByEmail(string $email)
300316 public function getCurrentUserEntity ()
301317 {
302318 if (empty ($ this ->getCurrentUser ()) && !empty ($ this ->getEmail ())) {
303- $ user = $ this ->getUserByEmail ($ this ->getEmail ());
304- if ($ user ) {
319+ $ user = $ this ->getUserModel ()-> getUserByEmail ($ this ->getEmail ());
320+ if (! empty ( $ user) ) {
305321 $ this ->setCurrentUser ($ user );
306322 }
307323 }
0 commit comments