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 Zemit\Modules\Api\Controller; |
14
|
|
|
use Zemit\Mvc\Controller\Identity; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class AuthController |
18
|
|
|
* |
19
|
|
|
* @author Julien Turbide <[email protected]> |
20
|
|
|
* @copyright Zemit Team <[email protected]> |
21
|
|
|
* |
22
|
|
|
* @since 1.0 |
23
|
|
|
* @version 1.0 |
24
|
|
|
* |
25
|
|
|
* @package Zemit\Modules\Api\Controllers |
26
|
|
|
*/ |
27
|
|
|
class AuthController extends Controller |
28
|
|
|
{ |
29
|
|
|
use Identity; |
|
|
|
|
30
|
|
|
|
31
|
|
|
public function indexAction($id = null) |
32
|
|
|
{ |
33
|
|
|
return $this->getAction(); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* |
38
|
|
|
*/ |
39
|
|
|
public function destroyAction() { |
40
|
|
|
return $this->session->destroy(); |
|
|
|
|
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Create a refresh a session |
45
|
|
|
* |
46
|
|
|
* @param bool $refresh |
47
|
|
|
* |
48
|
|
|
* @return bool |
49
|
|
|
* @throws \Phalcon\Security\Exception |
50
|
|
|
*/ |
51
|
|
|
public function getAction($request = null) |
52
|
|
|
{ |
53
|
|
|
$this->view->setVars($this->identity->getJwt($request === true)); |
|
|
|
|
54
|
|
|
$this->view->setVars($this->identity->getIdentity()); |
55
|
|
|
|
56
|
|
|
$indexLabelExpose = [false, 'email', 'label', 'labelFr', 'labelEn', 'addressId']; |
57
|
|
|
$expose = [ |
58
|
|
|
'User' => [false, 'email', 'firstName', 'lastName', 'category', 'addressId', 'id', 'companyId'], |
59
|
|
|
'Role' => $indexLabelExpose, |
60
|
|
|
'Group' => $indexLabelExpose, |
61
|
|
|
'Type' => $indexLabelExpose, |
62
|
|
|
]; |
63
|
|
|
|
64
|
|
|
$permissions = $this->config->permissions->roles->toArray() ?? []; |
|
|
|
|
65
|
|
|
$permissionList = ['everyone' => $permissions['everyone']['frontend'] ?? null]; |
66
|
|
|
$vars = []; |
67
|
|
|
foreach (['user', 'userAs', 'roleList', 'groupList', 'typeList'] as $var) { |
68
|
|
|
if (is_array($this->view->$var)) { |
69
|
|
|
foreach ($this->view->$var as $key => $role) { |
70
|
|
|
if ($role) { |
71
|
|
|
$vars[$var][$key] = $role->expose($expose); |
72
|
|
|
$permissionList[$key] = $permissions[$key]['frontend'] ?? null; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
} else if ($this->view->$var) { |
76
|
|
|
$vars[$var] = $this->view->$var->expose($expose); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
$this->view->setVars($vars); |
80
|
|
|
|
81
|
|
|
$this->view->permissionList = $permissionList; |
82
|
|
|
|
83
|
|
|
return $this->view->saved && $this->view->stored && $this->view->validated; |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|