Skip to content

Commit

Permalink
Support CakePHP 3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
Cheren committed May 22, 2018
1 parent f9bacd8 commit 4c4c7fa
Show file tree
Hide file tree
Showing 22 changed files with 350 additions and 71 deletions.
8 changes: 8 additions & 0 deletions src/Controller/Admin/GroupsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class GroupsController extends AppController
* @return mixed
*
* @throws RolledbackTransactionException
* @throws \Aura\Intl\Exception
*/
public function add()
{
Expand Down Expand Up @@ -82,6 +83,7 @@ public function down($id)
* @throws RecordNotFoundException
* @throws InvalidPrimaryKeyException
* @throws RolledbackTransactionException
* @throws \Aura\Intl\Exception
*/
public function edit($id)
{
Expand All @@ -108,6 +110,8 @@ public function edit($id)
* Index action.
*
* @return void
*
* @throws \Aura\Intl\Exception
*/
public function index()
{
Expand All @@ -120,6 +124,8 @@ public function index()
*
* @return void
*
* @throws \Aura\Intl\Exception
* @throws \JBZoo\Utils\Exception
* @throws \Cake\Core\Exception\Exception When trying to set a key that is invalid.
*/
public function initialize()
Expand All @@ -136,6 +142,8 @@ public function initialize()
* Process action.
*
* @return \Cake\Http\Response|null
*
* @throws \Aura\Intl\Exception
*/
public function process()
{
Expand Down
9 changes: 9 additions & 0 deletions src/Controller/Admin/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class UsersController extends AppController
*
* @return \Cake\Http\Response|null
*
* @throws \Aura\Intl\Exception
* @throws \Cake\ORM\Exception\RolledbackTransactionException
*/
public function add()
Expand Down Expand Up @@ -76,6 +77,8 @@ public function add()
*
* @param null|int $id User id.
* @return \Cake\Http\Response|null
*
* @throws \Aura\Intl\Exception
*/
public function changePassword($id = null)
{
Expand Down Expand Up @@ -103,6 +106,7 @@ public function changePassword($id = null)
* @param null|int $id User id.
* @return \Cake\Http\Response|null
*
* @throws \Aura\Intl\Exception
* @throws RecordNotFoundException
* @throws InvalidPrimaryKeyException
* @throws RolledbackTransactionException
Expand Down Expand Up @@ -138,6 +142,7 @@ public function edit($id = null)
*
* @return void
*
* @throws \Aura\Intl\Exception
* @throws \RuntimeException
*/
public function index()
Expand Down Expand Up @@ -169,6 +174,8 @@ public function initialize()
* Login action.
*
* @return \Cake\Http\Response|null
*
* @throws \Aura\Intl\Exception
*/
public function login()
{
Expand Down Expand Up @@ -200,6 +207,8 @@ public function logout()
* Process action.
*
* @return \Cake\Http\Response|null
*
* @throws \Aura\Intl\Exception
*/
public function process()
{
Expand Down
8 changes: 5 additions & 3 deletions src/Controller/Component/AuthComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,20 @@ protected function _getLoginRedirect()
* Sets defaults for configs.
*
* @return void
*
* @throws \Aura\Intl\Exception
*/
protected function _setDefaults()
{
$defaults = [
'authenticate' => [
'Form' => [
'userModel' => 'Users',
'scope' => ['Users.status' => 1],
'finder' => 'auth',
'userModel' => 'Community.Users',
'fields' => [
'username' => 'login',
'password' => 'password'
]
],
]
],
'flash' => [
Expand Down
8 changes: 6 additions & 2 deletions src/Controller/Component/UserComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ public function implementedEvents()
/**
* Startup callback.
*
* @param Event $event
* @param Event $event
*
* @throws \Aura\Intl\Exception
*/
public function startup(Event $event)
{
Expand All @@ -55,7 +57,9 @@ public function startup(Event $event)
/**
* Setup profile nav bar for admin.
*
* @return void
* @return void
*
* @throws \Aura\Intl\Exception
*/
protected function _setupAdminProfileNavBar()
{
Expand Down
17 changes: 13 additions & 4 deletions src/Controller/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use Core\Event\EventManager;
use Community\Model\Entity\User;
use Community\Model\Table\UsersTable;
use Cake\Network\Exception\BadRequestException;

/**
* Class UsersController
Expand All @@ -32,7 +31,9 @@ class UsersController extends AppController
/**
* Default profile page action.
*
* @return void
* @return void
*
* @throws \Aura\Intl\Exception
*/
public function profile()
{
Expand All @@ -53,13 +54,16 @@ public function profile()
* @param null|int $id User id.
* @param null|string $token User activation token.
* @return \Cake\Http\Response|null
*
* @throws \Aura\Intl\Exception
*/
public function activate($id = null, $token = null)
{
$user = $this->_getUser($id, $token);

if ($user === null) {
throw new BadRequestException(__d('community', 'User was not found'));
$this->Flash->error(__d('community', 'User was not found'));
return $this->redirect(['action' => 'login']);
}

if ($user->status) {
Expand Down Expand Up @@ -97,6 +101,8 @@ public function activate($id = null, $token = null)
* Login action.
*
* @return \Cake\Http\Response|null
*
* @throws \Aura\Intl\Exception
*/
public function login()
{
Expand Down Expand Up @@ -129,13 +135,16 @@ public function logout()
* @param null|int $id User id.
* @param null|string $token User activation token.
* @return \Cake\Http\Response|null
*
* @throws \Aura\Intl\Exception
*/
public function setupPassword($id = null, $token = null)
{
$user = $this->_getUser($id, $token);

if ($user === null) {
throw new BadRequestException(__d('community', 'User was not found'));
$this->Flash->error(__d('community', 'User was not found'));
return $this->redirect(['action' => 'login']);
}

if ($this->request->is(['patch', 'post', 'put'])) {
Expand Down
14 changes: 7 additions & 7 deletions src/Model/Entity/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
/**
* Class Group
*
* @package Community\Model\Entity
* @package Community\Model\Entity
*
* @property int $id
* @property null|int $parent_id
* @property string $name
* @property string $slug
* @property int $lft
* @property int $rght
* @property int $id
* @property null|int $parent_id
* @property string $name
* @property string $slug
* @property int $lft
* @property int $rght
*/
class Group extends Entity
{
Expand Down
32 changes: 16 additions & 16 deletions src/Model/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,23 @@
/**
* Class User
*
* @package Community\Model\Entity
* @package Community\Model\Entity
*
* @property int $id
* @property int $group_id
* @property Group $group
* @property string $login
* @property string $name
* @property string $slug
* @property string $email
* @property string $password
* @property string $token
* @property bool $status
* @property FrozenTime $last_login
* @property FrozenTime $last_action
* @property FrozenTime $modified
* @property FrozenTime $created
* @property string activation_url Virtual field.
* @property int $id
* @property int $group_id
* @property Group $group
* @property string $login
* @property string $name
* @property string $slug
* @property string $email
* @property string $password
* @property string $token
* @property bool $status
* @property FrozenTime $last_login
* @property FrozenTime $last_action
* @property FrozenTime $modified
* @property FrozenTime $created
* @property string activation_url Virtual field.
*/
class User extends Entity
{
Expand Down
4 changes: 3 additions & 1 deletion src/Model/Table/GroupsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ public function initialize(array $config)
*
* @param Validator $validator The validator that can be modified to add some rules to it.
* @return Validator
*
* @throws \Aura\Intl\Exception
*/
public function validationDefault(Validator $validator)
{
Expand All @@ -100,7 +102,7 @@ public function validationDefault(Validator $validator)
->add('slug', 'unique', [
'message' => __d('community', 'Group with this slug already exists.'),
'rule' => 'validateUnique',
'provider' => 'table',
'provider' => 'table'
]);

return $validator;
Expand Down
16 changes: 16 additions & 0 deletions src/Model/Table/UsersTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

namespace Community\Model\Table;

use Cake\ORM\Query;
use Core\ORM\Table;
use Core\Event\EventManager;
use Cake\Validation\Validator;
Expand Down Expand Up @@ -93,6 +94,8 @@ public function save(EntityInterface $entity, $options = [])
*
* @param Validator $validator The validator that can be modified to add some rules to it.
* @return Validator
*
* @throws \Aura\Intl\Exception
*/
public function validationDefault(Validator $validator)
{
Expand Down Expand Up @@ -155,4 +158,17 @@ public function validationDefault(Validator $validator)

return $validator;
}

/**
* Find auth user.
*
* @param Query $query
* @param array $options
*
* @return \Cake\ORM\Query
*/
public function findAuth(Query $query, array $options)
{
return $query->where(['Users.status' => 1]);
}
}
14 changes: 14 additions & 0 deletions tests/App/config/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
/**
* CakeCMS Community
*
* This file is part of the of the simple cms based on CakePHP 3.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @package Community
* @license MIT
* @copyright MIT License http://www.opensource.org/licenses/mit-license.php
* @link https://github.com/CakeCMS/Community".
* @author Sergey Kalistratov <kalistratov.s.m@gmail.com>
*/
27 changes: 27 additions & 0 deletions tests/App/src/Application.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
/**
* CakeCMS Community
*
* This file is part of the of the simple cms based on CakePHP 3.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @package Community
* @license MIT
* @copyright MIT License http://www.opensource.org/licenses/mit-license.php
* @link https://github.com/CakeCMS/Community".
* @author Sergey Kalistratov <kalistratov.s.m@gmail.com>
*/

namespace Test\App;

use Core\Application as CoreApplication;

/**
* Class Application
*
* @package Test\App
*/
class Application extends CoreApplication
{
}

0 comments on commit 4c4c7fa

Please sign in to comment.