Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 16769 | Rev 16996 | 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;
16768 efrain 8
 
1 www 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;
16766 efrain 18
use LeadersLinked\Library\Functions;
16768 efrain 19
use LeadersLinked\Cache\CacheInterface;
20
use LeadersLinked\Cache\CacheImpl;
1 www 21
 
22
 
23
class AuthController extends AbstractActionController
24
{
25
    /**
26
     *
16769 efrain 27
     * @var \Laminas\Db\Adapter\AdapterInterface
1 www 28
     */
29
    private $adapter;
30
 
31
    /**
32
     *
16769 efrain 33
     * @var \LeadersLinked\Cache\CacheInterface
1 www 34
     */
16769 efrain 35
    private $cache;
36
 
37
 
38
    /**
39
     *
40
     * @var \Laminas\Log\LoggerInterface
41
     */
16768 efrain 42
    private $logger;
1 www 43
 
44
    /**
45
     *
16768 efrain 46
     * @var array
1 www 47
     */
16768 efrain 48
    private $config;
49
 
16769 efrain 50
 
1 www 51
    /**
16769 efrain 52
     *
53
     * @var \Laminas\Mvc\I18n\Translator
1 www 54
     */
16769 efrain 55
    private $translator;
1 www 56
 
16769 efrain 57
 
1 www 58
    /**
16768 efrain 59
     *
16769 efrain 60
     * @param \Laminas\Db\Adapter\AdapterInterface $adapter
61
     * @param \LeadersLinked\Cache\CacheInterface $cache
62
     * @param \Laminas\Log\LoggerInterface LoggerInterface $logger
1 www 63
     * @param array $config
16769 efrain 64
     * @param \Laminas\Mvc\I18n\Translator $translator
1 www 65
     */
16769 efrain 66
    public function __construct($adapter, $cache, $logger, $config, $translator)
1 www 67
    {
16769 efrain 68
        $this->adapter      = $adapter;
69
        $this->cache        = $cache;
70
        $this->logger       = $logger;
71
        $this->config       = $config;
72
        $this->translator   = $translator;
1 www 73
    }
16768 efrain 74
 
1 www 75
 
76
    public function indexAction()
77
    {
78
        $this->layout()->setTemplate('layout/auth');
79
        $viewModel = new ViewModel();
80
        $viewModel->setTemplate('leaders-linked/auth/index.phtml');
81
 
82
        return $viewModel ;
83
    }
84
 
85
    public function signoutAction()
86
    {
87
        $auth = new AuthenticationService();
88
        $auth->clearIdentity();
89
 
90
        return $this->redirect()->toRoute('home');
91
    }
92
 
93
    public function signinAdminAction()
94
    {
95
 
96
 
97
        $request = $this->getRequest();
98
        if($request->isGet()) {
16766 efrain 99
            $user_uuid  = Functions::sanitizeFilterString($this->params()->fromQuery('user_uuid'));
1 www 100
            $rand       = filter_var($this->params()->fromQuery('rand'), FILTER_SANITIZE_NUMBER_INT);
101
            $timestamp  = filter_var($this->params()->fromQuery('time'), FILTER_SANITIZE_NUMBER_INT);
16766 efrain 102
            $password   = Functions::sanitizeFilterString($this->params()->fromQuery('password'));
1 www 103
 
104
 
105
            if(!$user_uuid || !$rand || !$timestamp || !$password ) {
106
                throw new \Exception('ERROR_PARAMETERS_ARE_INVALID');
107
            }
108
 
109
 
110
            $authAdapter = new AuthOneTimePasswordAdapter ($this->adapter, $this->config);
111
            $authAdapter->setDataAdmin($user_uuid, $password, $timestamp, $rand);
112
 
113
            $authService = new AuthenticationService();
114
            $result = $authService->authenticate($authAdapter);
115
 
116
 
117
            if($result->getCode() == AuthResult::SUCCESS) {
118
                return $this->redirect()->toRoute('dashboard');
119
            } else {
120
                throw new \Exception($result->getMessages()[0]);
121
            }
122
        }
123
 
124
        return new JsonModel([
125
            'success' => false,
126
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
127
        ]);
128
 
129
    }
130
 
131
    public function signinCompanyAction()
132
    {
133
        $request = $this->getRequest();
134
        if($request->isGet()) {
16766 efrain 135
            $company_uuid = Functions::sanitizeFilterString($this->params()->fromQuery('company_uuid'));
136
            $user_uuid  = Functions::sanitizeFilterString($this->params()->fromQuery('user_uuid'));
137
            $timestamp   = Functions::sanitizeFilterString($this->params()->fromQuery('time'));
138
            $password   = Functions::sanitizeFilterString($this->params()->fromQuery('password'));
1 www 139
            $rand       = filter_var($this->params()->fromQuery('rand'), FILTER_SANITIZE_NUMBER_INT);
16766 efrain 140
            $relational = Functions::sanitizeFilterString($this->params()->fromQuery('relational'));
141
            $type       = Functions::sanitizeFilterString($this->params()->fromQuery('type'));
1 www 142
 
143
            if(empty($user_uuid)  || empty($company_uuid) || empty($user_uuid) || empty($timestamp)  || empty($password) || empty($rand)) {
144
                return new JsonModel([
145
                    'success' => false,
146
                    'data' => 'ERROR_PARAMETERS_ARE_INVALID'
147
                ]);
148
            }
149
 
150
            $authAdapter = new AuthOneTimePasswordAdapter ($this->adapter, $this->config);
151
            $authAdapter->setDataCompany($user_uuid, $password, $timestamp, $rand, $company_uuid);
152
 
153
            $authService = new AuthenticationService();
154
            $result = $authService->authenticate($authAdapter);
155
 
156
 
157
            if($result->getCode() == AuthResult::SUCCESS) {
15444 efrain 158
 
159
                switch($type)
160
                {
16820 efrain 161
                    case CalendarEvent::TYPE_SURVEY_ORGANIZATIONAL_CLIMATE :
162
 
163
                        $this->cache->setItem('ACTIVITY_CENTER_RELATIONAL', $relational);
164
 
165
                        $route =  'activities-center/organizational-climate';
166
                        break;
167
 
168
 
169
                    case CalendarEvent::TYPE_SURVEY_NORMAL :
170
 
171
                        $this->cache->setItem('ACTIVITY_CENTER_RELATIONAL', $relational);
172
 
173
                        $route =  'activities-center/survey';
174
                        break;
175
 
176
 
15444 efrain 177
                    case CalendarEvent::TYPE_PERFORMANCE_EVALUATION :
178
 
179
                        $this->cache->setItem('ACTIVITY_CENTER_RELATIONAL', $relational);
180
 
181
                        $route =  'activities-center/performance-evaluation';
182
                        break;
183
 
15461 efrain 184
 
185
                    case CalendarEvent::TYPE_RECRUITMENT_SELECTION_INTERVIEW :
186
 
187
                        $this->cache->setItem('ACTIVITY_CENTER_RELATIONAL', $relational);
188
 
189
                        $route =  'activities-center/recruitment-and-selection';
190
                        break;
191
 
15444 efrain 192
                    default :
193
                        $route = 'dashboard';
194
                        break;
195
 
196
                }
197
 
198
                return $this->redirect()->toRoute($route);
199
 
200
 
201
 
1 www 202
            } else {
203
                throw new \Exception($result->getMessages()[0]);
204
            }
205
        }
206
 
207
        return new JsonModel([
208
            'success' => false,
209
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
210
        ]);
211
    }
212
}