1 | <?php |
||
21 | class UserController extends BaseController |
||
22 | { |
||
23 | /** |
||
24 | * Registration |
||
25 | * |
||
26 | * @Route("/api/users", methods={"POST"}) |
||
27 | * @param RegisterUserRequest $request |
||
28 | * @param RegisterService $registerService |
||
29 | * @param EventDispatcherInterface $dispatcher |
||
30 | * @param ValidatorInterface $validator |
||
31 | * @return JsonResponse|\Symfony\Component\HttpFoundation\Response |
||
32 | */ |
||
33 | 3 | public function postUsers(RegisterUserRequest $request, RegisterService $registerService, EventDispatcherInterface $dispatcher, ValidatorInterface $validator) |
|
34 | { |
||
35 | 3 | $this->denyAccessUnlessGranted('IS_AUTHENTICATED_ANONYMOUSLY'); // todo (not working) |
|
36 | |||
37 | 3 | $registeredUser = $registerService->registerByRequest($request); |
|
38 | 3 | $errors = $validator->validate($registeredUser); |
|
39 | |||
40 | 3 | if ($errors && 0 !== $errors->count()) { |
|
41 | 1 | return $request->getErrorResponse($errors); |
|
42 | } |
||
43 | |||
44 | 2 | $em = $this->getDoctrine()->getManager(); |
|
45 | 2 | $em->persist($registeredUser); |
|
46 | 2 | $em->flush(); |
|
47 | |||
48 | 2 | $userRegisteredEvent = new UserRegisteredEvent($registeredUser); |
|
49 | 2 | $dispatcher->dispatch(UserRegisteredEvent::NAME, $userRegisteredEvent); |
|
50 | |||
51 | 2 | return $this->response($registeredUser, 200, [], [ |
|
52 | 2 | 'groups' => ['view'], |
|
53 | ]); |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * Confirm email |
||
58 | * |
||
59 | * @Route("/api/confirmEmail", methods={"POST"}) |
||
60 | * @param ConfirmEmailRequest $request |
||
61 | * @param ConfirmationTokenRepository $confirmationTokenRepository |
||
62 | * @param TranslatorInterface $translator |
||
63 | * @return JsonResponse |
||
64 | */ |
||
65 | 2 | public function postConfirmEmail(ConfirmEmailRequest $request, ConfirmationTokenRepository $confirmationTokenRepository, TranslatorInterface $translator) |
|
85 | |||
86 | /** |
||
87 | * Get single user |
||
88 | * |
||
89 | * @Route("/api/users/{id}", methods={"GET"}) |
||
90 | * @param $id |
||
91 | * @param TranslatorInterface $translator |
||
92 | * @return JsonResponse |
||
93 | */ |
||
94 | 3 | public function getUsers($id, TranslatorInterface $translator) |
|
112 | |||
113 | /** |
||
114 | * Get all users |
||
115 | * |
||
116 | * @Route("/api/users", methods={"GET"}) |
||
117 | */ |
||
118 | 3 | public function getAll() |
|
132 | } |