0

I have written one extbase plugin, that creates the FE users from front end form.

The create action is something like this

/**
* action create
*
* @param \TYPO3\Usermanagement\Domain\Model\Users $newUsers
* @return void
*/
public function createAction(\TYPO3\Usermanagement\Domain\Model\Users $newUsers) {
    $this->usersRepository->add($newUsers);
}

Here I want to validate for same username or email already exists or not. How can I do this ? Any suggestions ? Thank you.

  • What about regular expressions and pure PHP? – Wipster Jun 28 '13 at 18:55
  • Also, you can write your own validator and refer to it in your model, something like "uniqueuser" . I'd put more details into an answer when I know more. I am creating one in our project right now. – Mateng Jun 30 '13 at 15:08

1 Answers1

1

You don't need to bind a $newUser as an action's param, instead you can just read some fields using $this->request->hasArgument('something') and $this->request->getArgument('something') to validate properties yourself, and create new user object manually like.

public function createAction() {
    $newUsers = new \TYPO3\Usermanagement\Domain\Model\Users();
    // do something with $newUsers object...
    $this->usersRepository->add($newUsers);
}

It will not throw an exception in case when there's no valid user object in the request, so it will allow you to handle form's error as you want/need.

It will also allow you to use some preprocessing before saving ie hashing/salting passwords.

biesior
  • 55,576
  • 10
  • 125
  • 182