public function registerAction() { $json = Dencoder::decode($this->getRequest()->getContent()); $userManager = $this->get('rtxlabs.user.user_manager'); $user = $userManager->findUserByEmail($json->email); if ($user instanceof User && $user->getDeletedAt() !== null) { $userManager->generateRegistrationToken($user); $userManager->saveUser($user); $this->get('rtxlabs.user.mailer')->sendReactivationEmailMessage($user); $response['success'] = false; $response['message'] = array('status' => 304); return new Response(Dencoder::encode($response)); } $user = $userManager->createUser(); $errors = $this->updateUser($user, $json, $userManager); if (!$json->tos) { $errors[] = array('propertyPath' => 'tos', 'message' => 'rtxlabs.user.tos'); } if (count($errors) > 0) { return new ValidationErrorResponse($errors); } $userManager->saveUser($user); $this->get('rtxlabs.user.mailer')->sendRegistrationEmailMessage($user); $userArray = $this->createUserBinder()->bind($user)->execute(); return new Response(Dencoder::encode($userArray)); }
protected function bindRequestData($group, $whitelist) { $data = Dencoder::decode($this->getRequest()->getContent()); $binder = $this->createDataBinder($this->whitelist)->bind($data)->to($group); if ($this->getCurrentUser()->isAdmin()) { $binder->field("roles", explode(",", $data->roles)); } else { $binder->except("roles"); } $binder->execute(); }
protected function findValidationErrors($entity) { $userManager = $this->get('rtxlabs.user.user_manager'); $data = Dencoder::decode($this->getRequest()->getContent()); $validator = $this->get('validator'); $errors = $validator->validate($entity); if ($data->passwordRequired && $data->plainPassword !== $data->passwordRepeat) { $errors[] = array('propertyPath' => 'passwordRepeat', 'message' => 'rtxlabs.user.validation.passwordRepeat'); } if ($data->passwordRequired && $entity->getPlainPassword() != $this->container->getParameter('password_placeholder') && $entity->getPlainPassword() != "" && !count($errors)) { $userManager->updatePassword($entity); } return $errors; }