Skip to content

Commit

Permalink
Merge pull request #681 from CakeDC/develop
Browse files Browse the repository at this point in the history
Release v7.0.0
  • Loading branch information
steinkel authored Apr 20, 2018
2 parents aafdf85 + a2cf90d commit 0dc1802
Show file tree
Hide file tree
Showing 45 changed files with 253 additions and 190 deletions.
4 changes: 2 additions & 2 deletions .semver
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
:major: 6
:major: 7
:minor: 0
:patch: 1
:patch: 0
:special: ''
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ php:
- 5.6
- 7.0
- 7.1
- 7.2

sudo: false

Expand All @@ -20,10 +21,10 @@ matrix:
fast_finish: true

include:
- php: 7.0
- php: 7.1
env: PHPCS=1 DEFAULT=0

- php: 7.0
- php: 7.1
env: CODECOVERAGE=1 DEFAULT=0 DB=mysql db_dsn='mysql://[email protected]/cakephp_test'

before_script:
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ Changelog
Releases for CakePHP 3
-------------

* 7.0.0
* Removed deprecations for CakePHP 3.6
* Added a new `UsersAuthComponent::EVENT_AFTER_CHANGE_PASSWORD`
* Updated docs

* 6.0.0
* Removed deprecations and orWhere usage
* Amazon login implemented
Expand Down
2 changes: 1 addition & 1 deletion Docs/Documentation/Extending-the-Plugin.md
Original file line number Diff line number Diff line change
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
5 changes: 4 additions & 1 deletion Docs/Documentation/Installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ Load the Component in your src/Controller/AppController.php, and use the passed
public function initialize()
{
parent::initialize();
$this->loadComponent('Flash');
// Important: add the 'enableBeforeRedirect' config or or disable deprecation warnings
$this->loadComponent('RequestHandler', ['enableBeforeRedirect' => false]);
$this->loadComponent('Flash');
$this->loadComponent('CakeDC/Users.UsersAuth');
}
```
18 changes: 18 additions & 0 deletions Docs/Documentation/Migration/6.x-7.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Migration 6.x to 7.0
======================

7.0 is compatible with CakePHP ^3.6 and the plugin code was updated to remove all deprecations.

* Add 'enableBeforeRedirect' configuration option to RequestHandler component load in your `src/Controller/AppController.php` file

```
public function initialize()
{
parent::initialize();
// Important: add the 'enableBeforeRedirect' config or or disable deprecation warnings
$this->loadComponent('RequestHandler', ['enableBeforeRedirect' => false]);
$this->loadComponent('Flash');
$this->loadComponent('CakeDC/Users.UsersAuth');
}
```
1 change: 1 addition & 0 deletions Docs/Home.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ Migration guides
----------------

* [4.x to 5.0](Documentation/Migration/4.x-5.0.md)
* [6.x to 7.0](Documentation/Migration/6.x-7.0.md)


2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License

Copyright 2009-2017
Copyright 2009-2018
Cake Development Corporation
1785 E. Sahara Avenue, Suite 490-423
Las Vegas, Nevada 89104
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ Versions and branches

| CakePHP | CakeDC Users Plugin | Tag | Notes |
| :-------------: | :------------------------: | :--: | :---- |
| ^3.5 | [master](https://github.com/cakedc/users/tree/master) | 6.0.1 | stable |
| ^3.5 | [develop](https://github.com/cakedc/users/tree/develop) | - | unstable |
| ^3.6 | [master](https://github.com/cakedc/users/tree/master) | 7.0.0 | stable |
| ^3.6 | [develop](https://github.com/cakedc/users/tree/develop) | - | unstable |
| 3.5 | [6.x](https://github.com/cakedc/users/tree/6.x) | 6.0.1 | stable |
| 3.4 | [5.x](https://github.com/cakedc/users/tree/5.x) | 5.2.0 | stable |
| 3.3 | [4.x](https://github.com/cakedc/users/tree/4.x) | 4.2.0 | stable |
| 2.x | [2.x](https://github.com/cakedc/users/tree/2.x) | 2.2.0 |stable |
Expand Down Expand Up @@ -45,7 +46,7 @@ Another decision made was limiting the plugin dependencies on other packages as
Requirements
------------

* CakePHP 3.4.0+
* CakePHP 3.6.0+
* PHP 5.6+

Documentation
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"source": "https://github.com/CakeDC/users"
},
"require": {
"cakephp/cakephp": "^3.5.0",
"cakephp/cakephp": "^3.6",
"cakedc/auth": "^2.0"
},
"require-dev": {
Expand Down
4 changes: 2 additions & 2 deletions config/bootstrap.php
Original file line number Diff line number Diff line change
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
5 changes: 2 additions & 3 deletions config/permissions.php
Original file line number Diff line number Diff line change
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 All @@ -50,7 +50,7 @@
*/

return [
'Users.SimpleRbac.permissions' => [
'CakeDC/Auth.permissions' => [
//admin role allowed to all the things
[
'role' => 'admin',
Expand Down Expand Up @@ -84,7 +84,6 @@
//all roles allowed to Pages/display
[
'role' => '*',
//'plugin' => null,
'controller' => 'Pages',
'action' => 'display',
],
Expand Down
6 changes: 3 additions & 3 deletions src/Auth/SocialAuthenticate.php
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
11 changes: 6 additions & 5 deletions src/Controller/Component/UsersAuthComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class UsersAuthComponent extends Component
const EVENT_BEFORE_LOGOUT = 'Users.Component.UsersAuth.beforeLogout';
const EVENT_AFTER_LOGOUT = 'Users.Component.UsersAuth.afterLogout';
const EVENT_BEFORE_SOCIAL_LOGIN_USER_CREATE = 'Users.Component.UsersAuth.beforeSocialLoginUserCreate';
const EVENT_AFTER_CHANGE_PASSWORD = 'Users.Component.UsersAuth.afterResetPassword';

/**
* Initialize method, setup Auth if not already done passing the $config provided and
Expand Down Expand Up @@ -116,8 +117,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 +151,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 +186,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 +221,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
13 changes: 9 additions & 4 deletions src/Controller/Traits/PasswordManagementTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace CakeDC\Users\Controller\Traits;

use CakeDC\Users\Controller\Component\UsersAuthComponent;
use CakeDC\Users\Exception\UserNotActiveException;
use CakeDC\Users\Exception\UserNotFoundException;
use CakeDC\Users\Exception\WrongPasswordException;
Expand Down Expand Up @@ -47,12 +48,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,11 +67,15 @@ 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);
if ($user) {
$event = $this->dispatchEvent(UsersAuthComponent::EVENT_AFTER_CHANGE_PASSWORD, ['user' => $user]);
if (!empty($event) && is_array($event->result)) {
return $this->redirect($event->result);
}
$this->Flash->success(__d('CakeDC/Users', 'Password has been changed successfully'));

return $this->redirect($redirect);
Expand Down Expand Up @@ -105,7 +110,7 @@ public function resetPassword($token = null)
/**
* Reset password
*
* @return void|\Cake\Network\Response
* @return void|\Cake\Http\Response
*/
public function requestResetPassword()
{
Expand Down
Loading

0 comments on commit 0dc1802

Please sign in to comment.