Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Docs/Documentation/Extending-the-Plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ Updating the Templates
Use the standard CakePHP conventions to override Plugin views using your application views
http://book.cakephp.org/3.0/en/plugins.html#overriding-plugin-templates-from-inside-your-application

`{project_dir}/src/Template/Plugin/CakeDC/Users/Users/{templates_in_here}`

Updating the Emails
-------------------

Expand Down
1 change: 1 addition & 0 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
5 changes: 5 additions & 0 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 @@ -71,6 +72,10 @@ public function changePassword()
} 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
39 changes: 37 additions & 2 deletions tests/TestCase/Controller/Traits/PasswordManagementTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

namespace CakeDC\Users\Test\TestCase\Controller\Traits;

use CakeDC\Users\Test\TestCase\Controller\Traits\BaseTraitTest;
use Cake\Auth\PasswordHasherFactory;
use Cake\Core\Configure;
use Cake\Event\Event;
use Cake\ORM\TableRegistry;
use Cake\TestSuite\TestCase;

Expand All @@ -27,7 +27,7 @@ class PasswordManagementTraitTest extends BaseTraitTest
public function setUp()
{
$this->traitClassName = 'CakeDC\Users\Controller\Traits\PasswordManagementTrait';
$this->traitMockMethods = ['set', 'redirect', 'validate', 'log'];
$this->traitMockMethods = ['set', 'redirect', 'validate', 'log', 'dispatchEvent'];
$this->mockDefaultEmail = true;
parent::setUp();
}
Expand Down Expand Up @@ -93,6 +93,41 @@ public function testChangePasswordWithError()
$this->Trait->changePassword();
}

/**
* test
*
* @return void
*/
public function testChangePasswordWithAfterChangeEvent()
{
$this->assertEquals('12345', $this->table->get('00000000-0000-0000-0000-000000000001')->password);
$this->_mockRequestPost();
$this->_mockAuthLoggedIn();
$this->_mockFlash();
$this->Trait->request->expects($this->once())
->method('getData')
->will($this->returnValue([
'password' => 'new',
'password_confirm' => 'new',
]));
$event = new Event('event');
$event->result = [
'action' => 'newAction',
];
$this->Trait->expects($this->once())
->method('dispatchEvent')
->will($this->returnValue($event));
$this->Trait->expects($this->once())
->method('redirect')
->with(['action' => 'newAction']);
$this->Trait->Flash->expects($this->any())
->method('success')
->with('Password has been changed successfully');
$this->Trait->changePassword();
$hasher = PasswordHasherFactory::build('Default');
$this->assertTrue($hasher->check('new', $this->table->get('00000000-0000-0000-0000-000000000001')->password));
}

/**
* test
*
Expand Down