/** * Builds a new user and validates it. * * @param CreateUserDTO $userParameters * * @return mixed[] */ private function buildAndValidateUserModelByDTO(CreateUserDTO $userParameters) { $violations = $this->validator->validate($userParameters); if (count($violations) > 0) { return ['valid' => false, 'violations' => $violations]; } $newUser = User::create($userParameters->getUsername(), $this->hasher->generateHash($userParameters->getPassword()), $userParameters->getEmail()); $newUser->setLocale($userParameters->getLocale()); $newUser->setActivationKey($this->getUniqueActivationKey()); return ['valid' => true, 'user' => $newUser]; }
/** * Set password. * * @param string $password * @param PasswordHasherInterface $passwordHasher * @param string|null $old * * @throws \InvalidArgumentException If the update fails. * * @return User */ public function setOrUpdatePassword(string $password, PasswordHasherInterface $passwordHasher, string $old = null) : self { if ($this->password && !$passwordHasher->compareWith($this->password, $old)) { throw new \InvalidArgumentException('Old password is invalid, but must be given to change it!'); } $this->password = $passwordHasher->generateHash($password); return $this; }