/** * Let the logged in user change his password. * * @param array $options * @return void */ public function changePassword($options = []) { $options = Hash::merge($this->_defaultConfig['changePassword'], $options); $entity = $this->UserTable->newEntity(); $entity->accessible(['id', 'old_password', 'new_password', 'confirm_password'], true); if ($this->request->is(['post', 'put'])) { $entity = $this->UserTable->patchEntity($entity, $this->request->data); $entity->id = $this->_controller->Auth->user('id'); $entity->isNew(false); if ($this->UserTable->changePassword($entity)) { $this->request->data = []; $entity = $this->UserTable->newEntity(); $entity->id = $this->_controller->Auth->user('id'); $entity->isNew(false); $this->handleFlashAndRedirect('success', $options); } else { $this->handleFlashAndRedirect('error', $options); } } $this->_controller->set('entity', $entity); }