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));
 }
Esempio n. 2
0
 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();
 }
Esempio n. 3
0
 private function responseForbidden($propertyPath = '', $message = 'rtxlabs.user.validation.forbidden')
 {
     $error = array('propertyPath' => $propertyPath, 'message' => $message);
     return new Response(Dencoder::encode($error), '403');
 }