/** * User registration * * Options: * * - `enabled` Disables/enables the registration. If false a NotFoundException is thrown. Default true. * - `successMessage` The success flash message. * - `successRedirectUrl` Success redirect url. Default /. * - `errorMessage` The error flash message. * - `errorRedirectUrl` The error redirect url. * - `setEntity` Set the entity to the view or not, default is true. * * @throws \Cake\Error\NotFoundException * @param array $options * @return boolean|null */ public function register($options = []) { $options = Hash::merge($this->_config['registration'], $options); if ($options['enabled'] === false) { throw new NotFoundException(); } $entity = $this->UserTable->newEntity(); // Make the field accessible in the case the default entity class is used. $entity->accessible('confirm_password', true); if ($this->request->is('post')) { $entity = $this->UserTable->patchEntity($entity, $this->request->data()); if ($this->UserTable->register($entity)) { $this->handleFlashAndRedirect('success', $options); if ($options['setEntity'] === true) { $this->_controller->set('usersEntity', $entity); } return true; } else { $this->handleFlashAndRedirect('error', $options); if ($options['setEntity'] === true) { $this->_controller->set('usersEntity', $entity); } return false; } } if ($options['setEntity'] === true) { $this->_controller->set('userEntity', $entity); // BC $this->_controller->set('usersEntity', $entity); } }
/** * User registration * * Options: * * - `enabled` Disables/enables the registration. If false a NotFoundException is thrown. Default true. * - `successMessage` The success flash message. * - `successRedirectUrl` Success redirect url. Default /. * - `errorMessage` The error flash message. * - `errorRedirectUrl` The error redirect url. * - `setEntity` Set the entity to the view or not, default is true. * * @throws \Cake\Error\NotFoundException * @param array $options * @return boolean|null */ public function register($options = []) { $options = Hash::merge($this->config('registration'), $options); if ($options['enabled'] === false) { throw new NotFoundException(); } $return = false; $entity = $this->UserTable->newEntity(); // Make the field accessible in the case the default entity class is used. $entity->accessible('confirm_password', true); if ($this->request->is('post')) { $entity = $this->UserTable->patchEntity($entity, $this->request->data(), ['validate' => $options['validation']]); if ($this->UserTable->register($entity)) { $this->handleFlashAndRedirect('success', $options); $return = true; } else { $this->handleFlashAndRedirect('error', $options); } } if ($options['setEntity'] === true) { $this->_setViewVar('userEntity', $entity); // For backward compatibility $this->_setViewVar('usersEntity', $entity); } return $return; }