/** * @Route("/test-json") */ public function testAction() { $user = new User(); $user->setUsername('test'); $user->setPhoneNumber('0627674523'); $object = new Demande(); $object->setDemandeur($user); /*return new JsonResponse(array( 'object' => $object ));*/ return $this->NTRender(array('object' => $object)); }
public function formatFriends(User $user) { $toRtn = array(); $friendsList = array_merge($user->getFriends()->toArray(), $user->getFriendsWithMe()->toArray()); $i = 0; foreach ($friendsList as $friend) { $toRtn[$i]["username"] = $friend->getUsername(); $toRtn[$i]["id"] = $friend->getId(); $i++; } return $toRtn; }
/** * @param $login * @param $password * @return \Symfony\Component\HttpFoundation\Response * * @Route("/register/{login}/{password}/{phone}/") */ public function registerAction($login, $password, $phone) { $em = $this->getDoctrine()->getManager(); $formatService = $this->get('server.format_service'); $fs = new Filesystem(); $user = new User(); $user->setUsername($login); $user->setPassword(password_hash($password, PASSWORD_BCRYPT)); $user->setPhoneNumber($formatService->formatPhone($phone)); try { $em->persist($user); $em->flush(); } catch (UniqueConstraintViolationException $e) { return $this->NTRender(array('response' => 0, 'message' => 'Utilisateur existant')); } $fs->mkdir('Files/Profil/' . $user->getId(), 0777); return $this->NTRender(array('response' => 1, 'message' => 'Inscription effectuée')); }