@@ -9,25 +9,25 @@ discard block |
||
| 9 | 9 | |
| 10 | 10 | class UserService |
| 11 | 11 | { |
| 12 | - public function __construct(private EntityManagerInterface $manager, private UserPasswordEncoderInterface $encoder) {} |
|
| 13 | - public function changePassword(User $user, $password) |
|
| 14 | - { |
|
| 12 | + public function __construct(private EntityManagerInterface $manager, private UserPasswordEncoderInterface $encoder) {} |
|
| 13 | + public function changePassword(User $user, $password) |
|
| 14 | + { |
|
| 15 | 15 | if (!$this->getPermission()) |
| 16 | - throw new Exception("You should not pass!!!", 301); |
|
| 16 | + throw new Exception("You should not pass!!!", 301); |
|
| 17 | 17 | |
| 18 | 18 | $user->setHash( |
| 19 | - $this->encoder->encodePassword($user, $password) |
|
| 19 | + $this->encoder->encodePassword($user, $password) |
|
| 20 | 20 | ); |
| 21 | 21 | |
| 22 | 22 | $this->manager->persist($user); |
| 23 | 23 | $this->manager->flush(); |
| 24 | 24 | return $user; |
| 25 | - } |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - public function createUser($people_id, $username, $password) |
|
| 28 | - { |
|
| 27 | + public function createUser($people_id, $username, $password) |
|
| 28 | + { |
|
| 29 | 29 | if (!$this->getPermission()) |
| 30 | - throw new Exception("You should not pass!!!", 301); |
|
| 30 | + throw new Exception("You should not pass!!!", 301); |
|
| 31 | 31 | |
| 32 | 32 | $user = new User(); |
| 33 | 33 | $user->setPeople($this->manager->getRepository(User::class)->find($people_id)); |
@@ -37,13 +37,13 @@ discard block |
||
| 37 | 37 | $this->manager->persist($user); |
| 38 | 38 | $this->manager->flush(); |
| 39 | 39 | return $user; |
| 40 | - } |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @todo arrumar |
|
| 44 | - */ |
|
| 45 | - private function getPermission() |
|
| 46 | - { |
|
| 42 | + /** |
|
| 43 | + * @todo arrumar |
|
| 44 | + */ |
|
| 45 | + private function getPermission() |
|
| 46 | + { |
|
| 47 | 47 | return true; |
| 48 | - } |
|
| 48 | + } |
|
| 49 | 49 | } |
@@ -12,8 +12,9 @@ discard block |
||
| 12 | 12 | public function __construct(private EntityManagerInterface $manager, private UserPasswordEncoderInterface $encoder) {} |
| 13 | 13 | public function changePassword(User $user, $password) |
| 14 | 14 | { |
| 15 | - if (!$this->getPermission()) |
|
| 16 | - throw new Exception("You should not pass!!!", 301); |
|
| 15 | + if (!$this->getPermission()) { |
|
| 16 | + throw new Exception("You should not pass!!!", 301); |
|
| 17 | + } |
|
| 17 | 18 | |
| 18 | 19 | $user->setHash( |
| 19 | 20 | $this->encoder->encodePassword($user, $password) |
@@ -26,8 +27,9 @@ discard block |
||
| 26 | 27 | |
| 27 | 28 | public function createUser($people_id, $username, $password) |
| 28 | 29 | { |
| 29 | - if (!$this->getPermission()) |
|
| 30 | - throw new Exception("You should not pass!!!", 301); |
|
| 30 | + if (!$this->getPermission()) { |
|
| 31 | + throw new Exception("You should not pass!!!", 301); |
|
| 32 | + } |
|
| 31 | 33 | |
| 32 | 34 | $user = new User(); |
| 33 | 35 | $user->setPeople($this->manager->getRepository(User::class)->find($people_id)); |
@@ -11,35 +11,35 @@ |
||
| 11 | 11 | class CreateUserAction |
| 12 | 12 | { |
| 13 | 13 | |
| 14 | - public function __construct( |
|
| 14 | + public function __construct( |
|
| 15 | 15 | private EntityManagerInterface $manager, |
| 16 | 16 | private UserService $service, |
| 17 | 17 | private HydratorService $hydratorService |
| 18 | 18 | |
| 19 | - ) {} |
|
| 19 | + ) {} |
|
| 20 | 20 | |
| 21 | - public function __invoke(Request $request) |
|
| 22 | - { |
|
| 21 | + public function __invoke(Request $request) |
|
| 22 | + { |
|
| 23 | 23 | |
| 24 | 24 | try { |
| 25 | - $payload = json_decode($request->getContent()); |
|
| 26 | - return new JsonResponse($this->hydratorService->result( |
|
| 25 | + $payload = json_decode($request->getContent()); |
|
| 26 | + return new JsonResponse($this->hydratorService->result( |
|
| 27 | 27 | $this->service->createUser( |
| 28 | - $payload->people, |
|
| 29 | - $payload->username, |
|
| 30 | - $payload->password |
|
| 28 | + $payload->people, |
|
| 29 | + $payload->username, |
|
| 30 | + $payload->password |
|
| 31 | 31 | ) |
| 32 | - )); |
|
| 32 | + )); |
|
| 33 | 33 | } catch (\Exception $e) { |
| 34 | 34 | |
| 35 | - return new JsonResponse([ |
|
| 35 | + return new JsonResponse([ |
|
| 36 | 36 | 'response' => [ |
| 37 | - 'data' => [], |
|
| 38 | - 'count' => 0, |
|
| 39 | - 'error' => $e->getMessage(), |
|
| 40 | - 'success' => false, |
|
| 37 | + 'data' => [], |
|
| 38 | + 'count' => 0, |
|
| 39 | + 'error' => $e->getMessage(), |
|
| 40 | + 'success' => false, |
|
| 41 | 41 | ], |
| 42 | - ], 500); |
|
| 42 | + ], 500); |
|
| 43 | + } |
|
| 43 | 44 | } |
| 44 | - } |
|
| 45 | 45 | } |
@@ -22,7 +22,7 @@ |
||
| 22 | 22 | { |
| 23 | 23 | |
| 24 | 24 | try { |
| 25 | - $payload = json_decode($request->getContent()); |
|
| 25 | + $payload = json_decode($request->getContent()); |
|
| 26 | 26 | return new JsonResponse($this->hydratorService->result( |
| 27 | 27 | $this->service->createUser( |
| 28 | 28 | $payload->people, |
@@ -12,29 +12,29 @@ |
||
| 12 | 12 | class ChangePasswordAction |
| 13 | 13 | { |
| 14 | 14 | |
| 15 | - public function __construct( |
|
| 15 | + public function __construct( |
|
| 16 | 16 | private EntityManagerInterface $manager, |
| 17 | 17 | private UserService $service, |
| 18 | 18 | private HydratorService $hydratorService |
| 19 | 19 | |
| 20 | - ) {} |
|
| 20 | + ) {} |
|
| 21 | 21 | |
| 22 | - public function __invoke(User $data, Request $request) |
|
| 23 | - { |
|
| 22 | + public function __invoke(User $data, Request $request) |
|
| 23 | + { |
|
| 24 | 24 | |
| 25 | 25 | try { |
| 26 | - $payload = json_decode($request->getContent()); |
|
| 27 | - return new JsonResponse($this->hydratorService->result($this->service->changePassword($data, $payload->password))); |
|
| 26 | + $payload = json_decode($request->getContent()); |
|
| 27 | + return new JsonResponse($this->hydratorService->result($this->service->changePassword($data, $payload->password))); |
|
| 28 | 28 | } catch (\Exception $e) { |
| 29 | 29 | |
| 30 | - return new JsonResponse([ |
|
| 30 | + return new JsonResponse([ |
|
| 31 | 31 | 'response' => [ |
| 32 | - 'data' => [], |
|
| 33 | - 'count' => 0, |
|
| 34 | - 'error' => $e->getMessage(), |
|
| 35 | - 'success' => false, |
|
| 32 | + 'data' => [], |
|
| 33 | + 'count' => 0, |
|
| 34 | + 'error' => $e->getMessage(), |
|
| 35 | + 'success' => false, |
|
| 36 | 36 | ], |
| 37 | - ], 500); |
|
| 37 | + ], 500); |
|
| 38 | + } |
|
| 38 | 39 | } |
| 39 | - } |
|
| 40 | 40 | } |
@@ -23,7 +23,7 @@ |
||
| 23 | 23 | { |
| 24 | 24 | |
| 25 | 25 | try { |
| 26 | - $payload = json_decode($request->getContent()); |
|
| 26 | + $payload = json_decode($request->getContent()); |
|
| 27 | 27 | return new JsonResponse($this->hydratorService->result($this->service->changePassword($data, $payload->password))); |
| 28 | 28 | } catch (\Exception $e) { |
| 29 | 29 | |