@@ -34,10 +34,10 @@ discard block |
||
| 34 | 34 | |
| 35 | 35 | class ProfileController extends AbstractController { |
| 36 | 36 | |
| 37 | - private EntityManagerInterface $entityManager; |
|
| 38 | - private AuthorizationCheckerInterface $authorizationChecker; |
|
| 39 | - private UserRepository $userRepository; |
|
| 40 | - private PaginatorInterface $paginator; |
|
| 37 | + private EntityManagerInterface $entityManager; |
|
| 38 | + private AuthorizationCheckerInterface $authorizationChecker; |
|
| 39 | + private UserRepository $userRepository; |
|
| 40 | + private PaginatorInterface $paginator; |
|
| 41 | 41 | |
| 42 | 42 | /** |
| 43 | 43 | * @param EntityManagerInterface $entityManager |
@@ -76,27 +76,27 @@ discard block |
||
| 76 | 76 | return new ResourcesListResponse($pagination); |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * @Route("/api/{version}/users/profile/{id}", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_user_get_user_profile") |
|
| 81 | - */ |
|
| 82 | - public function getAction($id) { |
|
| 79 | + /** |
|
| 80 | + * @Route("/api/{version}/users/profile/{id}", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_user_get_user_profile") |
|
| 81 | + */ |
|
| 82 | + public function getAction($id) { |
|
| 83 | 83 | $requestedUser = $this->userRepository->find($id); |
| 84 | 84 | if (!is_object($requestedUser) || !$requestedUser instanceof UserInterface) { |
| 85 | - throw new NotFoundHttpException('Requested user don\'t exists'); |
|
| 85 | + throw new NotFoundHttpException('Requested user don\'t exists'); |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | $this->checkIfCanAccess($requestedUser); |
| 89 | 89 | |
| 90 | 90 | return new SingleResourceResponse($requestedUser); |
| 91 | - } |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - /** |
|
| 94 | - * @Route("/api/{version}/users/profile/{id}", methods={"PATCH"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_user_edit_user_profile") |
|
| 95 | - */ |
|
| 96 | - public function editAction(Request $request, $id, UserPasswordEncoderInterface $passwordEncoder) { |
|
| 93 | + /** |
|
| 94 | + * @Route("/api/{version}/users/profile/{id}", methods={"PATCH"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_user_edit_user_profile") |
|
| 95 | + */ |
|
| 96 | + public function editAction(Request $request, $id, UserPasswordEncoderInterface $passwordEncoder) { |
|
| 97 | 97 | $requestedUser = $this->userRepository->find($id); |
| 98 | 98 | if (!is_object($requestedUser) || !$requestedUser instanceof UserInterface) { |
| 99 | - throw new NotFoundHttpException('Requested user don\'t exists'); |
|
| 99 | + throw new NotFoundHttpException('Requested user don\'t exists'); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | $this->checkIfCanAccess($requestedUser); |
@@ -107,32 +107,32 @@ discard block |
||
| 107 | 107 | $form->handleRequest($request); |
| 108 | 108 | |
| 109 | 109 | if ($form->isSubmitted() && $form->isValid()) { |
| 110 | - if (!empty($form->get('plainPassword')->getData())) { |
|
| 110 | + if (!empty($form->get('plainPassword')->getData())) { |
|
| 111 | 111 | $requestedUser->setPassword( |
| 112 | 112 | $passwordEncoder->encodePassword( |
| 113 | 113 | $requestedUser, |
| 114 | 114 | $form->get('plainPassword')->getData() |
| 115 | 115 | ) |
| 116 | 116 | ); |
| 117 | - } |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | - $entityManager = $this->entityManager; |
|
| 120 | - $entityManager->flush(); |
|
| 119 | + $entityManager = $this->entityManager; |
|
| 120 | + $entityManager->flush(); |
|
| 121 | 121 | |
| 122 | - return new SingleResourceResponse($requestedUser); |
|
| 122 | + return new SingleResourceResponse($requestedUser); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | return new SingleResourceResponse($form, new ResponseContext(400)); |
| 126 | - } |
|
| 126 | + } |
|
| 127 | 127 | |
| 128 | - private function checkIfCanAccess($requestedUser) { |
|
| 128 | + private function checkIfCanAccess($requestedUser) { |
|
| 129 | 129 | /** @var UserInterface $currentUser */ |
| 130 | 130 | $currentUser = $this->getUser(); |
| 131 | 131 | if ( |
| 132 | 132 | !$this->authorizationChecker->isGranted('ROLE_ADMIN') && |
| 133 | 133 | $requestedUser->getId() !== $currentUser->getId() |
| 134 | 134 | ) { |
| 135 | - throw new AccessDeniedException('This user does not have access to this section. profile'); |
|
| 135 | + throw new AccessDeniedException('This user does not have access to this section. profile'); |
|
| 136 | + } |
|
| 136 | 137 | } |
| 137 | - } |
|
| 138 | 138 | } |
@@ -65,8 +65,8 @@ |
||
| 65 | 65 | throw new AccessDeniedException('This user does not have access to this section.'); |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | - $limit = (int)$request->query->get('limit', 10); |
|
| 69 | - $page = (int)$request->query->get('page', 1); |
|
| 68 | + $limit = (int) $request->query->get('limit', 10); |
|
| 69 | + $page = (int) $request->query->get('page', 1); |
|
| 70 | 70 | $profilesQuery = $this->userRepository->createQueryBuilder('u') |
| 71 | 71 | ->orderBy('u.id', 'ASC') |
| 72 | 72 | ->getQuery(); |