示例#1
0
 /**
  * The method to create user
  * 
  * @ApiDoc(
  *  description="Create new user",
  *  requirements={
  *      { "name"="api_key", "dataType"="string", "requirement"=".+", "description"="Api key" },
  *      { "name"="username", "dataType"="string", "requirement"=".+", "description"="Username" },
  *      { "name"="email", "dataType"="string", "requirement"="email parser", "description"="Email" },
  *      { "name"="password", "dataType"="string", "requirement"="password parser", "description"="Password" },
  *      { "name"="roles", "dataType"="array", "requirement"="array", "description"="Roles" },
  *      { "name"="_format", "dataType"="string", "requirement"="xml|json", "description"="Returned data format" },
  *  },
  * )
  */
 public function postUserAction(Request $request)
 {
     if (!$this->getApiEvent()->isHttpStatus(Response::HTTP_OK)) {
         return $this->send();
     }
     $username = Cleaner::String($request->get('username'));
     $email = Cleaner::String($request->get('email'));
     $plainPassword = Cleaner::String($request->get('password'));
     $roles = $request->get('roles');
     if (!$username || !$email || !$plainPassword) {
         $this->setHttpStatus(Response::HTTP_BAD_REQUEST);
         $this->setData(array('Bad data' => 'Please send username, email and password'));
     }
     /** @var $userManager \FOS\UserBundle\Model\UserManagerInterface */
     $userManager = $this->get('fos_user.user_manager');
     /* @var $guardUser GuardUser */
     $guardUser = $userManager->createUser();
     $guardUser->setEnabled(false);
     $guardUser->setUsername($username)->setEmail($email)->setPlainPassword($plainPassword);
     foreach ($roles as $role) {
         $guardUser->addRole($role);
     }
     if (!$guardUser->isValid($this->getDoctrine()->getManager())) {
         $this->setData($guardUser->getErrors());
         $this->setHttpStatus(Response::HTTP_NOT_FOUND);
         return $this->send();
     }
     $userManager->updateUser($guardUser);
     $this->setHttpStatus(Response::HTTP_CREATED);
     return $this->send();
 }
示例#2
0
 public function getNotaryCostsLabel($separator = '.')
 {
     return \Acme\Utils\Cleaner::GetPriceLabel($this->notaryCosts, $separator);
 }