src/Controller/Component/UserToolComponent.php
public function resetPassword($token = null, $options = []) {
		$options = Hash::merge($this->getConfig('resetPassword'), $options);

		$tokenParam = $this->_getRequest()->getQuery($options['queryParam']);
		if (!empty($tokenParam)) {
			$token = $tokenParam;
		}

		// Check of the token exists
		try {
			$entity = $this->UserTable->verifyPasswordResetToken($token, $options['tokenOptions']);
		} catch (RecordNotFoundException $e) {
			if (empty($options['errorMessage']) && $options['errorMessage'] !== false) {
				$options['errorMessage'] = $e->getMessage();
			}

			$redirect = $this->handleFlashAndRedirect('invalidError', $options);
			if ($redirect instanceof Response) {
				return $redirect;
			}
			$entity = $this->UserTable->newEntity();
		}

		// Check if the token has expired
		if ($entity->get('token_is_expired') === true) {
			if (empty($options['invalidErrorMessage'])) {
				$options['invalidErrorMessage'] = $e->getMessage();
			}
			$redirect = $this->handleFlashAndRedirect('expiredError', $options);
			if ($redirect instanceof Response) {
				return $redirect;
			}
		}

		// Handle the POST
		if ($this->_getRequest()->is('post')) {
			$entity = $this->UserTable->patchEntity($entity, $this->_getRequest()->getData());
			if ($this->UserTable->resetPassword($entity)) {
				$redirect = $this->handleFlashAndRedirect('success', $options);
			} else {
				$redirect = $this->handleFlashAndRedirect('error', $options);
			}
			if ($redirect instanceof Response) {
				return $redirect;
			}
		} else {
			$entity = $this->UserTable->newEntity();
		}

		$this->_setViewVar('entity', $entity);
	}
public function resetPassword($token = null, $options = []) {
		$options = Hash::merge($this->getConfig('resetPassword'), $options);

		$tokenParam = $this->_getRequest()->getQuery($options['queryParam']);
		if (!empty($tokenParam)) {
			$token = $tokenParam;
		}

		// Check of the token exists
		try {
			$entity = $this->UserTable->verifyPasswordResetToken($token, $options['tokenOptions']);
		} catch (RecordNotFoundException $e) {
			if (empty($options['errorMessage']) && $options['errorMessage'] !== false) {
				$options['errorMessage'] = $e->getMessage();
			}

			$redirect = $this->handleFlashAndRedirect('invalidError', $options);
			if ($redirect instanceof Response) {
				return $redirect;
			}
			$entity = $this->UserTable->newEntity();
		}

		// Check if the token has expired
		if ($entity->get('token_is_expired') === true) {
			if (empty($options['invalidErrorMessage'])) {
				$options['invalidErrorMessage'] = $e->getMessage();
			}
			$redirect = $this->handleFlashAndRedirect('expiredError', $options);
			if ($redirect instanceof Response) {
				return $redirect;
			}
		}

		// Handle the POST
		if ($this->_getRequest()->is('post')) {
			$entity = $this->UserTable->patchEntity($entity, $this->_getRequest()->getData());
			if ($this->UserTable->resetPassword($entity)) {
				$redirect = $this->handleFlashAndRedirect('success', $options);
			} else {
				$redirect = $this->handleFlashAndRedirect('error', $options);
			}
			if ($redirect instanceof Response) {
				return $redirect;
			}
		} else {
			$entity = $this->UserTable->newEntity();
		}

		$this->_setViewVar('entity', $entity);
	}
public function resetPassword ( $ token = null , $ options = [ ] ) { $ options = Hash :: merge ( $ this -> getConfig ( 'resetPassword' ) , $ options ) ; $ tokenParam = $ this -> _getRequest ( ) -> getQuery ( $ options [ 'queryParam' ] ) ; if ( ! empty ( $ tokenParam ) ) { $ token = $ tokenParam ; } // Check of the token exists try { $ entity = $ this -> UserTable -> verifyPasswordResetToken ( $ token , $ options [ 'tokenOptions' ] ) ; } catch ( RecordNotFoundException $ e ) { if ( empty ( $ options [ 'errorMessage' ] ) && $ options [ 'errorMessage' ] !== false ) { $ options [ 'errorMessage' ] = $ e -> getMessage ( ) ; } $ redirect = $ this -> handleFlashAndRedirect ( 'invalidError' , $ options ) ; if ( $ redirect instanceof Response ) { return $ redirect ; } $ entity = $ this -> UserTable -> newEntity ( ) ; } // Check if the token has expired if ( $ entity -> get ( 'token_is_expired' ) === true ) { if ( empty ( $ options [ 'invalidErrorMessage' ] ) ) { $ options [ 'invalidErrorMessage' ] = $ e -> getMessage ( ) ; } $ redirect = $ this -> handleFlashAndRedirect ( 'expiredError' , $ options ) ; if ( $ redirect instanceof Response ) { return $ redirect ; } } // Handle the POST if ( $ this -> _getRequest ( ) -> is ( 'post' ) ) { $ entity = $ this -> UserTable -> patchEntity ( $ entity , $ this -> _getRequest ( ) -> getData ( ) ) ; if ( $ this -> UserTable -> resetPassword ( $ entity ) ) { $ redirect = $ this -> handleFlashAndRedirect ( 'success' , $ options ) ; } else { $ redirect = $ this -> handleFlashAndRedirect ( 'error' , $ options ) ; } if ( $ redirect instanceof Response ) { return $ redirect ; } } else { $ entity = $ this -> UserTable -> newEntity ( ) ; } $ this -> _setViewVar ( 'entity' , $ entity ) ; }
Allows the user to enter a new password.

@param string|null $token Token
@param array $options Options
@return null|\Cake\Http\Response
Allows the user to enter a new password .