/**
  * @Rest\Post("/create")
  * @return User
  */
 public function createAction(Request $request)
 {
     $account = $this->getAccount();
     $user = new User();
     $user->setUsername($request->request->get('username'));
     $user->setPlainPassword($request->request->get('password'));
     $user->setEmail($request->request->get('email'));
     $user->setEnabled(true);
     $user->setAccount($account);
     /** @var UserManager $manager */
     $manager = $this->get('cowtent.account.user.manager');
     $manager->updateCanonicalFields($user);
     $manager->updatePassword($user);
     $em = $this->getDoctrine()->getManager();
     $em->persist($user);
     $em->flush();
     return $user;
 }
 /**
  * @Rest\Post("/add")
  * @return bool
  */
 public function addAction(Request $request)
 {
     try {
         $account = $this->getAccount();
         $user = new User();
         $user->setUsername($request->request->get('username'));
         $user->setPlainPassword($request->request->get('password'));
         $user->setEmail($request->request->get('email'));
         $user->setEnabled(TRUE);
         $user->setAccount($account);
         /** @var UserManager $manager */
         $manager = $this->get('cowtent.account.user.manager');
         $manager->updateCanonicalFields($user);
         $manager->updatePassword($user);
         $em = $this->getDoctrine()->getManager();
         $em->persist($user);
         $em->flush();
         return $user;
     } catch (\Exception $e) {
         return array(get_class($e), $e->getCode(), $e->getMessage());
     }
 }
Esempio n. 3
0
 /**
  * @param User $user
  */
 public function updateCanonicalFields(User $user)
 {
     $user->setUsernameCanonical($this->canonicalizeUsername($user->getUsername()));
     $user->setEmailCanonical($this->canonicalizeEmail($user->getEmail()));
 }