Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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