1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ControleOnline\Controller; |
4
|
|
|
|
5
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
|
|
|
|
6
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
|
|
|
7
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
|
|
|
8
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
|
|
|
|
9
|
|
|
use ControleOnline\Entity\User; |
10
|
|
|
use ControleOnline\Entity\People; |
|
|
|
|
11
|
|
|
use App\Service\PeopleRoleService; |
|
|
|
|
12
|
|
|
|
13
|
|
|
class SecurityController extends AbstractController |
14
|
|
|
{ |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
public function __construct( |
18
|
|
|
private PeopleRoleService $roleService, |
19
|
|
|
private EntityManagerInterface $manager, |
20
|
|
|
) { |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @Route("/token", name="auth_token", methods={"POST"}) |
25
|
|
|
*/ |
26
|
|
|
public function token(Request $request) |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @var \ControleOnline\Entity\User |
30
|
|
|
*/ |
31
|
|
|
$user = $this->getUser(); |
32
|
|
|
|
33
|
|
|
if ($user === null) |
34
|
|
|
return $this->json([ |
35
|
|
|
'error' => 'User not found' |
36
|
|
|
]); |
37
|
|
|
|
38
|
|
|
// get contact data from user |
39
|
|
|
|
40
|
|
|
$email = ''; |
41
|
|
|
$code = ''; |
42
|
|
|
$number = ''; |
43
|
|
|
|
44
|
|
|
if ($user->getPeople()->getEmail()->count() > 0) |
45
|
|
|
$email = $user->getPeople()->getEmail()->first()->getEmail(); |
46
|
|
|
|
47
|
|
|
if ($user->getPeople()->getPhone()->count() > 0) { |
48
|
|
|
$phone = $user->getPeople()->getPhone()->first(); |
49
|
|
|
$code = $phone->getDdd(); |
50
|
|
|
$number = $phone->getPhone(); |
51
|
|
|
} |
52
|
|
|
|
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(), |
64
|
|
|
]); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
private function getUserRealName(People $people): string |
68
|
|
|
{ |
69
|
|
|
$realName = 'John Doe'; |
70
|
|
|
|
71
|
|
|
if ($people->getPeopleType() == 'J') |
72
|
|
|
$realName = $people->getAlias(); |
73
|
|
|
|
74
|
|
|
else { |
75
|
|
|
if ($people->getPeopleType() == 'F') { |
76
|
|
|
$realName = $people->getName(); |
77
|
|
|
$realName .= ' ' . $people->getAlias(); |
78
|
|
|
$realName = trim($realName); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
return $realName; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
private function getCompany(User $user): ?People |
86
|
|
|
{ |
87
|
|
|
$peopleLink = $this->manager->getRepository(People::class)->getPeopleLink($user->getPeople(), 'employee', 1); |
88
|
|
|
if ($peopleLink !== false && $peopleLink->getCompany() instanceof People) |
89
|
|
|
return $peopleLink->getCompany(); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
private function getCompanyId(User $user): ?int |
93
|
|
|
{ |
94
|
|
|
$company = $this->getCompany($user); |
95
|
|
|
return $company ? $company->getId() : null; |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths