1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the Zemit Framework. |
4
|
|
|
* |
5
|
|
|
* (c) Zemit Team <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE.txt |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Zemit\Modules\Api\Controllers; |
12
|
|
|
|
13
|
|
|
use Phalcon\Http\ResponseInterface; |
14
|
|
|
use Zemit\Mvc\Controller\Identity; |
15
|
|
|
|
16
|
|
|
class AuthController extends AbstractController |
17
|
|
|
{ |
18
|
|
|
use Identity { |
19
|
|
|
getAction as traitGetAction; |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Create a refresh a session |
24
|
|
|
* |
25
|
|
|
* @param bool $refresh |
26
|
|
|
* |
27
|
|
|
* @return bool |
28
|
|
|
*/ |
29
|
|
|
public function getAction($refresh = false): ResponseInterface |
30
|
|
|
{ |
31
|
|
|
$ret = $this->traitGetAction($refresh); |
32
|
|
|
|
33
|
|
|
$indexLabelExpose = [false, 'email', 'label']; |
34
|
|
|
$expose = [ |
35
|
|
|
'User' => [false, 'id', 'email', 'firstName', 'lastName'], |
36
|
|
|
'Role' => $indexLabelExpose, |
37
|
|
|
'Group' => $indexLabelExpose, |
38
|
|
|
'Type' => $indexLabelExpose, |
39
|
|
|
]; |
40
|
|
|
|
41
|
|
|
// @todo review this |
42
|
|
|
$permissions = $this->config->path('permissions.roles', []); |
43
|
|
|
$view = ['permissionList' => ['everyone' => $permissions['everyone']['frontend'] ?? null]]; |
44
|
|
|
foreach (['user', 'userAs', 'roleList', 'groupList', 'typeList'] as $var) { |
45
|
|
|
if (is_array($this->view->$var)) { |
46
|
|
|
foreach ($this->view->$var as $key => $role) { |
47
|
|
|
if ($role) { |
48
|
|
|
$view[$var][$key] = $role->expose($expose); |
49
|
|
|
$view['permissionList'][$key] = $permissions[$key]['frontend'] ?? null; |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
else if ($this->view->$var) { |
54
|
|
|
$view[$var] = $this->view->$var->expose($expose); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
$this->view->setVars($view); |
58
|
|
|
|
59
|
|
|
return $ret; |
|
|
|
|
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
|