Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 6866 | | 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
 
6749 efrain 6
 
1 www 7
use Laminas\Db\Adapter\AdapterInterface;
8
use Laminas\Mvc\Controller\AbstractActionController;
9
use Laminas\Log\LoggerInterface;
10
use Laminas\View\Model\JsonModel;
11
use LeadersLinked\Model\UserType;
12
use LeadersLinked\Library\Functions;
13
use LeadersLinked\Mapper\CompanyMapper;
14
use LeadersLinked\Mapper\CompanyUserMapper;
15
use LeadersLinked\Model\CompanyUser;
3639 efrain 16
use LeadersLinked\Mapper\NetworkMapper;
4398 efrain 17
use LeadersLinked\Model\CalendarEvent;
4656 efrain 18
use LeadersLinked\Mapper\PerformanceEvaluationTestMapper;
5050 efrain 19
use LeadersLinked\Mapper\RecruitmentSelectionInterviewMapper;
6849 efrain 20
;
6749 efrain 21
use LeadersLinked\Mapper\UserMapper;
6866 efrain 22
use Laminas\Mvc\I18n\Translator;
23
use LeadersLinked\Cache\CacheInterface;
7340 efrain 24
use LeadersLinked\Model\SurveyTest;
25
use LeadersLinked\Mapper\SurveyTestMapper;
1 www 26
 
27
 
28
class BackendController extends AbstractActionController
29
{
30
    /**
31
     *
6866 efrain 32
     * @var \Laminas\Db\Adapter\AdapterInterface
1 www 33
     */
34
    private $adapter;
35
 
36
    /**
37
     *
6866 efrain 38
     * @var \LeadersLinked\Cache\CacheInterface
1 www 39
     */
6866 efrain 40
    private $cache;
41
 
42
 
43
    /**
44
     *
45
     * @var \Laminas\Log\LoggerInterface
46
     */
1 www 47
    private $logger;
6866 efrain 48
 
1 www 49
    /**
6866 efrain 50
     *
1 www 51
     * @var array
52
     */
53
    private $config;
54
 
6866 efrain 55
 
1 www 56
    /**
6866 efrain 57
     *
58
     * @var \Laminas\Mvc\I18n\Translator
59
     */
60
    private $translator;
61
 
62
 
63
    /**
64
     *
65
     * @param \Laminas\Db\Adapter\AdapterInterface $adapter
66
     * @param \LeadersLinked\Cache\CacheInterface $cache
67
     * @param \Laminas\Log\LoggerInterface LoggerInterface $logger
1 www 68
     * @param array $config
6866 efrain 69
     * @param \Laminas\Mvc\I18n\Translator $translator
1 www 70
     */
6866 efrain 71
    public function __construct($adapter, $cache, $logger, $config, $translator)
1 www 72
    {
73
        $this->adapter      = $adapter;
6866 efrain 74
        $this->cache        = $cache;
1 www 75
        $this->logger       = $logger;
76
        $this->config       = $config;
6866 efrain 77
        $this->translator   = $translator;
1 www 78
    }
79
 
80
    public function signinAdminAction()
81
    {
82
 
83
        $request = $this->getRequest();
84
        if($request->isGet()) {
85
            $currentUserPlugin = $this->plugin('currentUserPlugin');
86
            $currentUser = $currentUserPlugin->getUser();
87
 
3639 efrain 88
            $networkMapper = NetworkMapper::getInstance($this->adapter);
89
            $network = $networkMapper->fetchOne($currentUser->network_id);
1 www 90
 
3639 efrain 91
            $sandbox = $this->config['leaderslinked.runmode.sandbox'];
92
            if($sandbox) {
93
                $salt = $this->config['leaderslinked.backend.sandbox_salt'];
94
            } else {
95
                $salt = $this->config['leaderslinked.backend.production_salt'];
96
            }
97
 
98
 
99
 
1 www 100
            if($currentUser && $currentUser->usertype_id == UserType::ADMIN) {
101
 
102
 
103
                if(!$currentUser->one_time_password) {
104
                    $one_time_password = Functions::generatePassword(25);
105
 
106
                    $currentUser->one_time_password = $one_time_password;
107
 
108
                    $userMapper = UserMapper::getInstance($this->adapter);
109
                    $userMapper->updateOneTimePassword($currentUser, $one_time_password);
110
                }
111
 
3639 efrain 112
 
1 www 113
 
114
 
115
                $rand = 1000 + mt_rand(1, 999);
116
                $timestamp = time();
117
                $password = md5($currentUser->one_time_password . '-' . $rand . '-' . $timestamp . '-' . $salt);
118
 
119
                $params = [
120
                    'user_uuid' => $currentUser->uuid,
121
                    'password' => $password,
122
                    'rand' => $rand,
123
                    'time' => $timestamp,
124
                ];
125
 
3639 efrain 126
                $link_admin = 'https://'. $network->admin_hostname . '/signin-admin' . '?' . http_build_query($params);
1 www 127
            } else {
128
                $link_admin = '';
129
            }
130
 
131
            $data = [
132
                'success' => true,
133
                'data' => $link_admin
134
            ];
135
 
136
            return new JsonModel($data);
137
 
138
        } else {
139
            $data = [
140
                'success' => false,
141
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
142
            ];
143
 
144
            return new JsonModel($data);
145
        }
146
 
147
        return new JsonModel($data);
148
 
149
 
150
    }
151
 
152
    public function signinCompanyAction()
153
    {
154
 
155
        $request = $this->getRequest();
156
        if($request->isGet()) {
157
 
158
 
159
            $currentUserPlugin = $this->plugin('currentUserPlugin');
160
            $currentUser = $currentUserPlugin->getUser();
3639 efrain 161
 
1 www 162
 
163
            $id = $this->params()->fromRoute('id');
4398 efrain 164
            $type = $this->params()->fromRoute('type');
165
            $relational = $this->params()->fromRoute('relational');
166
 
167
 
168
 
1 www 169
            $companyMapper = CompanyMapper::getInstance($this->adapter);
170
            $company = $companyMapper->fetchOneByUuid($id);
171
 
172
            $link_admin = '';
173
 
174
            if($company) {
175
 
3639 efrain 176
                $networkMapper = NetworkMapper::getInstance($this->adapter);
177
                $network = $networkMapper->fetchOne($currentUser->network_id);
178
 
1 www 179
                $companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
180
                $companyUser = $companyUserMapper->fetchOneByCompanyIdAndUserId($company->id, $currentUser->id);
181
 
182
                if($companyUser && $companyUser->status == CompanyUser::STATUS_ACCEPTED && $companyUser->backend == CompanyUser::BACKEND_YES ) {
183
                    if(!$currentUser->one_time_password) {
184
                        $one_time_password = Functions::generatePassword(25);
185
 
186
                        $currentUser->one_time_password = $one_time_password;
187
 
188
                        $userMapper = UserMapper::getInstance($this->adapter);
189
                        $userMapper->updateOneTimePassword($currentUser, $one_time_password);
190
                    }
191
 
192
 
193
                    $sandbox = $this->config['leaderslinked.runmode.sandbox'];
194
                    if($sandbox) {
195
                        $salt = $this->config['leaderslinked.backend.sandbox_salt'];
196
                    } else {
197
                        $salt = $this->config['leaderslinked.backend.production_salt'];
198
                    }
4398 efrain 199
 
200
                    if($relational && $type) {
201
                        switch($type)
202
                        {
7340 efrain 203
                            case CalendarEvent::TYPE_SURVEY_NORMAL :
204
                            case CalendarEvent::TYPE_SURVEY_ORGANIZATIONAL_CLIMATE :
205
                                $surveyTestMapper = SurveyTestMapper::getInstance($this->adapter);
206
                                $surveyTest = $surveyTestMapper->fetchOneByUuid($relational);
207
                                if( $surveyTest) {
208
 
209
 
210
                                    if( $surveyTest->user_id != $currentUser->id) {
211
                                        $data = [
212
                                            'success' => false,
213
                                            'data' => 'ERROR_BACKEND_COMPANY_RELATIONAL_RECORD_UNAUTHORIZE'
214
                                        ];
215
 
216
                                        return new JsonModel($data);
217
                                    }
218
 
219
                                } else {
220
                                    $data = [
221
                                        'success' => false,
222
                                        'data' => 'ERROR_BACKEND_COMPANY_RELATIONAL_RECORD_NOT_FOUND'
223
                                    ];
224
 
225
                                    return new JsonModel($data);
226
                                }
227
 
228
                                break;
229
 
230
 
5050 efrain 231
                            case CalendarEvent::TYPE_RECRUITMENT_SELECTION_INTERVIEW :
232
                                $recruitmentSelectionInterviewMapper = RecruitmentSelectionInterviewMapper::getInstance($this->adapter);
233
                                $recruitmentSelectionInterview =  $recruitmentSelectionInterviewMapper->fetchOneByUuid($relational);
234
                                if( $recruitmentSelectionInterview) {
235
 
236
 
237
                                    if( $recruitmentSelectionInterview->interviewer_id != $currentUser->id) {
238
                                            $data = [
239
                                                'success' => false,
240
                                                'data' => 'ERROR_BACKEND_COMPANY_RELATIONAL_RECORD_UNAUTHORIZE'
241
                                            ];
242
 
243
                                            return new JsonModel($data);
244
                                        }
245
 
246
                                } else {
247
                                    $data = [
248
                                        'success' => false,
249
                                        'data' => 'ERROR_BACKEND_COMPANY_RELATIONAL_RECORD_NOT_FOUND'
250
                                    ];
251
 
252
                                    return new JsonModel($data);
253
                                }
254
 
255
                                break;
256
 
257
 
258
 
4398 efrain 259
                            case CalendarEvent::TYPE_PERFORMANCE_EVALUATION :
4656 efrain 260
                                $performanceEvaluationTestMapper = PerformanceEvaluationTestMapper::getInstance($this->adapter);
261
                                $performanceEvaluationTest = $performanceEvaluationTestMapper->fetchOneByUuid($relational);
262
                                if($performanceEvaluationTest) {
4398 efrain 263
 
264
 
4656 efrain 265
                                    if($performanceEvaluationTest->employee_id != $currentUser->id
266
                                        && $performanceEvaluationTest->supervisor_id != $currentUser->id) {
4398 efrain 267
                                            $data = [
268
                                                'success' => false,
269
                                                'data' => 'ERROR_BACKEND_COMPANY_RELATIONAL_RECORD_UNAUTHORIZE'
270
                                            ];
271
 
272
                                            return new JsonModel($data);
273
                                    }
274
 
275
                                } else {
276
                                    $data = [
277
                                        'success' => false,
278
                                        'data' => 'ERROR_BACKEND_COMPANY_RELATIONAL_RECORD_NOT_FOUND'
279
                                    ];
280
 
281
                                    return new JsonModel($data);
282
                                }
283
 
284
                                break;
285
 
286
                            default :
287
                                $data = [
288
                                    'success' => false,
289
                                    'data' => 'ERROR_BACKEND_COMPANY_RELATIONAL_TYPE_NOT_FOUND'
290
                                ];
291
 
292
                                return new JsonModel($data);
293
 
294
 
295
                        }
296
                    }
1 www 297
 
298
 
3639 efrain 299
                    $timestamp = date('Y-m-d\TH:i:s');
300
                    $rand = 1000 + rand(1, 8999);
301
 
302
 
303
 
1 www 304
                    $rand = 1000 + mt_rand(1, 999);
305
                    $timestamp = time();
306
                    $password = md5($currentUser->one_time_password . '-' . $rand . '-' . $timestamp . '-' . $salt);
307
 
3639 efrain 308
                    $params = [
309
                        'user_uuid' => $currentUser->uuid,
310
                        'password' => $password,
311
                        'rand' => $rand,
312
                        'time' => $timestamp,
313
                        'company_uuid' => $company->uuid
4398 efrain 314
 
3639 efrain 315
                    ];
1 www 316
 
4398 efrain 317
                    if($relational && $type) {
318
                        $params['relational'] = $relational;
319
                        $params['type'] = $type;
320
                    }
321
 
3639 efrain 322
                    $link_admin = 'https://'. $network->admin_hostname . '/signin-company' . '?' . http_build_query($params);
323
               }
1 www 324
 
325
 
326
 
327
            }
328
 
329
 
330
 
331
            $data = [
332
                'success' => true,
333
                'data' => $link_admin
334
            ];
335
 
336
            return new JsonModel($data);
337
 
338
        } else {
339
            $data = [
340
                'success' => false,
341
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
342
            ];
343
 
344
            return new JsonModel($data);
345
        }
346
 
347
        return new JsonModel($data);
348
 
349
 
350
    }
351
 
352
 
353
}