Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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