0
votes

TYPO3-Version: 8.7.7

I want to access $this->request->getArguments() in a Validator for TYPO3 in PHP.

I set a temporary field in fluid with:

<label for="reenter_password" class="reenter_password{rm:hasError(property:'reenter_password',then:' text-danger')}">
    Reenter Password*
</label><br>
<f:form.password name="reenter_password" id="reenter_password"/>

If i set property instead of name in <f:form.password name="reenter_password" id="reenter_password"/> i get the following Error:

#1297759968: Exception while property mapping at property path "": Property "reenter_password" was not found in target object of type "RM\RmRegistration\Domain\Model\User".

I don't want to set a Model-Property, because this property should only use for checking with the passwortfield for equality and shouldn't get a TCA or SQL-Table for Storage.

Here is my Action, where i call the Validators:

/**
 * Complete New User Registeration
 *
 * @param User $newRegisteredUser
 * @validate $newRegisteredUser \RM\RmRegistration\Validation\Validator\NewRegisteredUser
 * @validate $newRegisteredUser \RM\RmRegistration\Validation\Validator\CompleteProfileUser
 */
public function completeNewRegisteredUserAction(User $newRegisteredUser)
{
    // Store Changes, Update and Persist
    $newRegisteredUser->setPassword($this->saltThisPassword($newRegisteredUser->getPassword()));
    $this->userRepository->update($newRegisteredUser);
    $this->objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager')->persistAll();
}

In the Validator i can get to the Password-Field with:

\TYPO3\CMS\Core\Utility\GeneralUtility::_POST()['tx_rmregistration_registration']['reenter_password']

But is it possible to get the Value temporary to the UserModel to check it in the Validator like this:

// Compare Entered Passwords
if ($user->getPassword() == $user->getReenteredPassword()) {
    return TRUE;
} else {
    return FALSE;
}
1

1 Answers

2
votes

Make an own (view) model for the password verification process or give the $newRegisteredUser a (transient or not) property for the reenterd password. Then use an own validator (see here).

class UserValidator extends \TYPO3\CMS\Extbase\Validation\Validator\AbstractValidator {

    /**
     * Object Manager
     *
     * @var \TYPO3\CMS\Extbase\Object\ObjectManager
     * @inject
     */
    protected $objectManager;

    /**
     * Is valid
     *
     * @param mixed $user
     * @return boolean
     */
    public function isValid($user) {
        if ($user->getPassword() !== $user->getPasswordConfirmation()) {
            $error = $this->objectManager->get(
                    'TYPO3\CMS\Extbase\Validation\Error',
                    'Password and password confirmation do not match.', time());
            $this->result->forProperty('passwordConfirmation')->addError($error);
            return FALSE;
        }
        return TRUE;
    }

}

And use in controller like this:

/**
 * action create
 *
 * @param \Vendor\Ext\Domain\Model\User $user
 * @validate $user \Vendor\Ext\Domain\Validator\UserValidator
 *
 * @return void
 */
public function createAction(\Vendor\Ext\Domain\Model\User $user) {

}