Skip to content
This repository has been archived by the owner on Jan 15, 2021. It is now read-only.

Commit

Permalink
Use appropriate flashes for success/error
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Krämer committed Feb 16, 2016
1 parent 5556ee3 commit 04c6553
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/Controller/Component/UserToolComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ protected function _afterLogin($user, array $options) {
public function login($options = []) {
$options = Hash::merge($this->config('login'), $options);
$this->_handleUserBeingAlreadyLoggedIn($options);
$entity = $this->UserTable->newEntity([], ['validate' => false]);
$entity = $this->UserTable->newEntity(null, ['validate' => false]);
if ($this->request->is('post')) {
$user = $this->_beforeLogin($entity, $options);
if ($user) {
Expand Down Expand Up @@ -623,7 +623,7 @@ public function verifyEmailToken($options = []) {
*/
public function requestPassword($options = []) {
$options = Hash::merge($this->config('requestPassword'), $options);
$entity = $this->UserTable->newEntity(['validate' => 'requestPassword']);
$entity = $this->UserTable->newEntity(null, ['validate' => 'requestPassword']);

if ($this->request->is('post')) {
$entity = $this->UserTable->patchEntity($entity, $this->request->data, ['validate' => 'requestPassword']);
Expand All @@ -641,12 +641,20 @@ public function requestPassword($options = []) {
unset($this->request->data[$options['field']]);
return false;
}

if ($options['setEntity']) {
$this->_controller->set('userEntity', $entity);
}
}

protected function _initPasswordReset($entity, $options) {
/**
* Initializes the password reset and handles a possible errors.
*
* @param \Cake\Datasource\EntityInterface
* @param array $options Options array
* @return bool
*/
protected function _initPasswordReset(Entity $entity, $options) {
try {
$this->UserTable->initPasswordReset($this->request->data[$options['field']]);
$this->handleFlashAndRedirect('success', $options);
Expand Down Expand Up @@ -810,7 +818,7 @@ protected function _handleFlash($type, $options) {
if (isset($options[$type . 'FlashOptions'])) {
$flashOptions = $options[$type . 'FlashOptions'];
}
$this->Flash->set($options[$type . 'Message'], $flashOptions);
$this->Flash->$type($options[$type . 'Message'], $flashOptions);
return true;
}
}
Expand Down

0 comments on commit 04c6553

Please sign in to comment.