Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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