@@ -10,37 +10,37 @@ discard block |
||
10 | 10 | |
11 | 11 | class UserService |
12 | 12 | { |
13 | - public function __construct(private EntityManagerInterface $manager, private UserPasswordEncoderInterface $encoder) {} |
|
14 | - public function changePassword(User $user, $password) |
|
15 | - { |
|
13 | + public function __construct(private EntityManagerInterface $manager, private UserPasswordEncoderInterface $encoder) {} |
|
14 | + public function changePassword(User $user, $password) |
|
15 | + { |
|
16 | 16 | if (!$this->getPermission()) |
17 | - throw new Exception("You should not pass!!!", 301); |
|
17 | + throw new Exception("You should not pass!!!", 301); |
|
18 | 18 | |
19 | 19 | $user->setHash( |
20 | - $this->encoder->encodePassword($user, $password) |
|
20 | + $this->encoder->encodePassword($user, $password) |
|
21 | 21 | ); |
22 | 22 | |
23 | 23 | $this->manager->persist($user); |
24 | 24 | $this->manager->flush(); |
25 | 25 | return $user; |
26 | - } |
|
26 | + } |
|
27 | 27 | |
28 | - public function changeApiKey(User $user) |
|
29 | - { |
|
28 | + public function changeApiKey(User $user) |
|
29 | + { |
|
30 | 30 | if (!$this->getPermission()) |
31 | - throw new Exception("You should not pass!!!", 301); |
|
31 | + throw new Exception("You should not pass!!!", 301); |
|
32 | 32 | |
33 | 33 | $user->generateApiKey(); |
34 | 34 | |
35 | 35 | $this->manager->persist($user); |
36 | 36 | $this->manager->flush(); |
37 | 37 | return $user; |
38 | - } |
|
38 | + } |
|
39 | 39 | |
40 | - public function createUser(People $people, $username, $password) |
|
41 | - { |
|
40 | + public function createUser(People $people, $username, $password) |
|
41 | + { |
|
42 | 42 | if (!$this->getPermission()) |
43 | - throw new Exception("You should not pass!!!", 301); |
|
43 | + throw new Exception("You should not pass!!!", 301); |
|
44 | 44 | |
45 | 45 | $user = new User(); |
46 | 46 | $user->setPeople($people); |
@@ -50,13 +50,13 @@ discard block |
||
50 | 50 | $this->manager->persist($user); |
51 | 51 | $this->manager->flush(); |
52 | 52 | return $user; |
53 | - } |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * @todo arrumar |
|
57 | - */ |
|
58 | - private function getPermission() |
|
59 | - { |
|
55 | + /** |
|
56 | + * @todo arrumar |
|
57 | + */ |
|
58 | + private function getPermission() |
|
59 | + { |
|
60 | 60 | return true; |
61 | - } |
|
61 | + } |
|
62 | 62 | } |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | public function __construct(private EntityManagerInterface $manager, private UserPasswordEncoderInterface $encoder) {} |
14 | 14 | public function changePassword(User $user, $password) |
15 | 15 | { |
16 | - if (!$this->getPermission()) |
|
17 | - throw new Exception("You should not pass!!!", 301); |
|
16 | + if (!$this->getPermission()) { |
|
17 | + throw new Exception("You should not pass!!!", 301); |
|
18 | + } |
|
18 | 19 | |
19 | 20 | $user->setHash( |
20 | 21 | $this->encoder->encodePassword($user, $password) |
@@ -27,8 +28,9 @@ discard block |
||
27 | 28 | |
28 | 29 | public function changeApiKey(User $user) |
29 | 30 | { |
30 | - if (!$this->getPermission()) |
|
31 | - throw new Exception("You should not pass!!!", 301); |
|
31 | + if (!$this->getPermission()) { |
|
32 | + throw new Exception("You should not pass!!!", 301); |
|
33 | + } |
|
32 | 34 | |
33 | 35 | $user->generateApiKey(); |
34 | 36 | |
@@ -39,8 +41,9 @@ discard block |
||
39 | 41 | |
40 | 42 | public function createUser(People $people, $username, $password) |
41 | 43 | { |
42 | - if (!$this->getPermission()) |
|
43 | - throw new Exception("You should not pass!!!", 301); |
|
44 | + if (!$this->getPermission()) { |
|
45 | + throw new Exception("You should not pass!!!", 301); |
|
46 | + } |
|
44 | 47 | |
45 | 48 | $user = new User(); |
46 | 49 | $user->setPeople($people); |
@@ -11,37 +11,37 @@ |
||
11 | 11 | class ChangeApiKeyAction |
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(User $data) |
|
22 | - { |
|
21 | + public function __invoke(User $data) |
|
22 | + { |
|
23 | 23 | |
24 | 24 | try { |
25 | 25 | |
26 | - $user = $this->service->changeApiKey($data); |
|
26 | + $user = $this->service->changeApiKey($data); |
|
27 | 27 | |
28 | - return new JsonResponse( |
|
28 | + return new JsonResponse( |
|
29 | 29 | $this->hydratorService->item( |
30 | - User::class, |
|
31 | - $user->getId(), |
|
32 | - "user_read" |
|
30 | + User::class, |
|
31 | + $user->getId(), |
|
32 | + "user_read" |
|
33 | 33 | ) |
34 | - ); |
|
34 | + ); |
|
35 | 35 | } catch (\Exception $e) { |
36 | 36 | |
37 | - return new JsonResponse([ |
|
37 | + return new JsonResponse([ |
|
38 | 38 | 'response' => [ |
39 | - 'data' => [], |
|
40 | - 'count' => 0, |
|
41 | - 'error' => $e->getMessage(), |
|
42 | - 'success' => false, |
|
39 | + 'data' => [], |
|
40 | + 'count' => 0, |
|
41 | + 'error' => $e->getMessage(), |
|
42 | + 'success' => false, |
|
43 | 43 | ], |
44 | - ], 500); |
|
44 | + ], 500); |
|
45 | + } |
|
45 | 46 | } |
46 | - } |
|
47 | 47 | } |