Skip to content

Commit

Permalink
Fixing deprecations from CakePHP 3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
challgren authored Jan 2, 2019
1 parent e4642b9 commit e1d0258
Showing 1 changed file with 39 additions and 51 deletions.
90 changes: 39 additions & 51 deletions src/Controller/Component/ImpersonateComponent.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
<?php
/**
* Impersonate component for Cakephp3
*
*
* Component to use impersonate to easily access as others user account
*
*
*
*
*/

namespace CakeImpersonate\Controller\Component;

use Cake\Controller\Component\AuthComponent;
use Cake\Controller\Component;
use Cake\Controller\ComponentRegistry;
use Cake\Core\Configure;
use Cake\Event\Event;
use Cake\ORM\Table;
use Cake\ORM\Entity;

/**
* Impersonate component
*/
Expand All @@ -26,68 +24,58 @@ class ImpersonateComponent extends Component
* @var array
*/
protected $_defaultConfig = [];


/**
* Initialize and use all Controller library
*
* return none
*/
public function initialize(array $config)
{
$this->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;
}
}

0 comments on commit e1d0258

Please sign in to comment.