@@ -12,89 +12,89 @@ 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 discoveryPeople($email, $firstName = '', $lastName = '') |
|
61 | - { |
|
60 | + public function discoveryPeople($email, $firstName = '', $lastName = '') |
|
61 | + { |
|
62 | 62 | $email = $this->manager->getRepository(Email::class) |
63 | - ->findOneBy([ |
|
63 | + ->findOneBy([ |
|
64 | 64 | 'email' => $email, |
65 | - ]); |
|
65 | + ]); |
|
66 | 66 | if ($email) { |
67 | - $people = $email->getPeople(); |
|
67 | + $people = $email->getPeople(); |
|
68 | 68 | } else { |
69 | - $email = new Email(); |
|
70 | - $email->setEmail($email); |
|
71 | - $this->manager->persist($email); |
|
69 | + $email = new Email(); |
|
70 | + $email->setEmail($email); |
|
71 | + $this->manager->persist($email); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | if (!$people) { |
75 | 75 | |
76 | - $lang = $this->manager->getRepository(Language::class)->findOneBy(['language' => 'pt-BR']); |
|
77 | - $people = new People(); |
|
78 | - $people->setAlias($firstName); |
|
79 | - $people->setName($lastName); |
|
80 | - $people->setLanguage($lang); |
|
81 | - //$people->setBilling(0); |
|
82 | - //$people->setBillingDays('daily'); |
|
83 | - //$people->setPaymentTerm(1); |
|
84 | - //$people->setIcms(0); |
|
85 | - $email->setPeople($people); |
|
86 | - $this->manager->persist($email); |
|
76 | + $lang = $this->manager->getRepository(Language::class)->findOneBy(['language' => 'pt-BR']); |
|
77 | + $people = new People(); |
|
78 | + $people->setAlias($firstName); |
|
79 | + $people->setName($lastName); |
|
80 | + $people->setLanguage($lang); |
|
81 | + //$people->setBilling(0); |
|
82 | + //$people->setBillingDays('daily'); |
|
83 | + //$people->setPaymentTerm(1); |
|
84 | + //$people->setIcms(0); |
|
85 | + $email->setPeople($people); |
|
86 | + $this->manager->persist($email); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | $this->manager->persist($people); |
90 | 90 | $this->manager->flush(); |
91 | 91 | return $people; |
92 | - } |
|
92 | + } |
|
93 | 93 | |
94 | - public function createUser(People $people, $username, $password) |
|
95 | - { |
|
94 | + public function createUser(People $people, $username, $password) |
|
95 | + { |
|
96 | 96 | if (!$this->getPermission()) |
97 | - throw new Exception("You should not pass!!!", 301); |
|
97 | + throw new Exception("You should not pass!!!", 301); |
|
98 | 98 | |
99 | 99 | $user = new User(); |
100 | 100 | $user->setPeople($people); |
@@ -104,28 +104,28 @@ discard block |
||
104 | 104 | $this->manager->persist($user); |
105 | 105 | $this->manager->flush(); |
106 | 106 | return $user; |
107 | - } |
|
107 | + } |
|
108 | 108 | |
109 | 109 | |
110 | - public function getCompany(User $user) |
|
111 | - { |
|
110 | + public function getCompany(User $user) |
|
111 | + { |
|
112 | 112 | $peopleLink = $user->getPeople()->getLink()->first(); |
113 | 113 | |
114 | 114 | if ($peopleLink !== false && $peopleLink->getCompany() instanceof People) |
115 | - return $peopleLink->getCompany(); |
|
116 | - } |
|
115 | + return $peopleLink->getCompany(); |
|
116 | + } |
|
117 | 117 | |
118 | - public function getCompanyId(User $user) |
|
119 | - { |
|
118 | + public function getCompanyId(User $user) |
|
119 | + { |
|
120 | 120 | $company = $this->getCompany($user); |
121 | 121 | return $company ? $company->getId() : null; |
122 | - } |
|
122 | + } |
|
123 | 123 | |
124 | - /** |
|
125 | - * @todo arrumar |
|
126 | - */ |
|
127 | - private function getPermission() |
|
128 | - { |
|
124 | + /** |
|
125 | + * @todo arrumar |
|
126 | + */ |
|
127 | + private function getPermission() |
|
128 | + { |
|
129 | 129 | return true; |
130 | - } |
|
130 | + } |
|
131 | 131 | } |
@@ -15,8 +15,9 @@ discard block |
||
15 | 15 | public function __construct(private EntityManagerInterface $manager, private UserPasswordEncoderInterface $encoder) {} |
16 | 16 | public function changePassword(User $user, $password) |
17 | 17 | { |
18 | - if (!$this->getPermission()) |
|
19 | - throw new Exception("You should not pass!!!", 301); |
|
18 | + if (!$this->getPermission()) { |
|
19 | + throw new Exception("You should not pass!!!", 301); |
|
20 | + } |
|
20 | 21 | |
21 | 22 | $user->setHash( |
22 | 23 | $this->encoder->encodePassword($user, $password) |
@@ -29,8 +30,9 @@ discard block |
||
29 | 30 | |
30 | 31 | public function changeApiKey(User $user) |
31 | 32 | { |
32 | - if (!$this->getPermission()) |
|
33 | - throw new Exception("You should not pass!!!", 301); |
|
33 | + if (!$this->getPermission()) { |
|
34 | + throw new Exception("You should not pass!!!", 301); |
|
35 | + } |
|
34 | 36 | |
35 | 37 | $user->generateApiKey(); |
36 | 38 | |
@@ -51,8 +53,9 @@ discard block |
||
51 | 53 | |
52 | 54 | $people = $this->discoveryPeople($email, $firstName, $lastName); |
53 | 55 | |
54 | - if (!$user) |
|
55 | - $user = $this->createUser($people, $email, $password); |
|
56 | + if (!$user) { |
|
57 | + $user = $this->createUser($people, $email, $password); |
|
58 | + } |
|
56 | 59 | |
57 | 60 | return $user; |
58 | 61 | } |
@@ -93,8 +96,9 @@ discard block |
||
93 | 96 | |
94 | 97 | public function createUser(People $people, $username, $password) |
95 | 98 | { |
96 | - if (!$this->getPermission()) |
|
97 | - throw new Exception("You should not pass!!!", 301); |
|
99 | + if (!$this->getPermission()) { |
|
100 | + throw new Exception("You should not pass!!!", 301); |
|
101 | + } |
|
98 | 102 | |
99 | 103 | $user = new User(); |
100 | 104 | $user->setPeople($people); |
@@ -111,8 +115,9 @@ discard block |
||
111 | 115 | { |
112 | 116 | $peopleLink = $user->getPeople()->getLink()->first(); |
113 | 117 | |
114 | - if ($peopleLink !== false && $peopleLink->getCompany() instanceof People) |
|
115 | - return $peopleLink->getCompany(); |
|
118 | + if ($peopleLink !== false && $peopleLink->getCompany() instanceof People) { |
|
119 | + return $peopleLink->getCompany(); |
|
120 | + } |
|
116 | 121 | } |
117 | 122 | |
118 | 123 | public function getCompanyId(User $user) |
@@ -34,20 +34,23 @@ |
||
34 | 34 | try { |
35 | 35 | |
36 | 36 | |
37 | - if ($request->get('code')) |
|
38 | - $token = $this->provider->getAccessToken('authorization_code', [ |
|
37 | + if ($request->get('code')) { |
|
38 | + $token = $this->provider->getAccessToken('authorization_code', [ |
|
39 | 39 | 'code' => $request->get('code') |
40 | 40 | ]); |
41 | + } |
|
41 | 42 | |
42 | - if ($request->get('access_token')) |
|
43 | - $token = new AccessToken([ |
|
43 | + if ($request->get('access_token')) { |
|
44 | + $token = new AccessToken([ |
|
44 | 45 | 'access_token' => $request->get('access_token'), |
45 | 46 | ]); |
47 | + } |
|
46 | 48 | |
47 | - if ($request->get('code')) |
|
48 | - $token = $this->provider->getAccessToken('authorization_code', [ |
|
49 | + if ($request->get('code')) { |
|
50 | + $token = $this->provider->getAccessToken('authorization_code', [ |
|
49 | 51 | 'code' => $request->get('code') |
50 | 52 | ]); |
53 | + } |
|
51 | 54 | |
52 | 55 | $ownerDetails = $this->provider->getResourceOwner($token); |
53 | 56 |