diff --git a/src/Controller/Component/ImpersonateComponent.php b/src/Controller/Component/ImpersonateComponent.php index 108524a..a07a152 100644 --- a/src/Controller/Component/ImpersonateComponent.php +++ b/src/Controller/Component/ImpersonateComponent.php @@ -1,19 +1,17 @@ controller = $this->_registry->getController(); - - } - + /** * Function impersonate * - * receive user Id - * return true + * @param mixed $id + * @return bool */ - public function login($id){ - - $this->controller->loadModel('Users'); - - $originalAuth = $this->request->getSession()->read('Auth'); - - $users = $this->controller->Users->get($id); - $this->controller->Auth->setUser($users->toArray()); - $this->request->getSession()->write('OriginalAuth',$originalAuth); - + public function login($id) + { + $this->getController()->loadModel('Users'); + + $originalAuth = $this->getController()->getRequest()->getSession()->read('Auth'); + + /** @var Entity $users */ + $users = $this->getController()->Users->get($id); + $this->getController()->Auth->setUser($users->toArray()); + $this->getController()->getRequest()->getSession()->write('OriginalAuth', $originalAuth); + return true; } - + /** * Function isImpersonate * - * To check wether current account is under impersonate - * return boolean + * To check if current account is being impersonated + * @return bool */ - public function isImpersonate() { - - if($this->request->getSession()->read('OriginalAuth')){ + public function isImpersonate() + { + if ($this->getController()->getRequest()->getSession()->read('OriginalAuth')) { + return true; } - + return false; } - + /** * Function logout * - * To logout impersonate account - * return true + * To log out of impersonated account + * + * @return bool */ - public function logout() { - - if($this->isImpersonate()) { - $Auth = $this->request->session()->read('OriginalAuth'); - $this->request->getSession()->write('Auth',$Auth); - - $this->request->getSession()->delete('OriginalAuth'); + public function logout() + { + if ($this->isImpersonate()) { + $Auth = $this->getController()->getRequest()->getSession()->read('OriginalAuth'); + $this->getController()->getRequest()->getSession()->write('Auth', $Auth); + $this->getController()->getRequest()->getSession()->delete('OriginalAuth'); } - + return true; } }