private static function validateTask($TaskDTO, $user) { $violations = array(); if ($user == null) { $violations[] = ValidatorHelper::generateValidationError("memberEmail", sprintf('The user with the email \'%s\' doesn\'t exists', $TaskDTO->memberEmail)); } if ($TaskDTO->endDate < $TaskDTO->startDate) { $violations[] = ValidatorHelper::generateValidationError("endDate", "The end date cannot be before the start date."); } return $violations; }
/** * @return \FOS\RestBundle\View\View * * @param PostUserRequest $userDTO * * * @Post("/users") * * @Security("has_role('ROLE_MANAGER')") * * @ApiDoc( * description="Creates a new user", * input={ * "class"="cs221\APIBundle\DataTransferObject\PostUserRequest", * }, * output={ * "class"="cs221\APIBundle\DataTransferObject\GetUserResponse", * } * ) */ public function postUsersAction(PostUserRequest $userDTO) { $userRepository = $this->container->get('cs221_api.user.repository'); $serializer = $this->get('serializer'); if ($userRepository->get($userDTO->email) != null) { $serializer = $this->get('serializer'); $violation = ValidatorHelper::generateValidationError("email", sprintf('The user with the email \'%s\' already exists', $userDTO->email)); ValidatorHelper::handleValidationException($serializer, "json", new ConstraintViolationList(array($violation))); return; //throw new HttpException(500, sprintf('The user with the email \'%s\' already exists', $userDTO->email)); } $entity = new UserEntity($userDTO->email, $userDTO->fullName, $userDTO->isActive, $userDTO->isManager); $encoderService = $this->get('security.encoder_factory'); $encoder = $encoderService->getEncoder($entity); $hash = $encoder->encodePassword($userDTO->password, $entity->getSalt()); $entity->setPassword($hash); $entity = $userRepository->create($entity); return $this->entityToGetUserResponse($entity); }