Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 15444 | Rev 16766 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 www 1
<?php
2
declare(strict_types=1);
3
 
4
namespace LeadersLinked\Controller;
5
 
6
use Laminas\Authentication\Result as AuthResult;
7
use Laminas\Db\Adapter\AdapterInterface;
8
use Laminas\Cache\Storage\Adapter\AbstractAdapter;
9
use Laminas\Mvc\Controller\AbstractActionController;
10
use Laminas\Log\LoggerInterface;
11
 
12
use LeadersLinked\Authentication\AuthOneTimePasswordAdapter;
13
use Laminas\Authentication\AuthenticationService;
14
 
15
use Laminas\View\Model\JsonModel;
16
use Laminas\View\Model\ViewModel;
15444 efrain 17
use LeadersLinked\Model\CalendarEvent;
1 www 18
 
19
 
20
class AuthController extends AbstractActionController
21
{
22
    /**
23
     *
24
     * @var AdapterInterface
25
     */
26
    private $adapter;
27
 
28
 
29
    /**
30
     *
31
     * @var AbstractAdapter
32
     */
33
    private $cache;
34
 
35
    /**
36
     *
37
     * @var  LoggerInterface
38
     */
39
    private $logger;
40
 
41
    /**
42
     *
43
     * @var array
44
     */
45
    private $config;
46
 
47
 
48
 
49
 
50
    /**
51
     *
52
     * @param AdapterInterface $adapter
53
     * @param AbstractAdapter $cache
54
     * @param LoggerInterface $logger
55
     * @param array $config
56
     */
57
    public function __construct($adapter, $cache , $logger, $config)
58
    {
59
        $this->adapter      = $adapter;
60
        $this->cache        = $cache;
61
        $this->logger       = $logger;
62
        $this->config       = $config;
63
    }
64
 
65
    public function indexAction()
66
    {
67
        $this->layout()->setTemplate('layout/auth');
68
        $viewModel = new ViewModel();
69
        $viewModel->setTemplate('leaders-linked/auth/index.phtml');
70
 
71
        return $viewModel ;
72
    }
73
 
74
    public function signoutAction()
75
    {
76
        $auth = new AuthenticationService();
77
        $auth->clearIdentity();
78
 
79
        return $this->redirect()->toRoute('home');
80
    }
81
 
82
    public function signinAdminAction()
83
    {
84
 
85
 
86
        $request = $this->getRequest();
87
        if($request->isGet()) {
88
            $user_uuid  = filter_var($this->params()->fromQuery('user_uuid'), FILTER_SANITIZE_STRING);
89
            $rand       = filter_var($this->params()->fromQuery('rand'), FILTER_SANITIZE_NUMBER_INT);
90
            $timestamp  = filter_var($this->params()->fromQuery('time'), FILTER_SANITIZE_NUMBER_INT);
91
            $password   = filter_var($this->params()->fromQuery('password'), FILTER_SANITIZE_STRING);
92
 
93
 
94
            if(!$user_uuid || !$rand || !$timestamp || !$password ) {
95
                throw new \Exception('ERROR_PARAMETERS_ARE_INVALID');
96
            }
97
 
98
 
99
            $authAdapter = new AuthOneTimePasswordAdapter ($this->adapter, $this->config);
100
            $authAdapter->setDataAdmin($user_uuid, $password, $timestamp, $rand);
101
 
102
            $authService = new AuthenticationService();
103
            $result = $authService->authenticate($authAdapter);
104
 
105
 
106
            if($result->getCode() == AuthResult::SUCCESS) {
107
                return $this->redirect()->toRoute('dashboard');
108
            } else {
109
                throw new \Exception($result->getMessages()[0]);
110
            }
111
        }
112
 
113
        return new JsonModel([
114
            'success' => false,
115
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
116
        ]);
117
 
118
    }
119
 
120
    public function signinCompanyAction()
121
    {
122
        $request = $this->getRequest();
123
        if($request->isGet()) {
124
            $company_uuid = filter_var($this->params()->fromQuery('company_uuid'), FILTER_SANITIZE_STRING);
125
            $user_uuid  = filter_var($this->params()->fromQuery('user_uuid'), FILTER_SANITIZE_STRING);
126
            $timestamp   = filter_var($this->params()->fromQuery('time'), FILTER_SANITIZE_STRING);
127
            $password   = filter_var($this->params()->fromQuery('password'), FILTER_SANITIZE_STRING);
128
            $rand       = filter_var($this->params()->fromQuery('rand'), FILTER_SANITIZE_NUMBER_INT);
15444 efrain 129
            $relational = filter_var($this->params()->fromQuery('relational'), FILTER_SANITIZE_STRING);
130
            $type       = filter_var($this->params()->fromQuery('type'), FILTER_SANITIZE_STRING);
1 www 131
 
132
            if(empty($user_uuid)  || empty($company_uuid) || empty($user_uuid) || empty($timestamp)  || empty($password) || empty($rand)) {
133
                return new JsonModel([
134
                    'success' => false,
135
                    'data' => 'ERROR_PARAMETERS_ARE_INVALID'
136
                ]);
137
            }
138
 
139
            $authAdapter = new AuthOneTimePasswordAdapter ($this->adapter, $this->config);
140
            $authAdapter->setDataCompany($user_uuid, $password, $timestamp, $rand, $company_uuid);
141
 
142
            $authService = new AuthenticationService();
143
            $result = $authService->authenticate($authAdapter);
144
 
145
 
146
            if($result->getCode() == AuthResult::SUCCESS) {
15444 efrain 147
 
148
                switch($type)
149
                {
150
                    case CalendarEvent::TYPE_PERFORMANCE_EVALUATION :
151
 
152
                        $this->cache->setItem('ACTIVITY_CENTER_RELATIONAL', $relational);
153
 
154
                        $route =  'activities-center/performance-evaluation';
155
                        break;
156
 
15461 efrain 157
 
158
                    case CalendarEvent::TYPE_RECRUITMENT_SELECTION_INTERVIEW :
159
 
160
                        $this->cache->setItem('ACTIVITY_CENTER_RELATIONAL', $relational);
161
 
162
                        $route =  'activities-center/recruitment-and-selection';
163
                        break;
164
 
15444 efrain 165
                    default :
166
                        $route = 'dashboard';
167
                        break;
168
 
169
                }
170
 
171
                return $this->redirect()->toRoute($route);
172
 
173
 
174
 
1 www 175
            } else {
176
                throw new \Exception($result->getMessages()[0]);
177
            }
178
        }
179
 
180
        return new JsonModel([
181
            'success' => false,
182
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
183
        ]);
184
    }
185
}