Skip to content

Commit

Permalink
Replace deprecated methods for 3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
jtraulle committed Apr 1, 2018
1 parent db86895 commit 603c111
Show file tree
Hide file tree
Showing 36 changed files with 171 additions and 177 deletions.
2 changes: 1 addition & 1 deletion Docs/Documentation/Extending-the-Plugin.md
Expand Up @@ -151,7 +151,7 @@ You could use a new Trait. For example, you want to add an 'impersonate' feature
namespace App\Controller\Traits;

use Cake\Datasource\Exception\RecordNotFoundException;
use Cake\Network\Exception\NotFoundException;
use Cake\Http\Exception\NotFoundException;

/**
* Impersonate Trait
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -27,7 +27,7 @@
"source": "https://github.com/CakeDC/users"
},
"require": {
"cakephp/cakephp": "^3.5.0",
"cakephp/cakephp": "dev-3.next",
"cakedc/auth": "^2.0"
},
"require-dev": {
Expand Down
4 changes: 2 additions & 2 deletions config/bootstrap.php
Expand Up @@ -22,8 +22,8 @@
Configure::load($file);
});

TableRegistry::config('Users', ['className' => Configure::read('Users.table')]);
TableRegistry::config('CakeDC/Users.Users', ['className' => Configure::read('Users.table')]);
TableRegistry::getTableLocator()->setConfig('Users', ['className' => Configure::read('Users.table')]);
TableRegistry::getTableLocator()->setConfig('CakeDC/Users.Users', ['className' => Configure::read('Users.table')]);

if (Configure::check('Users.auth')) {
Configure::write('Auth.authenticate.all.userModel', Configure::read('Users.table'));
Expand Down
2 changes: 1 addition & 1 deletion config/permissions.php
Expand Up @@ -39,7 +39,7 @@
'action' => ['edit', 'delete'],
'allowed' => function(array $user, $role, Request $request) {
$postId = Hash::get($request->params, 'pass.0');
$post = TableRegistry::get('Posts')->get($postId);
$post = TableRegistry::getTableLocator()->get('Posts')->get($postId);
$userId = Hash::get($user, 'id');
if (!empty($post->user_id) && !empty($userId)) {
return $post->user_id === $userId;
Expand Down
6 changes: 3 additions & 3 deletions src/Auth/SocialAuthenticate.php
Expand Up @@ -268,8 +268,8 @@ protected function _map($data)
* application.
*
* @param \Cake\Http\ServerRequest $request Request object.
* @param \Cake\Network\Response $response Response object.
* @return \Cake\Network\Response|null
* @param \Cake\Http\Response $response Response object.
* @return \Cake\Http\Response|null
*/
public function unauthenticated(ServerRequest $request, Response $response)
{
Expand Down Expand Up @@ -480,7 +480,7 @@ protected function _socialLogin($data)
];

$userModel = Configure::read('Users.table');
$User = TableRegistry::get($userModel);
$User = TableRegistry::getTableLocator()->get($userModel);
$user = $User->socialLogin($data, $options);

return $user;
Expand Down
14 changes: 7 additions & 7 deletions src/Controller/Component/RememberMeComponent.php
Expand Up @@ -105,8 +105,8 @@ public function setLoginCookie(Event $event)
if (empty($user)) {
return;
}
$user['user_agent'] = $this->getController()->request->getHeaderLine('User-Agent');
if (!(bool)$this->getController()->request->getData(Configure::read('Users.Key.Data.rememberMe'))) {
$user['user_agent'] = $this->getController()->getRequest()->getHeaderLine('User-Agent');
if (!(bool)$this->getController()->getRequest()->getData(Configure::read('Users.Key.Data.rememberMe'))) {
return;
}
$this->Cookie->write($this->_cookieName, $user);
Expand Down Expand Up @@ -135,10 +135,10 @@ public function beforeFilter(Event $event)
{
$user = $this->Auth->user();
if (!empty($user) ||
$this->getController()->request->is(['post', 'put']) ||
$this->getController()->request->getParam('action') === 'logout' ||
$this->getController()->request->getSession()->check(Configure::read('Users.Key.Session.social')) ||
$this->getController()->request->getParam('provider')) {
$this->getController()->getRequest()->is(['post', 'put']) ||
$this->getController()->getRequest()->getParam('action') === 'logout' ||
$this->getController()->getRequest()->getSession()->check(Configure::read('Users.Key.Session.social')) ||
$this->getController()->getRequest()->getParam('provider')) {
return;
}

Expand All @@ -152,7 +152,7 @@ public function beforeFilter(Event $event)
if (is_array($event->result)) {
return $this->getController()->redirect($event->result);
}
$url = $this->getController()->request->getRequestTarget();
$url = $this->getController()->getRequest()->getRequestTarget();

return $this->getController()->redirect($url);
}
Expand Down
10 changes: 5 additions & 5 deletions src/Controller/Component/UsersAuthComponent.php
Expand Up @@ -116,8 +116,8 @@ protected function _initAuth()
}

list($plugin, $controller) = pluginSplit(Configure::read('Users.controller'));
if ($this->getController()->request->getParam('plugin', null) === $plugin &&
$this->getController()->request->getParam('controller') === $controller
if ($this->getController()->getRequest()->getParam('plugin', null) === $plugin &&
$this->getController()->getRequest()->getParam('controller') === $controller
) {
$this->getController()->Auth->allow([
// LoginTrait
Expand Down Expand Up @@ -150,7 +150,7 @@ protected function _initAuth()
*/
public function isUrlAuthorized(Event $event)
{
$url = Hash::get((array)$event->data, 'url');
$url = Hash::get((array)$event->getData(), 'url');
if (empty($url)) {
return false;
}
Expand Down Expand Up @@ -185,7 +185,7 @@ public function isUrlAuthorized(Event $event)
}

$request = new ServerRequest($requestUrl);
$request = $request->addParams($requestParams);
$request = $request->withAttribute('params', $requestParams);

$isAuthorized = $this->getController()->Auth->isAuthorized(null, $request);

Expand Down Expand Up @@ -220,7 +220,7 @@ protected function _isActionAllowed($requestParams = [])
if (empty($requestParams['action'])) {
return false;
}
if (!empty($requestParams['controller']) && $requestParams['controller'] !== $this->getController()->name) {
if (!empty($requestParams['controller']) && $requestParams['controller'] !== $this->getController()->getName()) {
return false;
}
$action = strtolower($requestParams['action']);
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/SocialAccountsController.php
Expand Up @@ -15,7 +15,7 @@
use CakeDC\Users\Exception\AccountAlreadyActiveException;
use CakeDC\Users\Model\Table\SocialAccountsTable;
use Cake\Datasource\Exception\RecordNotFoundException;
use Cake\Network\Response;
use Cake\Http\Response;

/**
* SocialAccounts Controller
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Traits/CustomUsersTableTrait.php
Expand Up @@ -33,7 +33,7 @@ public function getUsersTable()
if ($this->_usersTable instanceof Table) {
return $this->_usersTable;
}
$this->_usersTable = TableRegistry::get(Configure::read('Users.table'));
$this->_usersTable = TableRegistry::getTableLocator()->get(Configure::read('Users.table'));

return $this->_usersTable;
}
Expand Down
16 changes: 8 additions & 8 deletions src/Controller/Traits/LinkSocialTrait.php
Expand Up @@ -13,7 +13,7 @@

use CakeDC\Users\Model\Table\SocialAccountsTable;
use Cake\Core\Configure;
use Cake\Network\Exception\NotFoundException;
use Cake\Http\Exception\NotFoundException;
use League\OAuth1\Client\Server\Twitter;

/**
Expand All @@ -27,8 +27,8 @@ trait LinkSocialTrait
*
* @param string $alias of the provider.
*
* @throws \Cake\Network\Exception\NotFoundException Quando o provider informado não existe
* @return \Cake\Network\Response Redirects on successful
* @throws \Cake\Http\Exception\NotFoundException Quando o provider informado não existe
* @return \Cake\Http\Response Redirects on successful
*/
public function linkSocial($alias = null)
{
Expand All @@ -52,8 +52,8 @@ public function linkSocial($alias = null)
*
* @param string $alias of the provider.
*
* @throws \Cake\Network\Exception\NotFoundException Quando o provider informado não existe
* @return \Cake\Network\Response Redirects to profile if okay or error
* @throws \Cake\Http\Exception\NotFoundException Quando o provider informado não existe
* @return \Cake\Http\Response Redirects to profile if okay or error
*/
public function callbackLinkSocial($alias = null)
{
Expand Down Expand Up @@ -117,7 +117,7 @@ public function callbackLinkSocial($alias = null)

$this->getUsersTable()->linkSocialAccount($user, $data);

if ($user->errors()) {
if ($user->getErrors()) {
$this->Flash->error($message);
} else {
$this->Flash->success(__d('CakeDC/Users', 'Social account was associated.'));
Expand Down Expand Up @@ -161,7 +161,7 @@ protected function _mapSocialUser($alias, $data)
*
* @param string $alias of the provider.
*
* @throws \Cake\Network\Exception\NotFoundException
* @throws \Cake\Http\Exception\NotFoundException
* @return \League\OAuth2\Client\Provider\AbstractProvider|\League\OAuth1\Client\Server\Twitter
*/
protected function _getSocialProvider($alias)
Expand All @@ -184,7 +184,7 @@ protected function _getSocialProvider($alias)
* @param array $config for social provider.
* @param string $alias provider alias
*
* @throws \Cake\Network\Exception\NotFoundException
* @throws \Cake\Http\Exception\NotFoundException
* @return \League\OAuth2\Client\Provider\AbstractProvider|\League\OAuth1\Client\Server\Twitter
*/
protected function _createSocialProvider($config, $alias = null)
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Traits/LoginTrait.php
Expand Up @@ -19,7 +19,7 @@
use Cake\Core\Configure;
use Cake\Core\Exception\Exception;
use Cake\Event\Event;
use Cake\Network\Exception\NotFoundException;
use Cake\Http\Exception\NotFoundException;
use Cake\Utility\Hash;
use League\OAuth1\Client\Server\Twitter;

Expand Down
8 changes: 4 additions & 4 deletions src/Controller/Traits/PasswordManagementTrait.php
Expand Up @@ -47,12 +47,12 @@ public function changePassword()
$validatePassword = false;
if (!$user->id) {
$this->Flash->error(__d('CakeDC/Users', 'User was not found'));
$this->redirect($this->Auth->config('loginAction'));
$this->redirect($this->Auth->getConfig('loginAction'));

return;
}
//@todo add to the documentation: list of routes used
$redirect = $this->Auth->config('loginAction');
$redirect = $this->Auth->getConfig('loginAction');
}
$this->set('validatePassword', $validatePassword);
if ($this->request->is('post')) {
Expand All @@ -66,7 +66,7 @@ public function changePassword()
$this->request->getData(),
['validate' => $validator]
);
if ($user->errors()) {
if ($user->getErrors()) {
$this->Flash->error(__d('CakeDC/Users', 'Password could not be changed'));
} else {
$user = $this->getUsersTable()->changePassword($user);
Expand Down Expand Up @@ -105,7 +105,7 @@ public function resetPassword($token = null)
/**
* Reset password
*
* @return void|\Cake\Network\Response
* @return void|\Cake\Http\Response
*/
public function requestResetPassword()
{
Expand Down
4 changes: 2 additions & 2 deletions src/Controller/Traits/RegisterTrait.php
Expand Up @@ -14,8 +14,8 @@
use CakeDC\Users\Controller\Component\UsersAuthComponent;
use Cake\Core\Configure;
use Cake\Datasource\EntityInterface;
use Cake\Network\Exception\NotFoundException;
use Cake\Network\Response;
use Cake\Http\Exception\NotFoundException;
use Cake\Http\Response;

/**
* Covers registration features and email token validation
Expand Down
14 changes: 7 additions & 7 deletions src/Controller/Traits/SimpleCrudTrait.php
Expand Up @@ -11,8 +11,8 @@

namespace CakeDC\Users\Controller\Traits;

use Cake\Network\Exception\NotFoundException;
use Cake\Network\Response;
use Cake\Http\Exception\NotFoundException;
use Cake\Http\Response;
use Cake\Utility\Inflector;

/**
Expand All @@ -30,7 +30,7 @@ trait SimpleCrudTrait
public function index()
{
$table = $this->loadModel();
$tableAlias = $table->alias();
$tableAlias = $table->getAlias();
$this->set($tableAlias, $this->paginate($table));
$this->set('tableAlias', $tableAlias);
$this->set('_serialize', [$tableAlias, 'tableAlias']);
Expand All @@ -46,7 +46,7 @@ public function index()
public function view($id = null)
{
$table = $this->loadModel();
$tableAlias = $table->alias();
$tableAlias = $table->getAlias();
$entity = $table->get($id, [
'contain' => []
]);
Expand All @@ -63,7 +63,7 @@ public function view($id = null)
public function add()
{
$table = $this->loadModel();
$tableAlias = $table->alias();
$tableAlias = $table->getAlias();
$entity = $table->newEntity();
$this->set($tableAlias, $entity);
$this->set('tableAlias', $tableAlias);
Expand Down Expand Up @@ -91,7 +91,7 @@ public function add()
public function edit($id = null)
{
$table = $this->loadModel();
$tableAlias = $table->alias();
$tableAlias = $table->getAlias();
$entity = $table->get($id, [
'contain' => []
]);
Expand Down Expand Up @@ -122,7 +122,7 @@ public function delete($id = null)
{
$this->request->allowMethod(['post', 'delete']);
$table = $this->loadModel();
$tableAlias = $table->alias();
$tableAlias = $table->getAlias();
$entity = $table->get($id, [
'contain' => []
]);
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Traits/SocialTrait.php
Expand Up @@ -12,7 +12,7 @@
namespace CakeDC\Users\Controller\Traits;

use Cake\Core\Configure;
use Cake\Network\Exception\NotFoundException;
use Cake\Http\Exception\NotFoundException;

/**
* Covers registration features and email token validation
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Traits/UserValidationTrait.php
Expand Up @@ -15,7 +15,7 @@
use CakeDC\Users\Exception\UserAlreadyActiveException;
use CakeDC\Users\Exception\UserNotFoundException;
use Cake\Core\Configure;
use Cake\Network\Response;
use Cake\Http\Response;
use Exception;

/**
Expand Down
13 changes: 6 additions & 7 deletions src/Mailer/UsersMailer.php
Expand Up @@ -11,7 +11,6 @@
namespace CakeDC\Users\Mailer;

use Cake\Datasource\EntityInterface;
use Cake\Mailer\Email;
use Cake\Mailer\Mailer;

/**
Expand All @@ -33,10 +32,10 @@ protected function validation(EntityInterface $user)
$user->setHidden(['password', 'token_expires', 'api_token']);
$subject = __d('CakeDC/Users', 'Your account validation link');
$this
->to($user['email'])
->setSubject($firstName . $subject)
->setViewVars($user->toArray())
->setTemplate('CakeDC/Users.validation');
->setTo($user['email'])
->setSubject($firstName . $subject)
->setViewVars($user->toArray())
->setTemplate('CakeDC/Users.validation');
}

/**
Expand All @@ -54,7 +53,7 @@ protected function resetPassword(EntityInterface $user)
$user->setHidden(['password', 'token_expires', 'api_token']);

$this
->to($user['email'])
->setTo($user['email'])
->setSubject($subject)
->setViewVars($user->toArray())
->setTemplate('CakeDC/Users.resetPassword');
Expand All @@ -74,7 +73,7 @@ protected function socialAccountValidation(EntityInterface $user, EntityInterfac
// note: we control the space after the username in the previous line
$subject = __d('CakeDC/Users', '{0}Your social account validation link', $firstName);
$this
->to($user['email'])
->setTo($user['email'])
->setSubject($subject)
->setViewVars(compact('user', 'socialAccount'))
->setTemplate('CakeDC/Users.socialAccountValidation');
Expand Down

0 comments on commit 603c111

Please sign in to comment.