@@ -14,26 +14,26 @@ discard block |
||
| 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 | - ) { |
|
| 21 | - } |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * @Route("/token", name="auth_token", methods={"POST"}) |
|
| 25 | - */ |
|
| 26 | - public function token(Request $request) |
|
| 27 | - { |
|
| 20 | + ) { |
|
| 21 | + } |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * @Route("/token", name="auth_token", methods={"POST"}) |
|
| 25 | + */ |
|
| 26 | + public function token(Request $request) |
|
| 27 | + { |
|
| 28 | 28 | /** |
| 29 | 29 | * @var \ControleOnline\Entity\User |
| 30 | 30 | */ |
| 31 | 31 | $user = $this->getUser(); |
| 32 | 32 | |
| 33 | 33 | if ($user === null) |
| 34 | - return $this->json([ |
|
| 34 | + return $this->json([ |
|
| 35 | 35 | 'error' => 'User not found' |
| 36 | - ]); |
|
| 36 | + ]); |
|
| 37 | 37 | |
| 38 | 38 | // get contact data from user |
| 39 | 39 | |
@@ -42,56 +42,56 @@ discard block |
||
| 42 | 42 | $number = ''; |
| 43 | 43 | |
| 44 | 44 | if ($user->getPeople()->getEmail()->count() > 0) |
| 45 | - $email = $user->getPeople()->getEmail()->first()->getEmail(); |
|
| 45 | + $email = $user->getPeople()->getEmail()->first()->getEmail(); |
|
| 46 | 46 | |
| 47 | 47 | if ($user->getPeople()->getPhone()->count() > 0) { |
| 48 | - $phone = $user->getPeople()->getPhone()->first(); |
|
| 49 | - $code = $phone->getDdd(); |
|
| 50 | - $number = $phone->getPhone(); |
|
| 48 | + $phone = $user->getPeople()->getPhone()->first(); |
|
| 49 | + $code = $phone->getDdd(); |
|
| 50 | + $number = $phone->getPhone(); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | return $this->json([ |
| 54 | - 'username' => $user->getUsername(), |
|
| 55 | - 'roles' => $user->getRoles(), |
|
| 56 | - 'api_key' => $user->getApiKey(), |
|
| 57 | - 'people' => $user->getPeople()->getId(), |
|
| 58 | - 'mycompany' => $this->getCompanyId($user), |
|
| 59 | - 'realname' => $this->getUserRealName($user->getPeople()), |
|
| 60 | - 'avatar' => $user->getPeople()->getFile() ? '/files/download/' . $user->getPeople()->getFile()->getId() : null, |
|
| 61 | - 'email' => $email, |
|
| 62 | - 'phone' => sprintf('%s%s', $code, $number), |
|
| 63 | - 'active' => (int) $user->getPeople()->getEnabled(), |
|
| 54 | + 'username' => $user->getUsername(), |
|
| 55 | + 'roles' => $user->getRoles(), |
|
| 56 | + 'api_key' => $user->getApiKey(), |
|
| 57 | + 'people' => $user->getPeople()->getId(), |
|
| 58 | + 'mycompany' => $this->getCompanyId($user), |
|
| 59 | + 'realname' => $this->getUserRealName($user->getPeople()), |
|
| 60 | + 'avatar' => $user->getPeople()->getFile() ? '/files/download/' . $user->getPeople()->getFile()->getId() : null, |
|
| 61 | + 'email' => $email, |
|
| 62 | + 'phone' => sprintf('%s%s', $code, $number), |
|
| 63 | + 'active' => (int) $user->getPeople()->getEnabled(), |
|
| 64 | 64 | ]); |
| 65 | - } |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - private function getUserRealName(People $people): string |
|
| 68 | - { |
|
| 67 | + private function getUserRealName(People $people): string |
|
| 68 | + { |
|
| 69 | 69 | $realName = 'John Doe'; |
| 70 | 70 | |
| 71 | 71 | if ($people->getPeopleType() == 'J') |
| 72 | - $realName = $people->getAlias(); |
|
| 72 | + $realName = $people->getAlias(); |
|
| 73 | 73 | |
| 74 | 74 | else { |
| 75 | - if ($people->getPeopleType() == 'F') { |
|
| 75 | + if ($people->getPeopleType() == 'F') { |
|
| 76 | 76 | $realName = $people->getName(); |
| 77 | 77 | $realName .= ' ' . $people->getAlias(); |
| 78 | 78 | $realName = trim($realName); |
| 79 | - } |
|
| 79 | + } |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | return $realName; |
| 83 | - } |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - private function getCompany(User $user): ?People |
|
| 86 | - { |
|
| 85 | + private function getCompany(User $user): ?People |
|
| 86 | + { |
|
| 87 | 87 | $peopleLink = $this->manager->getRepository(People::class)->getPeopleLink($user->getPeople(), 'employee', 1); |
| 88 | 88 | if ($peopleLink !== false && $peopleLink->getCompany() instanceof People) |
| 89 | - return $peopleLink->getCompany(); |
|
| 90 | - } |
|
| 89 | + return $peopleLink->getCompany(); |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - private function getCompanyId(User $user): ?int |
|
| 93 | - { |
|
| 92 | + private function getCompanyId(User $user): ?int |
|
| 93 | + { |
|
| 94 | 94 | $company = $this->getCompany($user); |
| 95 | 95 | return $company ? $company->getId() : null; |
| 96 | - } |
|
| 96 | + } |
|
| 97 | 97 | } |
@@ -30,10 +30,11 @@ discard block |
||
| 30 | 30 | */ |
| 31 | 31 | $user = $this->getUser(); |
| 32 | 32 | |
| 33 | - if ($user === null) |
|
| 34 | - return $this->json([ |
|
| 33 | + if ($user === null) { |
|
| 34 | + return $this->json([ |
|
| 35 | 35 | 'error' => 'User not found' |
| 36 | 36 | ]); |
| 37 | + } |
|
| 37 | 38 | |
| 38 | 39 | // get contact data from user |
| 39 | 40 | |
@@ -41,8 +42,9 @@ discard block |
||
| 41 | 42 | $code = ''; |
| 42 | 43 | $number = ''; |
| 43 | 44 | |
| 44 | - if ($user->getPeople()->getEmail()->count() > 0) |
|
| 45 | - $email = $user->getPeople()->getEmail()->first()->getEmail(); |
|
| 45 | + if ($user->getPeople()->getEmail()->count() > 0) { |
|
| 46 | + $email = $user->getPeople()->getEmail()->first()->getEmail(); |
|
| 47 | + } |
|
| 46 | 48 | |
| 47 | 49 | if ($user->getPeople()->getPhone()->count() > 0) { |
| 48 | 50 | $phone = $user->getPeople()->getPhone()->first(); |
@@ -68,10 +70,9 @@ discard block |
||
| 68 | 70 | { |
| 69 | 71 | $realName = 'John Doe'; |
| 70 | 72 | |
| 71 | - if ($people->getPeopleType() == 'J') |
|
| 72 | - $realName = $people->getAlias(); |
|
| 73 | - |
|
| 74 | - else { |
|
| 73 | + if ($people->getPeopleType() == 'J') { |
|
| 74 | + $realName = $people->getAlias(); |
|
| 75 | + } else { |
|
| 75 | 76 | if ($people->getPeopleType() == 'F') { |
| 76 | 77 | $realName = $people->getName(); |
| 77 | 78 | $realName .= ' ' . $people->getAlias(); |
@@ -85,8 +86,9 @@ discard block |
||
| 85 | 86 | private function getCompany(User $user): ?People |
| 86 | 87 | { |
| 87 | 88 | $peopleLink = $this->manager->getRepository(People::class)->getPeopleLink($user->getPeople(), 'employee', 1); |
| 88 | - if ($peopleLink !== false && $peopleLink->getCompany() instanceof People) |
|
| 89 | - return $peopleLink->getCompany(); |
|
| 89 | + if ($peopleLink !== false && $peopleLink->getCompany() instanceof People) { |
|
| 90 | + return $peopleLink->getCompany(); |
|
| 91 | + } |
|
| 90 | 92 | } |
| 91 | 93 | |
| 92 | 94 | private function getCompanyId(User $user): ?int |