@@ -28,13 +28,13 @@ |
||
28 | 28 | public function updatePassword(string $email, string $password): ?User |
29 | 29 | { |
30 | 30 | if ($user = $this->findOneByEmail($email)) { |
31 | - $user->setPassword($password); |
|
31 | + $user->setPassword($password); |
|
32 | 32 | |
33 | - $this->getEntityManager()->persist($user); |
|
33 | + $this->getEntityManager()->persist($user); |
|
34 | 34 | |
35 | - $this->getEntityManager()->flush(); |
|
35 | + $this->getEntityManager()->flush(); |
|
36 | 36 | |
37 | - return $user; |
|
37 | + return $user; |
|
38 | 38 | } |
39 | 39 | } |
40 | 40 |
@@ -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 | } |
@@ -13,43 +13,43 @@ |
||
13 | 13 | class CreateUserAction |
14 | 14 | { |
15 | 15 | |
16 | - public function __construct( |
|
16 | + public function __construct( |
|
17 | 17 | private EntityManagerInterface $manager, |
18 | 18 | private UserService $service, |
19 | 19 | private HydratorService $hydratorService |
20 | 20 | |
21 | - ) {} |
|
21 | + ) {} |
|
22 | 22 | |
23 | - public function __invoke(Request $request) |
|
24 | - { |
|
23 | + public function __invoke(Request $request) |
|
24 | + { |
|
25 | 25 | |
26 | 26 | try { |
27 | - $payload = json_decode($request->getContent()); |
|
28 | - $people = $this->manager->getRepository(People::class)->find($payload->people); |
|
27 | + $payload = json_decode($request->getContent()); |
|
28 | + $people = $this->manager->getRepository(People::class)->find($payload->people); |
|
29 | 29 | |
30 | - $user = $this->service->createUser( |
|
30 | + $user = $this->service->createUser( |
|
31 | 31 | $people, |
32 | 32 | $payload->username, |
33 | 33 | $payload->password |
34 | - ); |
|
34 | + ); |
|
35 | 35 | |
36 | - return new JsonResponse( |
|
36 | + return new JsonResponse( |
|
37 | 37 | $this->hydratorService->item( |
38 | - User::class, |
|
39 | - $user->getId(), |
|
40 | - "user:read" |
|
38 | + User::class, |
|
39 | + $user->getId(), |
|
40 | + "user:read" |
|
41 | 41 | ) |
42 | - ); |
|
42 | + ); |
|
43 | 43 | } catch (\Exception $e) { |
44 | 44 | |
45 | - return new JsonResponse([ |
|
45 | + return new JsonResponse([ |
|
46 | 46 | 'response' => [ |
47 | - 'data' => [], |
|
48 | - 'count' => 0, |
|
49 | - 'error' => $e->getMessage(), |
|
50 | - 'success' => false, |
|
47 | + 'data' => [], |
|
48 | + 'count' => 0, |
|
49 | + 'error' => $e->getMessage(), |
|
50 | + 'success' => false, |
|
51 | 51 | ], |
52 | - ], 500); |
|
52 | + ], 500); |
|
53 | + } |
|
53 | 54 | } |
54 | - } |
|
55 | 55 | } |
@@ -12,38 +12,38 @@ |
||
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()); |
|
26 | + $payload = json_decode($request->getContent()); |
|
27 | 27 | |
28 | - $user = $this->service->changePassword($data, $payload->password); |
|
28 | + $user = $this->service->changePassword($data, $payload->password); |
|
29 | 29 | |
30 | - return new JsonResponse( |
|
30 | + return new JsonResponse( |
|
31 | 31 | $this->hydratorService->item( |
32 | - User::class, |
|
33 | - $user->getId(), |
|
34 | - "user:read" |
|
32 | + User::class, |
|
33 | + $user->getId(), |
|
34 | + "user:read" |
|
35 | 35 | ) |
36 | - ); |
|
36 | + ); |
|
37 | 37 | } catch (\Exception $e) { |
38 | 38 | |
39 | - return new JsonResponse([ |
|
39 | + return new JsonResponse([ |
|
40 | 40 | 'response' => [ |
41 | - 'data' => [], |
|
42 | - 'count' => 0, |
|
43 | - 'error' => $e->getMessage(), |
|
44 | - 'success' => false, |
|
41 | + 'data' => [], |
|
42 | + 'count' => 0, |
|
43 | + 'error' => $e->getMessage(), |
|
44 | + 'success' => false, |
|
45 | 45 | ], |
46 | - ], 500); |
|
46 | + ], 500); |
|
47 | + } |
|
47 | 48 | } |
48 | - } |
|
49 | 49 | } |
@@ -14,25 +14,25 @@ |
||
14 | 14 | { |
15 | 15 | |
16 | 16 | |
17 | - public function __construct( |
|
17 | + public function __construct( |
|
18 | 18 | private PeopleRoleService $roleService, |
19 | 19 | private EntityManagerInterface $manager, |
20 | 20 | protected UserService $userService |
21 | - ) {} |
|
21 | + ) {} |
|
22 | 22 | |
23 | - public function __invoke(Request $request) |
|
24 | - { |
|
23 | + public function __invoke(Request $request) |
|
24 | + { |
|
25 | 25 | /** |
26 | 26 | * @var \ControleOnline\Entity\User |
27 | 27 | */ |
28 | 28 | $user = $this->getUser(); |
29 | 29 | |
30 | 30 | if ($user === null) |
31 | - return $this->json([ |
|
31 | + return $this->json([ |
|
32 | 32 | 'error' => 'User not found' |
33 | - ]); |
|
33 | + ]); |
|
34 | 34 | |
35 | 35 | return $this->json($this->userService->getUserSession($user)); |
36 | 36 | |
37 | - } |
|
37 | + } |
|
38 | 38 | } |
@@ -13,43 +13,43 @@ |
||
13 | 13 | class CreateAccountAction |
14 | 14 | { |
15 | 15 | |
16 | - public function __construct( |
|
16 | + public function __construct( |
|
17 | 17 | private EntityManagerInterface $manager, |
18 | 18 | private UserService $service, |
19 | 19 | private HydratorService $hydratorService |
20 | 20 | |
21 | - ) {} |
|
21 | + ) {} |
|
22 | 22 | |
23 | - public function __invoke(Request $request) |
|
24 | - { |
|
23 | + public function __invoke(Request $request) |
|
24 | + { |
|
25 | 25 | |
26 | 26 | try { |
27 | - $payload = json_decode($request->getContent()); |
|
28 | - $people = $this->service->discoveryPeople($payload->email, $payload->name); |
|
27 | + $payload = json_decode($request->getContent()); |
|
28 | + $people = $this->service->discoveryPeople($payload->email, $payload->name); |
|
29 | 29 | |
30 | - $user = $this->service->createUser( |
|
30 | + $user = $this->service->createUser( |
|
31 | 31 | $people, |
32 | 32 | $payload->email, |
33 | 33 | $payload->password |
34 | - ); |
|
34 | + ); |
|
35 | 35 | |
36 | - return new JsonResponse( |
|
36 | + return new JsonResponse( |
|
37 | 37 | $this->hydratorService->item( |
38 | - User::class, |
|
39 | - $user->getId(), |
|
40 | - "user:read" |
|
38 | + User::class, |
|
39 | + $user->getId(), |
|
40 | + "user:read" |
|
41 | 41 | ) |
42 | - ); |
|
42 | + ); |
|
43 | 43 | } catch (\Exception $e) { |
44 | 44 | |
45 | - return new JsonResponse([ |
|
45 | + return new JsonResponse([ |
|
46 | 46 | 'response' => [ |
47 | - 'data' => [], |
|
48 | - 'count' => 0, |
|
49 | - 'error' => $e->getMessage(), |
|
50 | - 'success' => false, |
|
47 | + 'data' => [], |
|
48 | + 'count' => 0, |
|
49 | + 'error' => $e->getMessage(), |
|
50 | + 'success' => false, |
|
51 | 51 | ], |
52 | - ], 500); |
|
52 | + ], 500); |
|
53 | + } |
|
53 | 54 | } |
54 | - } |
|
55 | 55 | } |
@@ -12,53 +12,53 @@ discard block |
||
12 | 12 | |
13 | 13 | class UserService |
14 | 14 | { |
15 | - public function __construct(private EntityManagerInterface $manager, private UserPasswordEncoderInterface $encoder) {} |
|
16 | - public function changePassword(User $user, $password) |
|
17 | - { |
|
15 | + public function __construct(private EntityManagerInterface $manager, private UserPasswordEncoderInterface $encoder) {} |
|
16 | + public function changePassword(User $user, $password) |
|
17 | + { |
|
18 | 18 | if (!$this->getPermission()) |
19 | - throw new Exception("You should not pass!!!", 301); |
|
19 | + throw new Exception("You should not pass!!!", 301); |
|
20 | 20 | |
21 | 21 | $user->setHash( |
22 | - $this->encoder->encodePassword($user, $password) |
|
22 | + $this->encoder->encodePassword($user, $password) |
|
23 | 23 | ); |
24 | 24 | |
25 | 25 | $this->manager->persist($user); |
26 | 26 | $this->manager->flush(); |
27 | 27 | return $user; |
28 | - } |
|
28 | + } |
|
29 | 29 | |
30 | - public function changeApiKey(User $user) |
|
31 | - { |
|
30 | + public function changeApiKey(User $user) |
|
31 | + { |
|
32 | 32 | if (!$this->getPermission()) |
33 | - throw new Exception("You should not pass!!!", 301); |
|
33 | + throw new Exception("You should not pass!!!", 301); |
|
34 | 34 | |
35 | 35 | $user->generateApiKey(); |
36 | 36 | |
37 | 37 | $this->manager->persist($user); |
38 | 38 | $this->manager->flush(); |
39 | 39 | return $user; |
40 | - } |
|
40 | + } |
|
41 | 41 | |
42 | 42 | |
43 | - public function discoveryUser($email, $password, $firstName, $lastName) |
|
44 | - { |
|
43 | + public function discoveryUser($email, $password, $firstName, $lastName) |
|
44 | + { |
|
45 | 45 | |
46 | 46 | $user = $this->manager->getRepository(User::class) |
47 | - ->findOneBy([ |
|
47 | + ->findOneBy([ |
|
48 | 48 | 'username' => $email, |
49 | - ]); |
|
49 | + ]); |
|
50 | 50 | |
51 | 51 | |
52 | 52 | $people = $this->discoveryPeople($email, $firstName, $lastName); |
53 | 53 | |
54 | 54 | if (!$user) |
55 | - $user = $this->createUser($people, $email, $password); |
|
55 | + $user = $this->createUser($people, $email, $password); |
|
56 | 56 | |
57 | 57 | return $user; |
58 | - } |
|
58 | + } |
|
59 | 59 | |
60 | - public function getUserSession($user) |
|
61 | - { |
|
60 | + public function getUserSession($user) |
|
61 | + { |
|
62 | 62 | |
63 | 63 | // get contact data from user |
64 | 64 | |
@@ -67,93 +67,93 @@ discard block |
||
67 | 67 | $number = ''; |
68 | 68 | |
69 | 69 | if ($user->getPeople()->getEmail()->count() > 0) |
70 | - $email = $user->getPeople()->getEmail()->first()->getEmail(); |
|
70 | + $email = $user->getPeople()->getEmail()->first()->getEmail(); |
|
71 | 71 | |
72 | 72 | if ($user->getPeople()->getPhone()->count() > 0) { |
73 | - $phone = $user->getPeople()->getPhone()->first(); |
|
74 | - $code = $phone->getDdd(); |
|
75 | - $number = $phone->getPhone(); |
|
73 | + $phone = $user->getPeople()->getPhone()->first(); |
|
74 | + $code = $phone->getDdd(); |
|
75 | + $number = $phone->getPhone(); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | return [ |
79 | - 'id' => $user->getPeople()->getId(), |
|
80 | - 'username' => $user->getUsername(), |
|
81 | - 'roles' => $user->getRoles(), |
|
82 | - 'api_key' => $user->getApiKey(), |
|
83 | - 'people' => $user->getPeople()->getId(), |
|
84 | - 'mycompany' => $this->getCompanyId($user), |
|
85 | - 'realname' => $this->getUserRealName($user->getPeople()), |
|
86 | - 'avatar' => $user->getPeople()->getImage() ? '/files/' . $user->getPeople()->getImage()->getId() . '/download' : null, |
|
87 | - 'email' => $email, |
|
88 | - 'phone' => sprintf('%s%s', $code, $number), |
|
89 | - 'active' => (int) $user->getPeople()->getEnabled(), |
|
79 | + 'id' => $user->getPeople()->getId(), |
|
80 | + 'username' => $user->getUsername(), |
|
81 | + 'roles' => $user->getRoles(), |
|
82 | + 'api_key' => $user->getApiKey(), |
|
83 | + 'people' => $user->getPeople()->getId(), |
|
84 | + 'mycompany' => $this->getCompanyId($user), |
|
85 | + 'realname' => $this->getUserRealName($user->getPeople()), |
|
86 | + 'avatar' => $user->getPeople()->getImage() ? '/files/' . $user->getPeople()->getImage()->getId() . '/download' : null, |
|
87 | + 'email' => $email, |
|
88 | + 'phone' => sprintf('%s%s', $code, $number), |
|
89 | + 'active' => (int) $user->getPeople()->getEnabled(), |
|
90 | 90 | ]; |
91 | - } |
|
91 | + } |
|
92 | 92 | |
93 | - private function getUserRealName(People $people): string |
|
94 | - { |
|
93 | + private function getUserRealName(People $people): string |
|
94 | + { |
|
95 | 95 | $realName = 'John Doe'; |
96 | 96 | |
97 | 97 | if ($people->getPeopleType() == 'J') |
98 | - $realName = $people->getAlias(); |
|
98 | + $realName = $people->getAlias(); |
|
99 | 99 | |
100 | 100 | else { |
101 | - if ($people->getPeopleType() == 'F') { |
|
101 | + if ($people->getPeopleType() == 'F') { |
|
102 | 102 | $realName = $people->getName(); |
103 | 103 | $realName .= ' ' . $people->getAlias(); |
104 | 104 | $realName = trim($realName); |
105 | - } |
|
105 | + } |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | return $realName; |
109 | - } |
|
109 | + } |
|
110 | 110 | |
111 | - public function discoveryPeople($mail, $firstName = '', $lastName = '') |
|
112 | - { |
|
111 | + public function discoveryPeople($mail, $firstName = '', $lastName = '') |
|
112 | + { |
|
113 | 113 | $email = $this->manager->getRepository(Email::class) |
114 | - ->findOneBy([ |
|
114 | + ->findOneBy([ |
|
115 | 115 | 'email' => $mail, |
116 | - ]); |
|
116 | + ]); |
|
117 | 117 | if ($email) { |
118 | - $people = $email->getPeople(); |
|
118 | + $people = $email->getPeople(); |
|
119 | 119 | } else { |
120 | - $email = new Email(); |
|
121 | - $email->setEmail($mail); |
|
122 | - $this->manager->persist($email); |
|
120 | + $email = new Email(); |
|
121 | + $email->setEmail($mail); |
|
122 | + $this->manager->persist($email); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | if (!$people) { |
126 | 126 | |
127 | - $lang = $this->manager->getRepository(Language::class)->findOneBy(['language' => 'pt-BR']); |
|
128 | - $people = new People(); |
|
129 | - $people->setAlias($firstName); |
|
130 | - $people->setName($lastName); |
|
131 | - $people->setLanguage($lang); |
|
132 | - //$people->setBilling(0); |
|
133 | - //$people->setBillingDays('daily'); |
|
134 | - //$people->setPaymentTerm(1); |
|
135 | - //$people->setIcms(0); |
|
136 | - $email->setPeople($people); |
|
137 | - $this->manager->persist($email); |
|
127 | + $lang = $this->manager->getRepository(Language::class)->findOneBy(['language' => 'pt-BR']); |
|
128 | + $people = new People(); |
|
129 | + $people->setAlias($firstName); |
|
130 | + $people->setName($lastName); |
|
131 | + $people->setLanguage($lang); |
|
132 | + //$people->setBilling(0); |
|
133 | + //$people->setBillingDays('daily'); |
|
134 | + //$people->setPaymentTerm(1); |
|
135 | + //$people->setIcms(0); |
|
136 | + $email->setPeople($people); |
|
137 | + $this->manager->persist($email); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | $this->manager->persist($people); |
141 | 141 | $this->manager->flush(); |
142 | 142 | return $people; |
143 | - } |
|
143 | + } |
|
144 | 144 | |
145 | - public function createUser(People $people, $username, $password) |
|
146 | - { |
|
145 | + public function createUser(People $people, $username, $password) |
|
146 | + { |
|
147 | 147 | if (!$this->getPermission()) |
148 | - throw new Exception("You should not pass!!!", 301); |
|
148 | + throw new Exception("You should not pass!!!", 301); |
|
149 | 149 | |
150 | 150 | $user = $this->manager->getRepository(User::class) |
151 | - ->findOneBy([ |
|
151 | + ->findOneBy([ |
|
152 | 152 | 'username' => $username, |
153 | - ]); |
|
153 | + ]); |
|
154 | 154 | |
155 | 155 | if ($username) |
156 | - throw new Exception("User already exists", 301); |
|
156 | + throw new Exception("User already exists", 301); |
|
157 | 157 | |
158 | 158 | $user = new User(); |
159 | 159 | $user->setPeople($people); |
@@ -163,28 +163,28 @@ discard block |
||
163 | 163 | $this->manager->persist($user); |
164 | 164 | $this->manager->flush(); |
165 | 165 | return $user; |
166 | - } |
|
166 | + } |
|
167 | 167 | |
168 | 168 | |
169 | - public function getCompany(User $user) |
|
170 | - { |
|
169 | + public function getCompany(User $user) |
|
170 | + { |
|
171 | 171 | $peopleLink = $user->getPeople()->getLink()->first(); |
172 | 172 | |
173 | 173 | if ($peopleLink !== false && $peopleLink->getCompany() instanceof People) |
174 | - return $peopleLink->getCompany(); |
|
175 | - } |
|
174 | + return $peopleLink->getCompany(); |
|
175 | + } |
|
176 | 176 | |
177 | - public function getCompanyId(User $user) |
|
178 | - { |
|
177 | + public function getCompanyId(User $user) |
|
178 | + { |
|
179 | 179 | $company = $this->getCompany($user); |
180 | 180 | return $company ? $company->getId() : null; |
181 | - } |
|
181 | + } |
|
182 | 182 | |
183 | - /** |
|
184 | - * @todo arrumar |
|
185 | - */ |
|
186 | - private function getPermission() |
|
187 | - { |
|
183 | + /** |
|
184 | + * @todo arrumar |
|
185 | + */ |
|
186 | + private function getPermission() |
|
187 | + { |
|
188 | 188 | return true; |
189 | - } |
|
189 | + } |
|
190 | 190 | } |