Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 6803 | Rev 6823 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 6803 Rev 6821
Línea 1... Línea 1...
1
<?php
1
<?php
-
 
2
 
2
declare(strict_types=1);
3
declare(strict_types=1);
Línea 3... Línea 4...
3
 
4
 
Línea 4... Línea 5...
4
namespace LeadersLinked\Controller;
5
namespace LeadersLinked\Controller;
5
 
6
 
Línea 6... Línea 7...
6
use Nullix\CryptoJsAes\CryptoJsAes;
7
use Nullix\CryptoJsAes\CryptoJsAes;
7
use GeoIp2\Database\Reader As GeoIp2Reader;
8
use GeoIp2\Database\Reader as GeoIp2Reader;
8
 
9
 
9
use Laminas\Authentication\AuthenticationService;
10
use Laminas\Authentication\AuthenticationService;
Línea 55... Línea 56...
55
    /**
56
    /**
56
     *
57
     *
57
     * @var AdapterInterface
58
     * @var AdapterInterface
58
     */
59
     */
59
    private $adapter;
60
    private $adapter;
60
    
61
 
61
    
62
 
62
    /**
63
    /**
63
     *
64
     *
64
     * @var CacheInterface
65
     * @var CacheInterface
65
     */
66
     */
66
    private $cache;
67
    private $cache;
67
    
68
 
68
    /**
69
    /**
69
     *
70
     *
70
     * @var  LoggerInterface
71
     * @var  LoggerInterface
71
     */
72
     */
72
    private $logger;
73
    private $logger;
Línea 74... Línea 75...
74
    /**
75
    /**
75
     * 
76
     * 
76
     * @var array
77
     * @var array
77
     */
78
     */
78
    private $config;
79
    private $config;
79
    
80
 
80
    
81
 
81
    
82
 
82
    
83
 
83
    /**
84
    /**
84
     * 
85
     * 
85
     * @param AdapterInterface $adapter
86
     * @param AdapterInterface $adapter
86
     * @param CacheInterface $cache
87
     * @param CacheInterface $cache
87
     * @param LoggerInterface $logger
88
     * @param LoggerInterface $logger
88
     * @param array $config
89
     * @param array $config
89
     */
90
     */
90
    public function __construct($adapter, $cache , $logger, $config)
91
    public function __construct($adapter, $cache, $logger, $config)
91
    {
92
    {
92
        $this->adapter      = $adapter;
93
        $this->adapter      = $adapter;
93
        $this->cache        = $cache;
94
        $this->cache        = $cache;
94
        $this->logger       = $logger;
95
        $this->logger       = $logger;
95
        $this->config       = $config;
96
        $this->config       = $config;
96
    }
97
    }
97
    
98
 
98
    public function signinAction()
99
    public function signinAction()
99
    {
100
    {
100
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
101
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
101
        $currentNetwork = $currentNetworkPlugin->getNetwork();
102
        $currentNetwork = $currentNetworkPlugin->getNetwork();
102
        
103
 
103
        $request = $this->getRequest();
104
        $request = $this->getRequest();
104
        
105
 
105
        if($request->isPost()) {
106
        if ($request->isPost()) {
106
            $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
107
            $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
107
            $currentNetwork = $currentNetworkPlugin->getNetwork();
108
            $currentNetwork = $currentNetworkPlugin->getNetwork();
Línea 108... Línea 109...
108
 
109
 
109
            
110
 
110
            $form = new  SigninForm($this->config);
111
            $form = new  SigninForm($this->config);
111
            $dataPost = $request->getPost()->toArray();
112
            $dataPost = $request->getPost()->toArray();
112
            
113
 
113
            if(empty($_SESSION['aes'])) {
114
            if (empty($_SESSION['aes'])) {
114
                return new JsonModel([
115
                return new JsonModel([
115
                    'success'   => false,
116
                    'success'   => false,
116
                    'data'      => 'ERROR_WEBSERVICE_ENCRYPTION_KEYS_NOT_FOUND'
117
                    'data'      => 'ERROR_WEBSERVICE_ENCRYPTION_KEYS_NOT_FOUND'
117
                ]);
118
                ]);
118
            }
119
            }
119
            
120
 
120
            if(!empty( $dataPost['email'])) {
121
            if (!empty($dataPost['email'])) {
121
                $dataPost['email'] = CryptoJsAes::decrypt( $dataPost['email'], $_SESSION['aes']);
122
                $dataPost['email'] = CryptoJsAes::decrypt($dataPost['email'], $_SESSION['aes']);
122
            }
123
            }
123
            
124
 
124
            
125
 
125
            if(!empty( $dataPost['password'])) {
126
            if (!empty($dataPost['password'])) {
126
                $dataPost['password'] = CryptoJsAes::decrypt( $dataPost['password'], $_SESSION['aes']);
127
                $dataPost['password'] = CryptoJsAes::decrypt($dataPost['password'], $_SESSION['aes']);
127
            }
128
            }
128
            
129
 
129
            $form->setData($dataPost);
130
            $form->setData($dataPost);
130
            
131
 
131
            if($form->isValid()) {
132
            if ($form->isValid()) {
132
                $dataPost = (array) $form->getData();
133
                $dataPost = (array) $form->getData();
133
                
134
 
134
                $email      = $dataPost['email'];
135
                $email      = $dataPost['email'];
135
                $password   = $dataPost['password'];
136
                $password   = $dataPost['password'];
136
                $remember   = $dataPost['remember'];
137
                $remember   = $dataPost['remember'];
137
                
138
 
138
                $authAdapter = new AuthAdapter($this->adapter, $this->logger);
139
                $authAdapter = new AuthAdapter($this->adapter, $this->logger);
139
                $authAdapter->setData($email, $password, $currentNetwork->id);
140
                $authAdapter->setData($email, $password, $currentNetwork->id);
140
                $authService = new AuthenticationService();
141
                $authService = new AuthenticationService();
141
                
142
 
-
 
143
                $result = $authService->authenticate($authAdapter);
142
                $result = $authService->authenticate($authAdapter);
144
 
-
 
145
 
-
 
146
                $sandbox = $this->config['leaderslinked.runmode.sandbox'];
-
 
147
                if ($sandbox) {
-
 
148
                    $google_map_key  = $this->config['leaderslinked.google_map.sandbox_api_key'];
-
 
149
                } else {
-
 
150
                    $google_map_key  = $this->config['leaderslinked.google_map.production_api_key'];
-
 
151
                }
143
   
152
 
144
                if($result->getCode() == AuthResult::SUCCESS) {
153
                if ($result->getCode() == AuthResult::SUCCESS) {
145
                    
154
 
146
                    
155
 
147
                    $userMapper = UserMapper::getInstance($this->adapter);
156
                    $userMapper = UserMapper::getInstance($this->adapter);
148
                    $user = $userMapper->fetchOneByEmail($email);
157
                    $user = $userMapper->fetchOneByEmail($email);
149
                    
158
 
150
                    $navigator = get_browser(null, true);
159
                    $navigator = get_browser(null, true);
151
                    $device_type    =  isset($navigator['device_type']) ? $navigator['device_type'] : '';
160
                    $device_type    =  isset($navigator['device_type']) ? $navigator['device_type'] : '';
152
                    $platform       =  isset($navigator['platform']) ? $navigator['platform'] : '';
161
                    $platform       =  isset($navigator['platform']) ? $navigator['platform'] : '';
153
                    $browser        =  isset($navigator['browser']) ? $navigator['browser'] : '';
162
                    $browser        =  isset($navigator['browser']) ? $navigator['browser'] : '';
154
                    
163
 
155
                    
164
 
156
                    $istablet = isset($navigator['istablet']) ?  intval( $navigator['istablet']) : 0;
165
                    $istablet = isset($navigator['istablet']) ?  intval($navigator['istablet']) : 0;
157
                    $ismobiledevice = isset($navigator['ismobiledevice']) ? intval( $navigator['ismobiledevice']) : 0;
166
                    $ismobiledevice = isset($navigator['ismobiledevice']) ? intval($navigator['ismobiledevice']) : 0;
158
                    $version = isset($navigator['version']) ? $navigator['version'] : '';
167
                    $version = isset($navigator['version']) ? $navigator['version'] : '';
159
                    
168
 
160
                    
169
 
161
                    $userBrowserMapper = UserBrowserMapper::getInstance($this->adapter);
170
                    $userBrowserMapper = UserBrowserMapper::getInstance($this->adapter);
162
                    $userBrowser = $userBrowserMapper->fetch($user->id, $device_type, $platform, $browser);
171
                    $userBrowser = $userBrowserMapper->fetch($user->id, $device_type, $platform, $browser);
163
                    if($userBrowser) {
172
                    if ($userBrowser) {
164
                        $userBrowserMapper->update($userBrowser);
173
                        $userBrowserMapper->update($userBrowser);
165
                    } else {
174
                    } else {
166
                        $userBrowser = new UserBrowser();
175
                        $userBrowser = new UserBrowser();
167
                        $userBrowser->user_id           = $user->id;
176
                        $userBrowser->user_id           = $user->id;
168
                        $userBrowser->browser           = $browser;
177
                        $userBrowser->browser           = $browser;
169
                        $userBrowser->platform          = $platform;
178
                        $userBrowser->platform          = $platform;
170
                        $userBrowser->device_type       = $device_type;
179
                        $userBrowser->device_type       = $device_type;
171
                        $userBrowser->is_tablet         = $istablet;
180
                        $userBrowser->is_tablet         = $istablet;
172
                        $userBrowser->is_mobile_device  = $ismobiledevice;
181
                        $userBrowser->is_mobile_device  = $ismobiledevice;
173
                        $userBrowser->version           = $version;
182
                        $userBrowser->version           = $version;
174
                        
183
 
175
                        $userBrowserMapper->insert($userBrowser);
184
                        $userBrowserMapper->insert($userBrowser);
176
                    }
185
                    }
177
                    //
186
                    //
178
                    
187
 
179
                    $ip = Functions::getUserIP();
188
                    $ip = Functions::getUserIP();
180
                    $ip = $ip == '127.0.0.1' ? '148.240.211.148' : $ip;
189
                    $ip = $ip == '127.0.0.1' ? '148.240.211.148' : $ip;
181
                    
190
 
182
                    $userIpMapper = UserIpMapper::getInstance($this->adapter);
191
                    $userIpMapper = UserIpMapper::getInstance($this->adapter);
183
                    $userIp = $userIpMapper->fetch($user->id, $ip);
192
                    $userIp = $userIpMapper->fetch($user->id, $ip);
184
                    if(empty($userIp)) {
193
                    if (empty($userIp)) {
185
                        
194
 
186
                        if($this->config['leaderslinked.runmode.sandbox']) {
195
                        if ($this->config['leaderslinked.runmode.sandbox']) {
187
                            $filename = $this->config['leaderslinked.geoip2.production_database'];
196
                            $filename = $this->config['leaderslinked.geoip2.production_database'];
188
                        } else {
197
                        } else {
189
                            $filename = $this->config['leaderslinked.geoip2.sandbox_database'];
198
                            $filename = $this->config['leaderslinked.geoip2.sandbox_database'];
190
                        }
199
                        }
191
                        
200
 
192
                        $reader = new GeoIp2Reader($filename); //GeoIP2-City.mmdb');
201
                        $reader = new GeoIp2Reader($filename); //GeoIP2-City.mmdb');
193
                        $record = $reader->city($ip);
202
                        $record = $reader->city($ip);
194
                        if($record) {
203
                        if ($record) {
195
                            $userIp = new UserIp();
204
                            $userIp = new UserIp();
196
                            $userIp->user_id = $user->id;
205
                            $userIp->user_id = $user->id;
197
                            $userIp->city = !empty($record->city->name) ? utf8_decode($record->city->name) : '';
206
                            $userIp->city = !empty($record->city->name) ? utf8_decode($record->city->name) : '';
198
                            $userIp->state_code = !empty($record->mostSpecificSubdivision->isoCode) ? utf8_decode($record->mostSpecificSubdivision->isoCode) : '';
207
                            $userIp->state_code = !empty($record->mostSpecificSubdivision->isoCode) ? utf8_decode($record->mostSpecificSubdivision->isoCode) : '';
Línea 201... Línea 210...
201
                            $userIp->country_name = !empty($record->country->name) ? utf8_decode($record->country->name) : '';
210
                            $userIp->country_name = !empty($record->country->name) ? utf8_decode($record->country->name) : '';
202
                            $userIp->ip = $ip;
211
                            $userIp->ip = $ip;
203
                            $userIp->latitude = !empty($record->location->latitude) ? $record->location->latitude : 0;
212
                            $userIp->latitude = !empty($record->location->latitude) ? $record->location->latitude : 0;
204
                            $userIp->longitude = !empty($record->location->longitude) ? $record->location->longitude : 0;
213
                            $userIp->longitude = !empty($record->location->longitude) ? $record->location->longitude : 0;
205
                            $userIp->postal_code = !empty($record->postal->code) ? $record->postal->code : '';
214
                            $userIp->postal_code = !empty($record->postal->code) ? $record->postal->code : '';
206
                            
215
 
207
                            $userIpMapper->insert($userIp);
216
                            $userIpMapper->insert($userIp);
208
                        }
217
                        }
209
                        
-
 
210
 
-
 
211
                    } else {
218
                    } else {
212
                        $userIpMapper->update($userIp);
219
                        $userIpMapper->update($userIp);
213
                    }
220
                    }
Línea 214... Línea 221...
214
 
221
 
215
                    if($remember) {
222
                    if ($remember) {
216
                        $expired = time() + 365 * 24 * 60 * 60;
223
                        $expired = time() + 365 * 24 * 60 * 60;
217
                        
224
 
218
                        $cookieEmail = new SetCookie('email', $email, $expired);
-
 
219
                        
225
                        $cookieEmail = new SetCookie('email', $email, $expired);
220
                    } else {
226
                    } else {
221
                        $expired = time() - 7200;
227
                        $expired = time() - 7200;
222
                        $cookieEmail = new SetCookie('email', '', $expired);
-
 
223
                        
228
                        $cookieEmail = new SetCookie('email', '', $expired);
224
                    }
229
                    }
225
                    
230
 
226
                    
231
 
227
                    $response = $this->getResponse();
232
                    $response = $this->getResponse();
228
                    $response->getHeaders()->addHeader($cookieEmail);
233
                    $response->getHeaders()->addHeader($cookieEmail);
229
                    
234
 
230
                    
235
 
231
                    
236
 
232
                    
237
 
233
                    
238
 
234
                    
239
 
235
                    
240
 
236
                    $this->logger->info('Ingreso a LeadersLiked', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
241
                    $this->logger->info('Ingreso a LeadersLiked', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
237
                    
242
 
238
                    $user_share_invitation = $this->cache->get('user_share_invitation');
243
                    $user_share_invitation = $this->cache->get('user_share_invitation');
239
                    
244
 
240
                    if($user_share_invitation) {
245
                    if ($user_share_invitation) {
241
                        $userRedirect = $userMapper->fetchOneByUuid($user_share_invitation);
246
                        $userRedirect = $userMapper->fetchOneByUuid($user_share_invitation);
242
                        if($userRedirect && $userRedirect->status == User::STATUS_ACTIVE && $user->id != $userRedirect->id) {
247
                        if ($userRedirect && $userRedirect->status == User::STATUS_ACTIVE && $user->id != $userRedirect->id) {
243
                            $connectionMapper = ConnectionMapper::getInstance($this->adapter);
248
                            $connectionMapper = ConnectionMapper::getInstance($this->adapter);
244
                            $connection = $connectionMapper->fetchOneByUserId1AndUserId2($user->id, $userRedirect->id);
249
                            $connection = $connectionMapper->fetchOneByUserId1AndUserId2($user->id, $userRedirect->id);
245
                            
250
 
246
                            if($connection) {
251
                            if ($connection) {
247
                                
252
 
248
                                if($connection->status != Connection::STATUS_ACCEPTED) {
253
                                if ($connection->status != Connection::STATUS_ACCEPTED) {
249
                                    $connectionMapper->approve($connection);
254
                                    $connectionMapper->approve($connection);
250
                                }
-
 
251
                                
255
                                }
252
                            } else {
256
                            } else {
253
                                $connection = new Connection();
257
                                $connection = new Connection();
254
                                $connection->request_from = $user->id;
258
                                $connection->request_from = $user->id;
255
                                $connection->request_to = $userRedirect->id;
259
                                $connection->request_to = $userRedirect->id;
256
                                $connection->status = Connection::STATUS_ACCEPTED;
260
                                $connection->status = Connection::STATUS_ACCEPTED;
257
                                
261
 
258
                                $connectionMapper->insert($connection);
262
                                $connectionMapper->insert($connection);
259
                            }
263
                            }
260
                        }
264
                        }
261
                    }
265
                    }
262
                    
266
 
263
                    
267
 
264
                    
268
 
265
                    $data = [
269
                    $data = [
266
                        'success'   => true,
270
                        'success'   => true,
267
                        'data'      => $this->url()->fromRoute('dashboard'),
271
                        'data'      => $this->url()->fromRoute('dashboard'),
268
                    ];
272
                    ];
269
                   
273
 
270
                    $this->cache->delete('user_share_invitation');
-
 
271
                    
-
 
272
                 
274
                    $this->cache->delete('user_share_invitation');
273
                } else {
275
                } else {
274
                    
276
 
-
 
277
                    $message = $result->getMessages()[0];
275
                    $message = $result->getMessages()[0];
278
                    if (!in_array($message, [
276
                    if(!in_array($message, ['ERROR_USER_NOT_FOUND', 'ERROR_USER_EMAIL_HASNT_BEEN_VARIFIED', 'ERROR_USER_IS_BLOCKED',
279
                        'ERROR_USER_NOT_FOUND', 'ERROR_USER_EMAIL_HASNT_BEEN_VARIFIED', 'ERROR_USER_IS_BLOCKED',
277
                        'ERROR_USER_IS_INACTIVE', 'ERROR_ENTERED_PASS_INCORRECT_USER_IS_BLOCKED', 'ERROR_ENTERED_PASS_INCORRECT_2',
280
                        'ERROR_USER_IS_INACTIVE', 'ERROR_ENTERED_PASS_INCORRECT_USER_IS_BLOCKED', 'ERROR_ENTERED_PASS_INCORRECT_2',
278
                        'ERROR_ENTERED_PASS_INCORRECT_1', 'ERROR_USER_REQUEST_ACCESS_IS_PENDING', 'ERROR_USER_REQUEST_ACCESS_IS_REJECTED' 
281
                        'ERROR_ENTERED_PASS_INCORRECT_1', 'ERROR_USER_REQUEST_ACCESS_IS_PENDING', 'ERROR_USER_REQUEST_ACCESS_IS_REJECTED'
279
                        
282
 
280
                        
283
 
281
                    ])) {
-
 
282
                        
-
 
283
                        
284
                    ])) {
284
                    }
285
                    }
285
                    
286
 
286
                    switch($message) 
-
 
287
                    {
287
                    switch ($message) {
288
                        case 'ERROR_USER_NOT_FOUND' : 
288
                        case 'ERROR_USER_NOT_FOUND':
289
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Email no existe', ['ip' => Functions::getUserIP()]);
289
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Email no existe', ['ip' => Functions::getUserIP()]);
290
                            break;
290
                            break;
291
                            
291
 
292
                        case 'ERROR_USER_EMAIL_HASNT_BEEN_VARIFIED' : 
292
                        case 'ERROR_USER_EMAIL_HASNT_BEEN_VARIFIED':
293
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Email no verificado', ['ip' => Functions::getUserIP()]);
293
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Email no verificado', ['ip' => Functions::getUserIP()]);
294
                            break;
294
                            break;
295
                            
295
 
296
                        case 'ERROR_USER_IS_BLOCKED' : 
296
                        case 'ERROR_USER_IS_BLOCKED':
297
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Usuario bloqueado', ['ip' => Functions::getUserIP()]);
297
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Usuario bloqueado', ['ip' => Functions::getUserIP()]);
298
                            break;
298
                            break;
299
                            
299
 
300
                        case 'ERROR_USER_IS_INACTIVE' :  
300
                        case 'ERROR_USER_IS_INACTIVE':
301
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Usuario inactivo', ['ip' => Functions::getUserIP()]);
301
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Usuario inactivo', ['ip' => Functions::getUserIP()]);
302
                            break;
302
                            break;
303
                            
303
 
304
                            
304
 
305
                        case 'ERROR_ENTERED_PASS_INCORRECT_USER_IS_BLOCKED': 
305
                        case 'ERROR_ENTERED_PASS_INCORRECT_USER_IS_BLOCKED':
306
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - 3er Intento Usuario bloqueado', ['ip' => Functions::getUserIP()]);
306
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - 3er Intento Usuario bloqueado', ['ip' => Functions::getUserIP()]);
307
                            break;
307
                            break;
308
                            
308
 
309
                            
309
 
310
                        case 'ERROR_ENTERED_PASS_INCORRECT_2' : 
310
                        case 'ERROR_ENTERED_PASS_INCORRECT_2':
311
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - 1er Intento', ['ip' => Functions::getUserIP()]);
311
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - 1er Intento', ['ip' => Functions::getUserIP()]);
312
                            break;
312
                            break;
313
                            
313
 
314
                            
314
 
315
                        case 'ERROR_ENTERED_PASS_INCORRECT_1' : 
315
                        case 'ERROR_ENTERED_PASS_INCORRECT_1':
316
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - 2do Intento', ['ip' => Functions::getUserIP()]);
316
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - 2do Intento', ['ip' => Functions::getUserIP()]);
317
                            break;
317
                            break;
318
                            
318
 
319
                            
319
 
320
                        case 'ERROR_USER_REQUEST_ACCESS_IS_PENDING' :
320
                        case 'ERROR_USER_REQUEST_ACCESS_IS_PENDING':
321
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Falta verificar que pertence a la Red Privada', ['ip' => Functions::getUserIP()]);
321
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Falta verificar que pertence a la Red Privada', ['ip' => Functions::getUserIP()]);
322
                            break;
322
                            break;
323
                            
323
 
324
                        case  'ERROR_USER_REQUEST_ACCESS_IS_REJECTED' :
324
                        case  'ERROR_USER_REQUEST_ACCESS_IS_REJECTED':
325
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Rechazado por no pertence a la Red Privada', ['ip' => Functions::getUserIP()]);
325
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Rechazado por no pertence a la Red Privada', ['ip' => Functions::getUserIP()]);
326
                            break;
326
                            break;
327
                            
327
 
328
                            
328
 
329
                        default :     
329
                        default:
330
                            $message = 'ERROR_UNKNOWN';
330
                            $message = 'ERROR_UNKNOWN';
331
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Error desconocido', ['ip' => Functions::getUserIP()]);
331
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Error desconocido', ['ip' => Functions::getUserIP()]);
332
                            break;
-
 
333
                            
-
 
334
 
332
                            break;
335
                    }
333
                    }
336
                    
334
 
337
                    
335
 
338
                    
336
 
339
                    
337
 
340
                    $data = [
338
                    $data = [
341
                        'success'   => false,
339
                        'success'   => false,
342
                        'data'   => $message
340
                        'data'   => $message
343
                    ];
-
 
344
                    
341
                    ];
345
                }
342
                }
346
                
343
 
347
                return new JsonModel($data);
-
 
348
                
344
                return new JsonModel($data);
349
            } else {
345
            } else {
350
                $messages = [];
346
                $messages = [];
351
                
347
 
352
                
348
 
353
                
349
 
354
                $form_messages = (array) $form->getMessages();
350
                $form_messages = (array) $form->getMessages();
355
                foreach($form_messages  as $fieldname => $field_messages)
-
 
356
                {
351
                foreach ($form_messages  as $fieldname => $field_messages) {
357
                    
352
 
358
                    $messages[$fieldname] = array_values($field_messages);
353
                    $messages[$fieldname] = array_values($field_messages);
359
                }
354
                }
360
                
355
 
361
                return new JsonModel([
356
                return new JsonModel([
362
                    'success'   => false,
357
                    'success'   => false,
363
                    'data'   => $messages
358
                    'data'   => $messages
364
                ]);
359
                ]);
365
            }
360
            }
366
        } else if($request->isGet())  {
361
        } else if ($request->isGet()) {
367
            
362
 
368
            if(empty($_SESSION['aes'])) {
363
            if (empty($_SESSION['aes'])) {
369
                $_SESSION['aes'] = Functions::generatePassword(16);
364
                $_SESSION['aes'] = Functions::generatePassword(16);
370
            }
365
            }
371
            
366
 
372
            if($this->config['leaderslinked.runmode.sandbox']) {
367
            if ($this->config['leaderslinked.runmode.sandbox']) {
373
                $site_key      = $this->config['leaderslinked.google_captcha.sandbox_site_key'];
368
                $site_key      = $this->config['leaderslinked.google_captcha.sandbox_site_key'];
374
            } else {
369
            } else {
375
                $site_key      = $this->config['leaderslinked.google_captcha.production_site_key'];
370
                $site_key      = $this->config['leaderslinked.google_captcha.production_site_key'];
376
            }
371
            }
377
            
372
 
378
            $headers  = $request->getHeaders();
373
            $headers  = $request->getHeaders();
379
            $isJson = false;
374
            $isJson = false;
380
            if($headers->has('Accept')) {
375
            if ($headers->has('Accept')) {
381
                $accept = $headers->get('Accept');
376
                $accept = $headers->get('Accept');
382
                
377
 
383
                $prioritized = $accept->getPrioritized();
378
                $prioritized = $accept->getPrioritized();
384
                
379
 
385
                foreach($prioritized as $key => $value) {
380
                foreach ($prioritized as $key => $value) {
386
                    $raw = trim($value->getRaw());
381
                    $raw = trim($value->getRaw());
387
                    
382
 
388
                    if(!$isJson) {
383
                    if (!$isJson) {
389
                        $isJson = strpos($raw, 'json');
384
                        $isJson = strpos($raw, 'json');
390
                    }
-
 
391
                    
385
                    }
392
                }
386
                }
393
            }
387
            }
394
            
388
 
395
            $email      = isset($_COOKIE['email']) ? $_COOKIE['email'] : '';
389
            $email      = isset($_COOKIE['email']) ? $_COOKIE['email'] : '';
396
            $remember   = $email ? true : false;
390
            $remember   = $email ? true : false;
397
            $access_usign_social_networks = $this->config['leaderslinked.runmode.access_usign_social_networks'];
391
            $access_usign_social_networks = $this->config['leaderslinked.runmode.access_usign_social_networks'];
398
            
392
 
399
            if($isJson) {
393
            if ($isJson) {
400
                
394
 
401
                
395
 
402
                
396
 
-
 
397
                $data = [
403
                $data = [
398
                    'google_map_key'    => $google_map_key,
404
                    'email'     => $email,
399
                    'email'     => $email,
405
                    'remember'  => $remember,
400
                    'remember'  => $remember,
406
                    'site_key'  => $site_key,
401
                    'site_key'  => $site_key,
407
                    'theme_id'  => $currentNetwork->theme_id,
402
                    'theme_id'  => $currentNetwork->theme_id,
Línea 410... Línea 405...
410
                    'access_usign_social_networks' => $access_usign_social_networks && $currentNetwork->default == Network::DEFAULT_YES ? 'y' : 'n',
405
                    'access_usign_social_networks' => $access_usign_social_networks && $currentNetwork->default == Network::DEFAULT_YES ? 'y' : 'n',
411
                    'logo_url' => $this->url()->fromRoute('storage-network', ['type' => 'logo']),
406
                    'logo_url' => $this->url()->fromRoute('storage-network', ['type' => 'logo']),
412
                    'navbar_url' => $this->url()->fromRoute('storage-network', ['type' => 'navbar']),
407
                    'navbar_url' => $this->url()->fromRoute('storage-network', ['type' => 'navbar']),
413
                    'favico_url' => $this->url()->fromRoute('storage-network', ['type' => 'favico']),
408
                    'favico_url' => $this->url()->fromRoute('storage-network', ['type' => 'favico']),
414
                    'intro' => $currentNetwork->intro
409
                    'intro' => $currentNetwork->intro
415
                    
410
 
416
                ];
411
                ];
417
                
-
 
418
                
-
 
419
            } else {
412
            } else {
420
                $form = new SigninForm($this->config);
413
                $form = new SigninForm($this->config);
421
                $form->setData([
414
                $form->setData([
422
                    'email'     => $email,
415
                    'email'     => $email,
423
                    'remember'  => $remember,
416
                    'remember'  => $remember,
Línea 430... Línea 423...
430
                    'site_key'  => $site_key,
423
                    'site_key'  => $site_key,
431
                    'aes'       => $_SESSION['aes'],
424
                    'aes'       => $_SESSION['aes'],
432
                    'defaultNetwork' => $currentNetwork->default,
425
                    'defaultNetwork' => $currentNetwork->default,
433
                    'access_usign_social_networks' => $access_usign_social_networks && $currentNetwork->default == Network::DEFAULT_YES ? 'y' : 'n',
426
                    'access_usign_social_networks' => $access_usign_social_networks && $currentNetwork->default == Network::DEFAULT_YES ? 'y' : 'n',
434
                ]);
427
                ]);
435
                
-
 
436
                return $viewModel ;
-
 
437
            }
-
 
438
            
-
 
439
 
-
 
Línea -... Línea 428...
-
 
428
 
440
 
429
                return $viewModel;
441
            
430
            }
442
        } else {
431
        } else {
443
            $data = [
432
            $data = [
444
                'success' => false,
433
                'success' => false,
445
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
434
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
446
            ];
435
            ];
447
            
436
 
448
            return new JsonModel($data);
437
            return new JsonModel($data);
Línea 449... Línea 438...
449
        }
438
        }
450
 
-
 
451
        return new JsonModel($data);
439
 
452
        
440
        return new JsonModel($data);
453
    }
441
    }
454
    
442
 
Línea 455... Línea 443...
455
    public function facebookAction()
443
    public function facebookAction()
456
    {
444
    {
Línea 508... Línea 496...
508
                'success' => false,
496
                'success' => false,
509
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
497
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
510
            ]);
498
            ]);
511
        }
499
        }
512
    }
500
    }
513
    
501
 
514
    public function twitterAction()
502
    public function twitterAction()
515
    {
503
    {
516
        $request = $this->getRequest();
504
        $request = $this->getRequest();
517
        if($request->isGet()) {
505
        if ($request->isGet()) {
518
            
506
 
519
            try {
507
            try {
520
                if($this->config['leaderslinked.runmode.sandbox']) {
508
                if ($this->config['leaderslinked.runmode.sandbox']) {
521
                    
509
 
522
                    $twitter_api_key = $this->config['leaderslinked.twitter.sandbox_api_key'];
510
                    $twitter_api_key = $this->config['leaderslinked.twitter.sandbox_api_key'];
523
                    $twitter_api_secret = $this->config['leaderslinked.twitter.sandbox_api_secret'];
511
                    $twitter_api_secret = $this->config['leaderslinked.twitter.sandbox_api_secret'];
524
                    
-
 
525
                } else {
512
                } else {
526
                    $twitter_api_key = $this->config['leaderslinked.twitter.production_api_key'];
513
                    $twitter_api_key = $this->config['leaderslinked.twitter.production_api_key'];
527
                    $twitter_api_secret = $this->config['leaderslinked.twitter.production_api_secret'];
514
                    $twitter_api_secret = $this->config['leaderslinked.twitter.production_api_secret'];
528
                }
515
                }
529
                
516
 
530
                /*
517
                /*
531
                 echo '$twitter_api_key = ' . $twitter_api_key . PHP_EOL;
518
                 echo '$twitter_api_key = ' . $twitter_api_key . PHP_EOL;
532
                 echo '$twitter_api_secret = ' . $twitter_api_secret . PHP_EOL;
519
                 echo '$twitter_api_secret = ' . $twitter_api_secret . PHP_EOL;
533
                 exit;
520
                 exit;
534
                 */
521
                 */
535
                
522
 
536
                //Twitter
523
                //Twitter
537
                //$redirect_url =  $this->url()->fromRoute('oauth/twitter', [], ['force_canonical' => true]);
524
                //$redirect_url =  $this->url()->fromRoute('oauth/twitter', [], ['force_canonical' => true]);
538
                $redirect_url = $this->config['leaderslinked.twitter.app_redirect_url'];
525
                $redirect_url = $this->config['leaderslinked.twitter.app_redirect_url'];
539
                $twitter = new \Abraham\TwitterOAuth\TwitterOAuth($twitter_api_key, $twitter_api_secret);
526
                $twitter = new \Abraham\TwitterOAuth\TwitterOAuth($twitter_api_key, $twitter_api_secret);
540
                $request_token =  $twitter->oauth('oauth/request_token', ['oauth_callback' => $redirect_url ]);
527
                $request_token =  $twitter->oauth('oauth/request_token', ['oauth_callback' => $redirect_url]);
541
                $twitterUrl = $twitter->url('oauth/authorize', [ 'oauth_token' => $request_token['oauth_token'] ]);
528
                $twitterUrl = $twitter->url('oauth/authorize', ['oauth_token' => $request_token['oauth_token']]);
542
                
529
 
543
                $twitterSession = new \Laminas\Session\Container('twitter');
530
                $twitterSession = new \Laminas\Session\Container('twitter');
544
                $twitterSession->oauth_token = $request_token['oauth_token'];
531
                $twitterSession->oauth_token = $request_token['oauth_token'];
545
                $twitterSession->oauth_token_secret = $request_token['oauth_token_secret'];
532
                $twitterSession->oauth_token_secret = $request_token['oauth_token_secret'];
546
                
533
 
547
                return new JsonModel([
534
                return new JsonModel([
548
                    'success' => true,
535
                    'success' => true,
549
                    'data' =>  $twitterUrl
536
                    'data' =>  $twitterUrl
550
                ]);
537
                ]);
551
            } catch (\Throwable $e) {
538
            } catch (\Throwable $e) {
552
                return new JsonModel([
539
                return new JsonModel([
553
                    'success' => false,
540
                    'success' => false,
554
                    'data' =>  'ERROR_WE_COULD_NOT_CONNECT_TO_TWITTER'
541
                    'data' =>  'ERROR_WE_COULD_NOT_CONNECT_TO_TWITTER'
555
                ]);
542
                ]);
556
            }
543
            }
557
            
-
 
558
        } else {
544
        } else {
559
            return new JsonModel([
545
            return new JsonModel([
560
                'success' => false,
546
                'success' => false,
561
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
547
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
562
            ]);
548
            ]);
563
        }
549
        }
564
        
-
 
565
       
-
 
566
    }
550
    }
567
    
551
 
568
    public function googleAction()
552
    public function googleAction()
569
    {
553
    {
570
        $request = $this->getRequest();
554
        $request = $this->getRequest();
571
        if($request->isGet()) {
555
        if ($request->isGet()) {
572
            
556
 
573
            try {
557
            try {
574
                
558
 
575
                
559
 
576
                //Google
560
                //Google
577
                $google = new \Google_Client();
561
                $google = new \Google_Client();
578
                $google->setAuthConfig('data/google/auth-leaderslinked/apps.google.com_secreto_cliente.json');
562
                $google->setAuthConfig('data/google/auth-leaderslinked/apps.google.com_secreto_cliente.json');
579
                $google->setAccessType("offline");        // offline access
563
                $google->setAccessType("offline");        // offline access
580
                
564
 
581
                $google->setIncludeGrantedScopes(true);   // incremental auth
565
                $google->setIncludeGrantedScopes(true);   // incremental auth
582
                
566
 
583
                $google->addScope('profile');
567
                $google->addScope('profile');
584
                $google->addScope('email');
568
                $google->addScope('email');
585
                
569
 
586
                // $redirect_url =  $this->url()->fromRoute('oauth/google', [], ['force_canonical' => true]);
570
                // $redirect_url =  $this->url()->fromRoute('oauth/google', [], ['force_canonical' => true]);
587
                $redirect_url = $this->config['leaderslinked.google_auth.app_redirect_url'];
571
                $redirect_url = $this->config['leaderslinked.google_auth.app_redirect_url'];
588
                
572
 
589
                $google->setRedirectUri($redirect_url);
573
                $google->setRedirectUri($redirect_url);
590
                $googleUrl = $google->createAuthUrl();
574
                $googleUrl = $google->createAuthUrl();
591
                
575
 
592
                return new JsonModel([
576
                return new JsonModel([
593
                    'success' => true,
577
                    'success' => true,
594
                    'data' =>  $googleUrl
578
                    'data' =>  $googleUrl
595
                ]);
579
                ]);
596
            } catch (\Throwable $e) {
580
            } catch (\Throwable $e) {
597
                return new JsonModel([
581
                return new JsonModel([
598
                    'success' => false,
582
                    'success' => false,
599
                    'data' =>  'ERROR_WE_COULD_NOT_CONNECT_TO_GOOGLE'
583
                    'data' =>  'ERROR_WE_COULD_NOT_CONNECT_TO_GOOGLE'
600
                ]);
584
                ]);
601
            }
585
            }
602
            
-
 
603
        } else {
586
        } else {
604
            return new JsonModel([
587
            return new JsonModel([
605
                'success' => false,
588
                'success' => false,
606
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
589
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
607
            ]);
590
            ]);
608
        }
591
        }
609
    }
592
    }
610
    
593
 
611
    public function signoutAction()
594
    public function signoutAction()
612
    {
595
    {
613
        $currentUserPlugin = $this->plugin('currentUserPlugin');
596
        $currentUserPlugin = $this->plugin('currentUserPlugin');
614
        $currentUser = $currentUserPlugin->getRawUser();
597
        $currentUser = $currentUserPlugin->getRawUser();
615
        if($currentUserPlugin->hasImpersonate()) {
598
        if ($currentUserPlugin->hasImpersonate()) {
616
            
599
 
617
            
600
 
618
            $userMapper = UserMapper::getInstance($this->adapter);
601
            $userMapper = UserMapper::getInstance($this->adapter);
619
            $userMapper->leaveImpersonate($currentUser->id);
602
            $userMapper->leaveImpersonate($currentUser->id);
620
            
603
 
621
            $networkMapper = NetworkMapper::getInstance($this->adapter);
604
            $networkMapper = NetworkMapper::getInstance($this->adapter);
622
            $network = $networkMapper->fetchOne($currentUser->network_id);
605
            $network = $networkMapper->fetchOne($currentUser->network_id);
623
            
606
 
624
            
607
 
625
            if(!$currentUser->one_time_password) {
608
            if (!$currentUser->one_time_password) {
626
                $one_time_password = Functions::generatePassword(25);
609
                $one_time_password = Functions::generatePassword(25);
627
                
610
 
628
                $currentUser->one_time_password = $one_time_password;
611
                $currentUser->one_time_password = $one_time_password;
629
                
612
 
630
                $userMapper = UserMapper::getInstance($this->adapter);
613
                $userMapper = UserMapper::getInstance($this->adapter);
631
                $userMapper->updateOneTimePassword($currentUser, $one_time_password);
614
                $userMapper->updateOneTimePassword($currentUser, $one_time_password);
632
            }
615
            }
633
            
616
 
634
            
617
 
635
            $sandbox = $this->config['leaderslinked.runmode.sandbox'];
618
            $sandbox = $this->config['leaderslinked.runmode.sandbox'];
636
            if($sandbox) {
619
            if ($sandbox) {
637
                $salt = $this->config['leaderslinked.backend.sandbox_salt'];
620
                $salt = $this->config['leaderslinked.backend.sandbox_salt'];
638
            } else {
621
            } else {
639
                $salt = $this->config['leaderslinked.backend.production_salt'];
622
                $salt = $this->config['leaderslinked.backend.production_salt'];
640
            }
623
            }
641
            
624
 
642
            
625
 
643
            
626
 
644
            
627
 
645
            $rand = 1000 + mt_rand(1, 999);
628
            $rand = 1000 + mt_rand(1, 999);
646
            $timestamp = time();
629
            $timestamp = time();
647
            $password = md5($currentUser->one_time_password . '-' . $rand . '-' . $timestamp . '-' . $salt);
630
            $password = md5($currentUser->one_time_password . '-' . $rand . '-' . $timestamp . '-' . $salt);
648
            
631
 
649
            $params = [
632
            $params = [
650
                'user_uuid' => $currentUser->uuid,
633
                'user_uuid' => $currentUser->uuid,
651
                'password' => $password,
634
                'password' => $password,
652
                'rand' => $rand,
635
                'rand' => $rand,
653
                'time' => $timestamp,
636
                'time' => $timestamp,
654
            ];
637
            ];
655
            
638
 
656
            $currentUserPlugin->clearIdentity();
639
            $currentUserPlugin->clearIdentity();
657
            $url = 'https://'. $network->main_hostname . '/signin/impersonate' . '?' . http_build_query($params);
640
            $url = 'https://' . $network->main_hostname . '/signin/impersonate' . '?' . http_build_query($params);
658
            return $this->redirect()->toUrl($url);
641
            return $this->redirect()->toUrl($url);
659
            
-
 
660
            
-
 
661
            
-
 
662
        } else {
642
        } else {
663
            
643
 
664
            
644
 
665
            if($currentUserPlugin->hasIdentity()) {
645
            if ($currentUserPlugin->hasIdentity()) {
666
    
646
 
667
                $this->logger->info('Desconexión de LeadersLinked', ['user_id' => $currentUserPlugin->getUserId(), 'ip' => Functions::getUserIP()]);
647
                $this->logger->info('Desconexión de LeadersLinked', ['user_id' => $currentUserPlugin->getUserId(), 'ip' => Functions::getUserIP()]);
668
            }
648
            }
669
            
649
 
670
            $currentUserPlugin->clearIdentity();
650
            $currentUserPlugin->clearIdentity();
671
            
651
 
672
            return $this->redirect()->toRoute('home');
652
            return $this->redirect()->toRoute('home');
673
        }
653
        }
674
    }
654
    }
675
    
655
 
676
    
656
 
677
    public function resetPasswordAction()
657
    public function resetPasswordAction()
678
    {
658
    {
679
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
659
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
680
        $currentNetwork  = $currentNetworkPlugin->getNetwork();
660
        $currentNetwork  = $currentNetworkPlugin->getNetwork();
681
        
661
 
682
        
662
 
683
        $flashMessenger = $this->plugin('FlashMessenger');
663
        $flashMessenger = $this->plugin('FlashMessenger');
684
        $code =  Functions::sanitizeFilterString($this->params()->fromRoute('code', ''));
664
        $code =  Functions::sanitizeFilterString($this->params()->fromRoute('code', ''));
685
        
665
 
686
        $userMapper = UserMapper::getInstance($this->adapter);
666
        $userMapper = UserMapper::getInstance($this->adapter);
687
        $user = $userMapper->fetchOneByPasswordResetKeyAndNetworkId($code, $currentNetwork->id);
667
        $user = $userMapper->fetchOneByPasswordResetKeyAndNetworkId($code, $currentNetwork->id);
688
        if(!$user) {
668
        if (!$user) {
689
            $this->logger->err('Restablecer contraseña - Error código no existe', ['ip' => Functions::getUserIP()]);
669
            $this->logger->err('Restablecer contraseña - Error código no existe', ['ip' => Functions::getUserIP()]);
690
            
670
 
691
            $flashMessenger->addErrorMessage('ERROR_PASSWORD_RECOVER_CODE_IS_INVALID');
671
            $flashMessenger->addErrorMessage('ERROR_PASSWORD_RECOVER_CODE_IS_INVALID');
692
            return $this->redirect()->toRoute('forgot-password');
672
            return $this->redirect()->toRoute('forgot-password');
693
        }
673
        }
694
        
674
 
695
        
675
 
696
        
676
 
697
        $password_generated_on = strtotime($user->password_generated_on);
677
        $password_generated_on = strtotime($user->password_generated_on);
698
        $expiry_time = $password_generated_on + $this->config['leaderslinked.security.reset_password_expired'];
678
        $expiry_time = $password_generated_on + $this->config['leaderslinked.security.reset_password_expired'];
699
        if (time() > $expiry_time) {
679
        if (time() > $expiry_time) {
700
            $this->logger->err('Restablecer contraseña - Error código expirado', ['ip' => Functions::getUserIP()]);
680
            $this->logger->err('Restablecer contraseña - Error código expirado', ['ip' => Functions::getUserIP()]);
701
            
681
 
702
            $flashMessenger->addErrorMessage('ERROR_PASSWORD_RECOVER_CODE_HAS_EXPIRED');
682
            $flashMessenger->addErrorMessage('ERROR_PASSWORD_RECOVER_CODE_HAS_EXPIRED');
703
            return $this->redirect()->toRoute('forgot-password');
683
            return $this->redirect()->toRoute('forgot-password');
704
        }
684
        }
705
        
685
 
706
        $request = $this->getRequest();
686
        $request = $this->getRequest();
707
        if($request->isPost()) {
687
        if ($request->isPost()) {
708
            $dataPost = $request->getPost()->toArray();
688
            $dataPost = $request->getPost()->toArray();
709
            if(empty($_SESSION['aes'])) {
689
            if (empty($_SESSION['aes'])) {
710
                return new JsonModel([
690
                return new JsonModel([
711
                    'success'   => false,
691
                    'success'   => false,
712
                    'data'      => 'ERROR_WEBSERVICE_ENCRYPTION_KEYS_NOT_FOUND'
692
                    'data'      => 'ERROR_WEBSERVICE_ENCRYPTION_KEYS_NOT_FOUND'
713
                ]);
693
                ]);
714
            }
694
            }
Línea 715... Línea 695...
715
 
695
 
716
            if(!empty( $dataPost['password'])) {
696
            if (!empty($dataPost['password'])) {
717
                $dataPost['password'] = CryptoJsAes::decrypt( $dataPost['password'], $_SESSION['aes']);
697
                $dataPost['password'] = CryptoJsAes::decrypt($dataPost['password'], $_SESSION['aes']);
718
            }
698
            }
719
            if(!empty( $dataPost['confirmation'])) {
699
            if (!empty($dataPost['confirmation'])) {
720
                $dataPost['confirmation'] = CryptoJsAes::decrypt( $dataPost['confirmation'], $_SESSION['aes']);
700
                $dataPost['confirmation'] = CryptoJsAes::decrypt($dataPost['confirmation'], $_SESSION['aes']);
721
            }
701
            }
722
            
702
 
723
            
703
 
724
            
704
 
725
            $form = new ResetPasswordForm($this->config);
705
            $form = new ResetPasswordForm($this->config);
726
            $form->setData($dataPost);
706
            $form->setData($dataPost);
727
            
707
 
728
            if($form->isValid()) {
708
            if ($form->isValid()) {
729
                $data = (array) $form->getData();
709
                $data = (array) $form->getData();
730
                $password = $data['password'];
710
                $password = $data['password'];
Línea 731... Línea 711...
731
                
711
 
732
 
712
 
Línea 733... Línea 713...
733
                $userPasswordMapper = UserPasswordMapper::getInstance($this->adapter);
713
                $userPasswordMapper = UserPasswordMapper::getInstance($this->adapter);
734
                $userPasswords = $userPasswordMapper->fetchAllByUserId($user->id);
714
                $userPasswords = $userPasswordMapper->fetchAllByUserId($user->id);
735
 
-
 
736
                $oldPassword = false;
715
 
737
                foreach($userPasswords as $userPassword)
-
 
738
                {
716
                $oldPassword = false;
739
                    if(password_verify($password, $userPassword->password) || (md5($password) == $userPassword->password)) 
717
                foreach ($userPasswords as $userPassword) {
740
                    {
718
                    if (password_verify($password, $userPassword->password) || (md5($password) == $userPassword->password)) {
741
                        $oldPassword = true;
719
                        $oldPassword = true;
742
                        break;
720
                        break;
743
                    }
721
                    }
744
                }
722
                }
745
                
723
 
746
                if($oldPassword) {
724
                if ($oldPassword) {
747
                    $this->logger->err('Restablecer contraseña - Error contraseña ya utilizada anteriormente', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
725
                    $this->logger->err('Restablecer contraseña - Error contraseña ya utilizada anteriormente', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
748
                    
726
 
749
                    return new JsonModel([
727
                    return new JsonModel([
750
                        'success'   => false,
728
                        'success'   => false,
751
                        'data'      => 'ERROR_PASSWORD_HAS_ALREADY_BEEN_USED'
729
                        'data'      => 'ERROR_PASSWORD_HAS_ALREADY_BEEN_USED'
752
                        
730
 
753
                    ]);
731
                    ]);
754
                } else {
732
                } else {
755
                    $password_hash = password_hash($password, PASSWORD_DEFAULT);
733
                    $password_hash = password_hash($password, PASSWORD_DEFAULT);
756
                    
734
 
757
                    
735
 
758
                    $result = $userMapper->updatePassword($user, $password_hash);
736
                    $result = $userMapper->updatePassword($user, $password_hash);
759
                    if($result) {
737
                    if ($result) {
760
                        
738
 
761
                        $userPassword = new UserPassword();
739
                        $userPassword = new UserPassword();
762
                        $userPassword->user_id = $user->id;
740
                        $userPassword->user_id = $user->id;
763
                        $userPassword->password = $password_hash;
741
                        $userPassword->password = $password_hash;
764
                        $userPasswordMapper->insert($userPassword);
742
                        $userPasswordMapper->insert($userPassword);
765
                        
743
 
766
                        
744
 
767
                        $this->logger->info('Restablecer contraseña realizado', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
745
                        $this->logger->info('Restablecer contraseña realizado', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
768
                        
746
 
769
                       
747
 
770
                        $flashMessenger->addSuccessMessage('LABEL_YOUR_PASSWORD_HAS_BEEN_UPDATED');
748
                        $flashMessenger->addSuccessMessage('LABEL_YOUR_PASSWORD_HAS_BEEN_UPDATED');
771
                        
749
 
772
                        return new JsonModel([
750
                        return new JsonModel([
773
                            'success'   => true,
751
                            'success'   => true,
774
                            'data'      => $this->url()->fromRoute('home')
752
                            'data'      => $this->url()->fromRoute('home')
775
                            
753
 
776
                        ]);
754
                        ]);
777
                    } else {
755
                    } else {
778
                        $this->logger->err('Restablecer contraseña - Error desconocido', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
756
                        $this->logger->err('Restablecer contraseña - Error desconocido', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
779
                        
757
 
780
                        return new JsonModel([
758
                        return new JsonModel([
781
                            'success'   => true,
759
                            'success'   => true,
782
                            'data'      => 'ERROR_THERE_WAS_AN_ERROR'
760
                            'data'      => 'ERROR_THERE_WAS_AN_ERROR'
783
                            
761
 
784
                        ]);
-
 
785
                    }
762
                        ]);
786
                }
763
                    }
787
 
764
                }
788
            } else {
765
            } else {
789
                $form_messages =  $form->getMessages('captcha');
766
                $form_messages =  $form->getMessages('captcha');
790
                if(!empty($form_messages)) {
767
                if (!empty($form_messages)) {
791
                    return new JsonModel([
768
                    return new JsonModel([
792
                        'success'   => false,
769
                        'success'   => false,
793
                        'data'      => 'ERROR_RECAPTCHA_EMPTY'
770
                        'data'      => 'ERROR_RECAPTCHA_EMPTY'
794
                    ]);
771
                    ]);
795
                }
772
                }
796
                
773
 
797
                $messages = [];
774
                $messages = [];
798
                
-
 
799
                $form_messages = (array) $form->getMessages();
775
 
800
                foreach($form_messages  as $fieldname => $field_messages)
776
                $form_messages = (array) $form->getMessages();
801
                {
777
                foreach ($form_messages  as $fieldname => $field_messages) {
802
                    $messages[$fieldname] = array_values($field_messages);
778
                    $messages[$fieldname] = array_values($field_messages);
803
                }
779
                }
804
                
780
 
805
                return new JsonModel([
781
                return new JsonModel([
806
                    'success'   => false,
782
                    'success'   => false,
807
                    'data'   => $messages
-
 
808
                ]);
783
                    'data'   => $messages
Línea 809... Línea 784...
809
            }
784
                ]);
810
            
785
            }
811
        } 
786
        }
812
 
787
 
813
        if($request->isGet()) {
788
        if ($request->isGet()) {
814
            
789
 
815
            if(empty($_SESSION['aes'])) {
790
            if (empty($_SESSION['aes'])) {
816
                $_SESSION['aes'] = Functions::generatePassword(16);
791
                $_SESSION['aes'] = Functions::generatePassword(16);
817
            }
792
            }
818
            
793
 
819
            if($this->config['leaderslinked.runmode.sandbox']) {
794
            if ($this->config['leaderslinked.runmode.sandbox']) {
820
                $site_key      = $this->config['leaderslinked.google_captcha.sandbox_site_key'];
795
                $site_key      = $this->config['leaderslinked.google_captcha.sandbox_site_key'];
821
            } else {
796
            } else {
822
                $site_key      = $this->config['leaderslinked.google_captcha.production_site_key'];
797
                $site_key      = $this->config['leaderslinked.google_captcha.production_site_key'];
823
            }
798
            }
824
            
799
 
825
            
800
 
826
            $form = new ResetPasswordForm($this->config);
801
            $form = new ResetPasswordForm($this->config);
827
            
802
 
828
            $this->layout()->setTemplate('layout/auth.phtml');
803
            $this->layout()->setTemplate('layout/auth.phtml');
829
            $viewModel = new ViewModel();
804
            $viewModel = new ViewModel();
830
            $viewModel->setTemplate('leaders-linked/auth/reset-password.phtml');
805
            $viewModel->setTemplate('leaders-linked/auth/reset-password.phtml');
831
            $viewModel->setVariables([
806
            $viewModel->setVariables([
832
                'code' => $code,
807
                'code' => $code,
833
                'form' => $form,
808
                'form' => $form,
834
                'site_key' => $site_key,
809
                'site_key' => $site_key,
835
                'aes'       => $_SESSION['aes'],
810
                'aes'       => $_SESSION['aes'],
836
                'defaultNetwork' => $currentNetwork->default,
811
                'defaultNetwork' => $currentNetwork->default,
-
 
812
            ]);
-
 
813
 
Línea 837... Línea -...
837
            ]);
-
 
838
            
-
 
839
            return $viewModel;
814
            return $viewModel;
840
        } 
815
        }
841
 
816
 
842
            
817
 
843
            
818
 
844
        return new JsonModel([
819
        return new JsonModel([
845
            'success' => false,
820
            'success' => false,
846
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
821
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
847
        ]);
822
        ]);
848
    }
823
    }
849
    
824
 
850
    public function forgotPasswordAction()
825
    public function forgotPasswordAction()
851
    {
826
    {
852
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
827
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
853
        $currentNetwork  = $currentNetworkPlugin->getNetwork();
828
        $currentNetwork  = $currentNetworkPlugin->getNetwork();
854
        
829
 
855
        
830
 
856
        
831
 
857
        $request = $this->getRequest();
832
        $request = $this->getRequest();
858
        if($request->isPost()) {
833
        if ($request->isPost()) {
859
            $dataPost = $request->getPost()->toArray();
834
            $dataPost = $request->getPost()->toArray();
860
            if(empty($_SESSION['aes'])) {
835
            if (empty($_SESSION['aes'])) {
861
                return new JsonModel([
836
                return new JsonModel([
862
                    'success'   => false,
837
                    'success'   => false,
863
                    'data'      => 'ERROR_WEBSERVICE_ENCRYPTION_KEYS_NOT_FOUND'
838
                    'data'      => 'ERROR_WEBSERVICE_ENCRYPTION_KEYS_NOT_FOUND'
864
                ]);
839
                ]);
865
            }
840
            }
866
            
841
 
867
            if(!empty( $dataPost['email'])) {
842
            if (!empty($dataPost['email'])) {
868
                $dataPost['email'] = CryptoJsAes::decrypt( $dataPost['email'], $_SESSION['aes']);
843
                $dataPost['email'] = CryptoJsAes::decrypt($dataPost['email'], $_SESSION['aes']);
869
            }
844
            }
870
            
845
 
871
            $form = new ForgotPasswordForm($this->config);
846
            $form = new ForgotPasswordForm($this->config);
872
            $form->setData($dataPost);
847
            $form->setData($dataPost);
873
            
848
 
874
            if($form->isValid()) {
849
            if ($form->isValid()) {
875
                $dataPost = (array) $form->getData();
850
                $dataPost = (array) $form->getData();
876
                $email      = $dataPost['email'];
851
                $email      = $dataPost['email'];
877
                
852
 
878
                $userMapper = UserMapper::getInstance($this->adapter);
853
                $userMapper = UserMapper::getInstance($this->adapter);
879
                $user = $userMapper->fetchOneByEmailAndNetworkId($email, $currentNetwork->id);
854
                $user = $userMapper->fetchOneByEmailAndNetworkId($email, $currentNetwork->id);
880
                if(!$user) {
855
                if (!$user) {
881
                    $this->logger->err('Olvidó contraseña ' . $email . '- Email no existe ', ['ip' => Functions::getUserIP()]);
856
                    $this->logger->err('Olvidó contraseña ' . $email . '- Email no existe ', ['ip' => Functions::getUserIP()]);
882
                    
857
 
883
                    return new JsonModel([
858
                    return new JsonModel([
884
                        'success' => false,
859
                        'success' => false,
885
                        'data' =>  'ERROR_EMAIL_IS_NOT_REGISTERED'
860
                        'data' =>  'ERROR_EMAIL_IS_NOT_REGISTERED'
886
                    ]);
861
                    ]);
887
                } else {
862
                } else {
888
                    if($user->status == User::STATUS_INACTIVE) {
863
                    if ($user->status == User::STATUS_INACTIVE) {
889
                        return new JsonModel([
864
                        return new JsonModel([
890
                            'success' => false,
865
                            'success' => false,
891
                            'data' =>  'ERROR_USER_IS_INACTIVE'
866
                            'data' =>  'ERROR_USER_IS_INACTIVE'
892
                        ]);
867
                        ]);
893
                    } else if ($user->email_verified == User::EMAIL_VERIFIED_NO) {
868
                    } else if ($user->email_verified == User::EMAIL_VERIFIED_NO) {
894
                        $this->logger->err('Olvidó contraseña - Email no verificado ', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
869
                        $this->logger->err('Olvidó contraseña - Email no verificado ', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
895
                        
870
 
896
                        return new JsonModel([
871
                        return new JsonModel([
897
                            'success' => false,
872
                            'success' => false,
898
                            'data' => 'ERROR_EMAIL_HAS_NOT_BEEN_VERIFIED'
873
                            'data' => 'ERROR_EMAIL_HAS_NOT_BEEN_VERIFIED'
899
                        ]);
874
                        ]);
900
                    } else {
875
                    } else {
901
                        $password_reset_key = md5($user->email. time());
876
                        $password_reset_key = md5($user->email . time());
902
                        $userMapper->updatePasswordResetKey((int) $user->id, $password_reset_key);
877
                        $userMapper->updatePasswordResetKey((int) $user->id, $password_reset_key);
903
                        
878
 
904
                        $emailTemplateMapper = EmailTemplateMapper::getInstance($this->adapter);
879
                        $emailTemplateMapper = EmailTemplateMapper::getInstance($this->adapter);
905
                        $emailTemplate = $emailTemplateMapper->fetchOneByCodeAndNetworkId(EmailTemplate::CODE_RESET_PASSWORD, $currentNetwork->id);
880
                        $emailTemplate = $emailTemplateMapper->fetchOneByCodeAndNetworkId(EmailTemplate::CODE_RESET_PASSWORD, $currentNetwork->id);
906
                        if($emailTemplate) {
881
                        if ($emailTemplate) {
Línea 913... Línea 888...
913
                                'group_name'            => '',
888
                                'group_name'            => '',
914
                                'content'               => '',
889
                                'content'               => '',
915
                                'code'                  => '',
890
                                'code'                  => '',
916
                                'link'                  => $this->url()->fromRoute('reset-password', ['code' => $password_reset_key], ['force_canonical' => true])
891
                                'link'                  => $this->url()->fromRoute('reset-password', ['code' => $password_reset_key], ['force_canonical' => true])
917
                            ];
892
                            ];
918
                            
893
 
919
                            $email = new QueueEmail($this->adapter);
894
                            $email = new QueueEmail($this->adapter);
920
                            $email->processEmailTemplate($emailTemplate, $arrayCont, $user->email, trim($user->first_name . ' ' . $user->last_name));
895
                            $email->processEmailTemplate($emailTemplate, $arrayCont, $user->email, trim($user->first_name . ' ' . $user->last_name));
921
                        }
896
                        }
922
                        $flashMessenger = $this->plugin('FlashMessenger');
897
                        $flashMessenger = $this->plugin('FlashMessenger');
923
                        $flashMessenger->addSuccessMessage('LABEL_RECOVERY_LINK_WAS_SENT_TO_YOUR_EMAIL');
898
                        $flashMessenger->addSuccessMessage('LABEL_RECOVERY_LINK_WAS_SENT_TO_YOUR_EMAIL');
924
                        
899
 
925
                        $this->logger->info('Olvidó contraseña - Se envio link de recuperación ', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
900
                        $this->logger->info('Olvidó contraseña - Se envio link de recuperación ', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
926
                        
901
 
927
                        return new JsonModel([
902
                        return new JsonModel([
928
                            'success' => true,
903
                            'success' => true,
929
                        ]);
904
                        ]);
930
                    }
905
                    }
931
                }
906
                }
932
                
-
 
933
            } else {
907
            } else {
934
                
908
 
935
                
909
 
936
                $form_messages =  $form->getMessages('captcha');
910
                $form_messages =  $form->getMessages('captcha');
937
                
911
 
938
         
912
 
939
                
913
 
940
                if(!empty($form_messages)) {
914
                if (!empty($form_messages)) {
941
                    return new JsonModel([
915
                    return new JsonModel([
942
                        'success'   => false,
916
                        'success'   => false,
943
                        'data'      => 'ERROR_RECAPTCHA_EMPTY'
917
                        'data'      => 'ERROR_RECAPTCHA_EMPTY'
944
                    ]);
918
                    ]);
945
                }
919
                }
946
                
920
 
947
                $messages = [];
921
                $messages = [];
948
                $form_messages = (array) $form->getMessages();
922
                $form_messages = (array) $form->getMessages();
949
                foreach($form_messages  as $fieldname => $field_messages)
923
                foreach ($form_messages  as $fieldname => $field_messages) {
950
                {
-
 
951
                    $messages[$fieldname] = array_values($field_messages);
924
                    $messages[$fieldname] = array_values($field_messages);
952
                }
925
                }
Línea 953... Línea 926...
953
 
926
 
954
                return new JsonModel([
927
                return new JsonModel([
955
                    'success'   => false,
928
                    'success'   => false,
956
                    'data'      => $messages    
929
                    'data'      => $messages
957
                ]);
930
                ]);
958
            }
931
            }
959
        } 
932
        }
960
        
933
 
961
        /*
934
        /*
962
        if($request->isGet())  {
935
        if($request->isGet())  {
963
            if(empty($_SESSION['aes'])) {
936
            if(empty($_SESSION['aes'])) {
964
                $_SESSION['aes'] = Functions::generatePassword(16);
937
                $_SESSION['aes'] = Functions::generatePassword(16);
Línea 983... Línea 956...
983
            ]);
956
            ]);
Línea 984... Línea 957...
984
            
957
            
985
            return $viewModel ;
958
            return $viewModel ;
986
        } 
959
        } 
987
        */
960
        */
988
        
961
 
989
        if($request->isGet())  {
962
        if ($request->isGet()) {
990
            
963
 
991
            if(empty($_SESSION['aes'])) {
964
            if (empty($_SESSION['aes'])) {
992
                $_SESSION['aes'] = Functions::generatePassword(16);
965
                $_SESSION['aes'] = Functions::generatePassword(16);
993
            }
966
            }
994
            
967
 
995
            if($this->config['leaderslinked.runmode.sandbox']) {
968
            if ($this->config['leaderslinked.runmode.sandbox']) {
996
                $site_key      = $this->config['leaderslinked.google_captcha.sandbox_site_key'];
969
                $site_key      = $this->config['leaderslinked.google_captcha.sandbox_site_key'];
997
            } else {
970
            } else {
998
                $site_key      = $this->config['leaderslinked.google_captcha.production_site_key'];
971
                $site_key      = $this->config['leaderslinked.google_captcha.production_site_key'];
999
            }
972
            }
1000
            
973
 
1001
            $email      = isset($_COOKIE['email']) ? $_COOKIE['email'] : '';
974
            $email      = isset($_COOKIE['email']) ? $_COOKIE['email'] : '';
1002
            $remember   = $email ? true : false;
975
            $remember   = $email ? true : false;
1003
            
976
 
1004
            $form = new SigninForm($this->config);
977
            $form = new SigninForm($this->config);
1005
            $form->setData([
978
            $form->setData([
1006
                'email'     => $email,
979
                'email'     => $email,
1007
                'remember'  => $remember,
980
                'remember'  => $remember,
Línea 1013... Línea 986...
1013
                'form'      =>  $form,
986
                'form'      =>  $form,
1014
                'site_key'  => $site_key,
987
                'site_key'  => $site_key,
1015
                'aes'       => $_SESSION['aes'],
988
                'aes'       => $_SESSION['aes'],
1016
                'defaultNetwork' => $currentNetwork->default,
989
                'defaultNetwork' => $currentNetwork->default,
1017
            ]);
990
            ]);
1018
            
991
 
1019
            return $viewModel ;
992
            return $viewModel;
1020
            
-
 
1021
        } 
993
        }
1022
        
994
 
1023
        return new JsonModel([
995
        return new JsonModel([
1024
            'success' => false,
996
            'success' => false,
1025
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
997
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1026
        ]);
998
        ]);
1027
    }
999
    }
1028
    
1000
 
1029
    public function signupAction()
1001
    public function signupAction()
1030
    {
1002
    {
1031
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
1003
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
1032
        $currentNetwork  = $currentNetworkPlugin->getNetwork();
1004
        $currentNetwork  = $currentNetworkPlugin->getNetwork();
1033
        
1005
 
1034
        
1006
 
1035
        $request = $this->getRequest();
1007
        $request = $this->getRequest();
1036
        if($request->isPost()) {
1008
        if ($request->isPost()) {
1037
            $dataPost = $request->getPost()->toArray();
1009
            $dataPost = $request->getPost()->toArray();
1038
            
1010
 
1039
            if(empty($_SESSION['aes'])) {
1011
            if (empty($_SESSION['aes'])) {
1040
                return new JsonModel([
1012
                return new JsonModel([
1041
                    'success'   => false,
1013
                    'success'   => false,
1042
                    'data'      => 'ERROR_WEBSERVICE_ENCRYPTION_KEYS_NOT_FOUND'
1014
                    'data'      => 'ERROR_WEBSERVICE_ENCRYPTION_KEYS_NOT_FOUND'
1043
                ]);
1015
                ]);
1044
            }
1016
            }
1045
            
1017
 
1046
            if(!empty( $dataPost['email'])) {
1018
            if (!empty($dataPost['email'])) {
1047
                $dataPost['email'] = CryptoJsAes::decrypt( $dataPost['email'], $_SESSION['aes']);
1019
                $dataPost['email'] = CryptoJsAes::decrypt($dataPost['email'], $_SESSION['aes']);
1048
            }
1020
            }
1049
            
1021
 
1050
            if(!empty( $dataPost['password'])) {
1022
            if (!empty($dataPost['password'])) {
1051
                $dataPost['password'] = CryptoJsAes::decrypt( $dataPost['password'], $_SESSION['aes']);
1023
                $dataPost['password'] = CryptoJsAes::decrypt($dataPost['password'], $_SESSION['aes']);
1052
            }
1024
            }
1053
            
1025
 
1054
            if(!empty( $dataPost['confirmation'])) {
1026
            if (!empty($dataPost['confirmation'])) {
1055
                $dataPost['confirmation'] = CryptoJsAes::decrypt( $dataPost['confirmation'], $_SESSION['aes']);
1027
                $dataPost['confirmation'] = CryptoJsAes::decrypt($dataPost['confirmation'], $_SESSION['aes']);
1056
            }
1028
            }
1057
            
1029
 
1058
            if(empty($dataPost['is_adult'])) {
1030
            if (empty($dataPost['is_adult'])) {
1059
                $dataPost['is_adult'] = User::IS_ADULT_NO;
1031
                $dataPost['is_adult'] = User::IS_ADULT_NO;
1060
            } else {
1032
            } else {
1061
                $dataPost['is_adult'] = $dataPost['is_adult'] == User::IS_ADULT_YES ? User::IS_ADULT_YES : User::IS_ADULT_NO;
1033
                $dataPost['is_adult'] = $dataPost['is_adult'] == User::IS_ADULT_YES ? User::IS_ADULT_YES : User::IS_ADULT_NO;
1062
            }
1034
            }
1063
            
1035
 
1064
            
1036
 
1065
            
1037
 
1066
            $form = new SignupForm($this->config);
1038
            $form = new SignupForm($this->config);
1067
            $form->setData($dataPost);
1039
            $form->setData($dataPost);
1068
            
1040
 
1069
            if($form->isValid()) {
1041
            if ($form->isValid()) {
1070
                $dataPost = (array) $form->getData();
1042
                $dataPost = (array) $form->getData();
1071
                
1043
 
1072
                $email = $dataPost['email'];
1044
                $email = $dataPost['email'];
1073
                
1045
 
1074
                $userMapper = UserMapper::getInstance($this->adapter);
1046
                $userMapper = UserMapper::getInstance($this->adapter);
1075
                $user = $userMapper->fetchOneByEmailAndNetworkId($email, $currentNetwork->id);
1047
                $user = $userMapper->fetchOneByEmailAndNetworkId($email, $currentNetwork->id);
1076
                if($user) {
1048
                if ($user) {
1077
                    $this->logger->err('Registro ' . $email . '- Email ya  existe ', ['ip' => Functions::getUserIP()]);
1049
                    $this->logger->err('Registro ' . $email . '- Email ya  existe ', ['ip' => Functions::getUserIP()]);
1078
                    
1050
 
1079
                    
1051
 
1080
                    
1052
 
1081
                    return new JsonModel([
1053
                    return new JsonModel([
1082
                        'success' => false,
1054
                        'success' => false,
1083
                        'data' => 'ERROR_EMAIL_IS_REGISTERED'
1055
                        'data' => 'ERROR_EMAIL_IS_REGISTERED'
1084
                    ]);
1056
                    ]);
1085
                } else {
1057
                } else {
1086
                    
1058
 
1087
                    $user_share_invitation = $this->cache->get('user_share_invitation');
1059
                    $user_share_invitation = $this->cache->get('user_share_invitation');
Línea 1088... Línea 1060...
1088
 
1060
 
1089
                    
1061
 
1090
                    if($user_share_invitation) {
1062
                    if ($user_share_invitation) {
1091
                        $userRedirect = $userMapper->fetchOneByUuid($user_share_invitation);
1063
                        $userRedirect = $userMapper->fetchOneByUuid($user_share_invitation);
1092
                        if($userRedirect && $userRedirect->status == User::STATUS_ACTIVE) {
1064
                        if ($userRedirect && $userRedirect->status == User::STATUS_ACTIVE) {
1093
                            $password_hash = password_hash($dataPost['password'], PASSWORD_DEFAULT);
1065
                            $password_hash = password_hash($dataPost['password'], PASSWORD_DEFAULT);
1094
                            
1066
 
1095
                            $user = new User();
1067
                            $user = new User();
1096
                            $user->network_id           = $currentNetwork->id;
1068
                            $user->network_id           = $currentNetwork->id;
1097
                            $user->email                = $dataPost['email'];
1069
                            $user->email                = $dataPost['email'];
1098
                            $user->first_name           = $dataPost['first_name'];
1070
                            $user->first_name           = $dataPost['first_name'];
Línea 1105... Línea 1077...
1105
                            $user->email_verified       = User::EMAIL_VERIFIED_YES;
1077
                            $user->email_verified       = User::EMAIL_VERIFIED_YES;
1106
                            $user->login_attempt        = 0;
1078
                            $user->login_attempt        = 0;
1107
                            $user->is_adult             = $dataPost['is_adult'];
1079
                            $user->is_adult             = $dataPost['is_adult'];
1108
                            $user->request_access       = User::REQUEST_ACCESS_APPROVED;
1080
                            $user->request_access       = User::REQUEST_ACCESS_APPROVED;
Línea 1109... Línea 1081...
1109
 
1081
 
1110
              
1082
 
1111
                            
1083
 
1112
                            
1084
 
1113
                            
1085
 
1114
                            if($userMapper->insert($user)) {
1086
                            if ($userMapper->insert($user)) {
1115
                                
1087
 
1116
                                $userPassword = new UserPassword();
1088
                                $userPassword = new UserPassword();
1117
                                $userPassword->user_id = $user->id;
1089
                                $userPassword->user_id = $user->id;
1118
                                $userPassword->password = $password_hash;
1090
                                $userPassword->password = $password_hash;
1119
                                
1091
 
1120
                                $userPasswordMapper = UserPasswordMapper::getInstance($this->adapter);
1092
                                $userPasswordMapper = UserPasswordMapper::getInstance($this->adapter);
1121
                                $userPasswordMapper->insert($userPassword);
1093
                                $userPasswordMapper->insert($userPassword);
1122
                                
1094
 
1123
                                
1095
 
1124
                                $connectionMapper = ConnectionMapper::getInstance($this->adapter);
1096
                                $connectionMapper = ConnectionMapper::getInstance($this->adapter);
1125
                                $connection = $connectionMapper->fetchOneByUserId1AndUserId2($user->id, $userRedirect->id);
1097
                                $connection = $connectionMapper->fetchOneByUserId1AndUserId2($user->id, $userRedirect->id);
1126
                                
1098
 
1127
                                if($connection) {
1099
                                if ($connection) {
1128
                                    
1100
 
1129
                                    if($connection->status != Connection::STATUS_ACCEPTED) {
1101
                                    if ($connection->status != Connection::STATUS_ACCEPTED) {
1130
                                        $connectionMapper->approve($connection);
1102
                                        $connectionMapper->approve($connection);
1131
                                    }
-
 
1132
                                    
1103
                                    }
1133
                                } else {
1104
                                } else {
1134
                                    $connection = new Connection();
1105
                                    $connection = new Connection();
1135
                                    $connection->request_from = $user->id;
1106
                                    $connection->request_from = $user->id;
1136
                                    $connection->request_to = $userRedirect->id;
1107
                                    $connection->request_to = $userRedirect->id;
1137
                                    $connection->status = Connection::STATUS_ACCEPTED;
1108
                                    $connection->status = Connection::STATUS_ACCEPTED;
1138
                                    
1109
 
1139
                                    $connectionMapper->insert($connection);
1110
                                    $connectionMapper->insert($connection);
1140
                                }
1111
                                }
1141
                                
1112
 
1142
                                
1113
 
Línea 1143... Línea 1114...
1143
                                $this->cache->delete('user_share_invitation');
1114
                                $this->cache->delete('user_share_invitation');
1144
 
1115
 
1145
                                
1116
 
1146
                                
1117
 
1147
                                $data = [
1118
                                $data = [
1148
                                    'success'   => true,
1119
                                    'success'   => true,
1149
                                    'data'      => $this->url()->fromRoute('home'),
1120
                                    'data'      => $this->url()->fromRoute('home'),
1150
                                ];
1121
                                ];
1151
        
1122
 
1152
                              
1123
 
1153
                                $this->logger->info('Registro con Exito ', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
1124
                                $this->logger->info('Registro con Exito ', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
1154
                                
1125
 
1155
                                return new JsonModel($data);
1126
                                return new JsonModel($data);
1156
                            }
1127
                            }
1157
                        }
-
 
Línea -... Línea 1128...
-
 
1128
                        }
1158
                    }
1129
                    }
1159
                    
1130
 
1160
 
1131
 
1161
                    
1132
 
1162
                    
1133
 
1163
                    $timestamp = time();
1134
                    $timestamp = time();
1164
                    $activation_key = sha1($dataPost['email'] . uniqid() . $timestamp);
1135
                    $activation_key = sha1($dataPost['email'] . uniqid() . $timestamp);
1165
                    
1136
 
1166
                    $password_hash = password_hash($dataPost['password'], PASSWORD_DEFAULT);
1137
                    $password_hash = password_hash($dataPost['password'], PASSWORD_DEFAULT);
1167
                    
1138
 
1168
                    $user = new User();
1139
                    $user = new User();
1169
                    $user->network_id           = $currentNetwork->id;
1140
                    $user->network_id           = $currentNetwork->id;
Línea 1176... Línea 1147...
1176
                    $user->activation_key       = $activation_key;
1147
                    $user->activation_key       = $activation_key;
1177
                    $user->status               = User::STATUS_INACTIVE;
1148
                    $user->status               = User::STATUS_INACTIVE;
1178
                    $user->blocked              = User::BLOCKED_NO;
1149
                    $user->blocked              = User::BLOCKED_NO;
1179
                    $user->email_verified       = User::EMAIL_VERIFIED_NO;
1150
                    $user->email_verified       = User::EMAIL_VERIFIED_NO;
1180
                    $user->login_attempt        = 0;
1151
                    $user->login_attempt        = 0;
1181
                    
1152
 
1182
                    if($currentNetwork->default == Network::DEFAULT_YES) {
1153
                    if ($currentNetwork->default == Network::DEFAULT_YES) {
1183
                        $user->request_access = User::REQUEST_ACCESS_APPROVED;
1154
                        $user->request_access = User::REQUEST_ACCESS_APPROVED;
1184
                    } else {
1155
                    } else {
1185
                        $user->request_access = User::REQUEST_ACCESS_PENDING;
1156
                        $user->request_access = User::REQUEST_ACCESS_PENDING;
1186
                    }
1157
                    }
1187
                    
1158
 
1188
               
1159
 
1189
                    
1160
 
1190
                    if($userMapper->insert($user)) {
1161
                    if ($userMapper->insert($user)) {
1191
                        
1162
 
1192
                        $userPassword = new UserPassword();
1163
                        $userPassword = new UserPassword();
1193
                        $userPassword->user_id = $user->id;
1164
                        $userPassword->user_id = $user->id;
1194
                        $userPassword->password = $password_hash;
1165
                        $userPassword->password = $password_hash;
1195
                        
1166
 
1196
                        $userPasswordMapper = UserPasswordMapper::getInstance($this->adapter);
1167
                        $userPasswordMapper = UserPasswordMapper::getInstance($this->adapter);
1197
                        $userPasswordMapper->insert($userPassword);
1168
                        $userPasswordMapper->insert($userPassword);
1198
                        
1169
 
1199
                        $emailTemplateMapper = EmailTemplateMapper::getInstance($this->adapter);
1170
                        $emailTemplateMapper = EmailTemplateMapper::getInstance($this->adapter);
1200
                        $emailTemplate = $emailTemplateMapper->fetchOneByCodeAndNetworkId(EmailTemplate::CODE_USER_REGISTER, $currentNetwork->id);
1171
                        $emailTemplate = $emailTemplateMapper->fetchOneByCodeAndNetworkId(EmailTemplate::CODE_USER_REGISTER, $currentNetwork->id);
1201
                        if($emailTemplate) {
1172
                        if ($emailTemplate) {
1202
                            $arrayCont = [
1173
                            $arrayCont = [
1203
                                'firstname'             => $user->first_name,
1174
                                'firstname'             => $user->first_name,
1204
                                'lastname'              => $user->last_name,
1175
                                'lastname'              => $user->last_name,
1205
                                'other_user_firstname'  => '',
1176
                                'other_user_firstname'  => '',
1206
                                'other_user_lastname'   => '',
1177
                                'other_user_lastname'   => '',
Línea 1208... Línea 1179...
1208
                                'group_name'            => '',
1179
                                'group_name'            => '',
1209
                                'content'               => '',
1180
                                'content'               => '',
1210
                                'code'                  => '',
1181
                                'code'                  => '',
1211
                                'link'                  => $this->url()->fromRoute('activate-account', ['code' => $user->activation_key], ['force_canonical' => true])
1182
                                'link'                  => $this->url()->fromRoute('activate-account', ['code' => $user->activation_key], ['force_canonical' => true])
1212
                            ];
1183
                            ];
1213
                            
1184
 
1214
                            $email = new QueueEmail($this->adapter);
1185
                            $email = new QueueEmail($this->adapter);
1215
                            $email->processEmailTemplate($emailTemplate, $arrayCont, $user->email, trim($user->first_name . ' ' . $user->last_name));
1186
                            $email->processEmailTemplate($emailTemplate, $arrayCont, $user->email, trim($user->first_name . ' ' . $user->last_name));
1216
                        }
1187
                        }
1217
                        $flashMessenger = $this->plugin('FlashMessenger');
1188
                        $flashMessenger = $this->plugin('FlashMessenger');
1218
                        $flashMessenger->addSuccessMessage('LABEL_REGISTRATION_DONE');
1189
                        $flashMessenger->addSuccessMessage('LABEL_REGISTRATION_DONE');
1219
                        
1190
 
1220
                        $this->logger->info('Registro con Exito ', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
1191
                        $this->logger->info('Registro con Exito ', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
1221
                        
1192
 
1222
                        return new JsonModel([
1193
                        return new JsonModel([
1223
                            'success' => true,
1194
                            'success' => true,
1224
                        ]);
1195
                        ]);
1225
                        
-
 
1226
                    } else {
1196
                    } else {
1227
                        $this->logger->err('Registro ' . $email . '- Ha ocurrido un error ', ['ip' => Functions::getUserIP()]);
1197
                        $this->logger->err('Registro ' . $email . '- Ha ocurrido un error ', ['ip' => Functions::getUserIP()]);
1228
                        
1198
 
1229
                        return new JsonModel([
1199
                        return new JsonModel([
1230
                            'success' => false,
1200
                            'success' => false,
1231
                            'data' => 'ERROR_THERE_WAS_AN_ERROR'
1201
                            'data' => 'ERROR_THERE_WAS_AN_ERROR'
1232
                        ]);
1202
                        ]);
1233
                    }
1203
                    }
1234
                }
1204
                }
1235
                
-
 
1236
 
-
 
1237
                
-
 
1238
            } else {
1205
            } else {
1239
               
1206
 
1240
                $form_messages =  $form->getMessages('captcha');
1207
                $form_messages =  $form->getMessages('captcha');
1241
                if(!empty($form_messages)) {
1208
                if (!empty($form_messages)) {
1242
                    return new JsonModel([
1209
                    return new JsonModel([
1243
                        'success'   => false,
1210
                        'success'   => false,
1244
                        'data'      => 'ERROR_RECAPTCHA_EMPTY'
1211
                        'data'      => 'ERROR_RECAPTCHA_EMPTY'
1245
                    ]);
1212
                    ]);
1246
                }
1213
                }
1247
                
1214
 
1248
                $messages = [];
1215
                $messages = [];
1249
                
1216
 
1250
                $form_messages = (array) $form->getMessages();
1217
                $form_messages = (array) $form->getMessages();
1251
                foreach($form_messages  as $fieldname => $field_messages)
1218
                foreach ($form_messages  as $fieldname => $field_messages) {
1252
                {
-
 
1253
                    $messages[$fieldname] = array_values($field_messages);
1219
                    $messages[$fieldname] = array_values($field_messages);
1254
                }
1220
                }
1255
                
1221
 
1256
                return new JsonModel([
1222
                return new JsonModel([
1257
                    'success'   => false,
1223
                    'success'   => false,
1258
                    'data'   => $messages
1224
                    'data'   => $messages
1259
                ]);
1225
                ]);
1260
            }
1226
            }
1261
        } 
1227
        }
1262
        /*
1228
        /*
1263
        if($request->isGet())  {
1229
        if($request->isGet())  {
1264
            if(empty($_SESSION['aes'])) {
1230
            if(empty($_SESSION['aes'])) {
1265
                $_SESSION['aes'] = Functions::generatePassword(16);
1231
                $_SESSION['aes'] = Functions::generatePassword(16);
1266
            }
1232
            }
Línea 1283... Línea 1249...
1283
                'aes' =>  $_SESSION['aes'],
1249
                'aes' =>  $_SESSION['aes'],
1284
            ]);
1250
            ]);
Línea 1285... Línea 1251...
1285
            
1251
            
1286
            return $viewModel ;
1252
            return $viewModel ;
1287
        } */
1253
        } */
1288
        
1254
 
1289
        
1255
 
1290
        if($request->isGet())  {
1256
        if ($request->isGet()) {
1291
            
1257
 
1292
            if(empty($_SESSION['aes'])) {
1258
            if (empty($_SESSION['aes'])) {
1293
                $_SESSION['aes'] = Functions::generatePassword(16);
1259
                $_SESSION['aes'] = Functions::generatePassword(16);
1294
            }
1260
            }
1295
            
1261
 
1296
            if($this->config['leaderslinked.runmode.sandbox']) {
1262
            if ($this->config['leaderslinked.runmode.sandbox']) {
1297
                $site_key      = $this->config['leaderslinked.google_captcha.sandbox_site_key'];
1263
                $site_key      = $this->config['leaderslinked.google_captcha.sandbox_site_key'];
1298
            } else {
1264
            } else {
1299
                $site_key      = $this->config['leaderslinked.google_captcha.production_site_key'];
1265
                $site_key      = $this->config['leaderslinked.google_captcha.production_site_key'];
1300
            }
1266
            }
1301
            
1267
 
1302
            $email      = isset($_COOKIE['email']) ? $_COOKIE['email'] : '';
1268
            $email      = isset($_COOKIE['email']) ? $_COOKIE['email'] : '';
1303
            $remember   = $email ? true : false;
1269
            $remember   = $email ? true : false;
1304
            
1270
 
1305
            $form = new SigninForm($this->config);
1271
            $form = new SigninForm($this->config);
1306
            $form->setData([
1272
            $form->setData([
1307
                'email'     => $email,
1273
                'email'     => $email,
1308
                'remember'  => $remember,
1274
                'remember'  => $remember,
Línea 1314... Línea 1280...
1314
                'form'      =>  $form,
1280
                'form'      =>  $form,
1315
                'site_key'  => $site_key,
1281
                'site_key'  => $site_key,
1316
                'aes'       => $_SESSION['aes'],
1282
                'aes'       => $_SESSION['aes'],
1317
                'defaultNetwork' => $currentNetwork->default,
1283
                'defaultNetwork' => $currentNetwork->default,
1318
            ]);
1284
            ]);
1319
            
1285
 
1320
            return $viewModel ;
1286
            return $viewModel;
1321
            
-
 
1322
        } 
1287
        }
1323
            
1288
 
1324
        return new JsonModel([
1289
        return new JsonModel([
1325
            'success' => false,
1290
            'success' => false,
1326
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1291
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1327
        ]);
1292
        ]);
1328
        
-
 
1329
        
-
 
1330
    }
1293
    }
1331
    
1294
 
1332
    public function activateAccountAction()
1295
    public function activateAccountAction()
1333
    {
1296
    {
1334
        
1297
 
1335
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
1298
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
1336
        $currentNetwork  = $currentNetworkPlugin->getNetwork();
1299
        $currentNetwork  = $currentNetworkPlugin->getNetwork();
1337
        
1300
 
1338
        
1301
 
1339
        
1302
 
1340
        $request = $this->getRequest();
1303
        $request = $this->getRequest();
1341
        if($request->isGet()) {
1304
        if ($request->isGet()) {
1342
            $code   =  Functions::sanitizeFilterString($this->params()->fromRoute('code'));
1305
            $code   =  Functions::sanitizeFilterString($this->params()->fromRoute('code'));
1343
            $userMapper = UserMapper::getInstance($this->adapter);
1306
            $userMapper = UserMapper::getInstance($this->adapter);
1344
            $user = $userMapper->fetchOneByActivationKeyAndNetworkId($code, $currentNetwork->id);
1307
            $user = $userMapper->fetchOneByActivationKeyAndNetworkId($code, $currentNetwork->id);
1345
            
1308
 
1346
            $flashMessenger = $this->plugin('FlashMessenger');
1309
            $flashMessenger = $this->plugin('FlashMessenger');
1347
            
1310
 
1348
            if($user) {
1311
            if ($user) {
1349
                if(User::EMAIL_VERIFIED_YES == $user->email_verified) {
1312
                if (User::EMAIL_VERIFIED_YES == $user->email_verified) {
1350
             
1313
 
1351
                    $this->logger->err('Verificación email - El código ya habia sido verificao ', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
1314
                    $this->logger->err('Verificación email - El código ya habia sido verificao ', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
1352
                    
1315
 
1353
                    $flashMessenger->addErrorMessage('ERROR_EMAIL_HAS_BEEN_PREVIOUSLY_VERIFIED');
1316
                    $flashMessenger->addErrorMessage('ERROR_EMAIL_HAS_BEEN_PREVIOUSLY_VERIFIED');
1354
                } else {
1317
                } else {
1355
              
1318
 
1356
                    if($userMapper->activateAccount((int) $user->id)) {
1319
                    if ($userMapper->activateAccount((int) $user->id)) {
Línea 1357... Línea 1320...
1357
 
1320
 
1358
                        $this->logger->info('Verificación email realizada ', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
1321
                        $this->logger->info('Verificación email realizada ', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
1359
                        
1322
 
1360
                        
1323
 
1361
                    
1324
 
1362
                        $user_share_invitation = $this->cache->get('user_share_invitation');
1325
                        $user_share_invitation = $this->cache->get('user_share_invitation');
1363
                        
1326
 
1364
                        if($user_share_invitation) {
1327
                        if ($user_share_invitation) {
1365
                            $userRedirect = $userMapper->fetchOneByUuid($user_share_invitation);
1328
                            $userRedirect = $userMapper->fetchOneByUuid($user_share_invitation);
1366
                            if($userRedirect && $userRedirect->status == User::STATUS_ACTIVE && $user->id != $userRedirect->id) {
1329
                            if ($userRedirect && $userRedirect->status == User::STATUS_ACTIVE && $user->id != $userRedirect->id) {
1367
                                $connectionMapper = ConnectionMapper::getInstance($this->adapter);
1330
                                $connectionMapper = ConnectionMapper::getInstance($this->adapter);
1368
                                $connection = $connectionMapper->fetchOneByUserId1AndUserId2($user->id, $userRedirect->id);
1331
                                $connection = $connectionMapper->fetchOneByUserId1AndUserId2($user->id, $userRedirect->id);
1369
                                
1332
 
1370
                                if($connection) {
1333
                                if ($connection) {
1371
                                    
1334
 
1372
                                    if($connection->status != Connection::STATUS_ACCEPTED) {
1335
                                    if ($connection->status != Connection::STATUS_ACCEPTED) {
1373
                                        $connectionMapper->approve($connection);
1336
                                        $connectionMapper->approve($connection);
1374
                                    }
-
 
1375
                                    
1337
                                    }
1376
                                } else {
1338
                                } else {
1377
                                    $connection = new Connection();
1339
                                    $connection = new Connection();
1378
                                    $connection->request_from = $user->id;
1340
                                    $connection->request_from = $user->id;
1379
                                    $connection->request_to = $userRedirect->id;
1341
                                    $connection->request_to = $userRedirect->id;
1380
                                    $connection->status = Connection::STATUS_ACCEPTED;
1342
                                    $connection->status = Connection::STATUS_ACCEPTED;
1381
                                    
1343
 
1382
                                    $connectionMapper->insert($connection);
1344
                                    $connectionMapper->insert($connection);
1383
                                }
1345
                                }
1384
                            }
1346
                            }
1385
                        }
1347
                        }
1386
                        
1348
 
1387
    
1349
 
1388
                        
1350
 
1389
                        $this->cache->delete('user_share_invitation');
1351
                        $this->cache->delete('user_share_invitation');
1390
                        
1352
 
1391
                        
1353
 
1392
                        if($currentNetwork->default == Network::DEFAULT_YES) {
1354
                        if ($currentNetwork->default == Network::DEFAULT_YES) {
1393
                            $flashMessenger->addSuccessMessage('LABEL_YOUR_EMAIL_HAS_BEEN_VERIFIED');
1355
                            $flashMessenger->addSuccessMessage('LABEL_YOUR_EMAIL_HAS_BEEN_VERIFIED');
1394
                        } else {
1356
                        } else {
1395
                            
1357
 
1396
                            $emailTemplateMapper = EmailTemplateMapper::getInstance($this->adapter);
1358
                            $emailTemplateMapper = EmailTemplateMapper::getInstance($this->adapter);
1397
                            $emailTemplate = $emailTemplateMapper->fetchOneByCodeAndNetworkId(EmailTemplate::CODE_REQUEST_ACCESS_PENDING, $currentNetwork->id);
1359
                            $emailTemplate = $emailTemplateMapper->fetchOneByCodeAndNetworkId(EmailTemplate::CODE_REQUEST_ACCESS_PENDING, $currentNetwork->id);
1398
                            
1360
 
1399
                            if($emailTemplate) {
1361
                            if ($emailTemplate) {
1400
                                $arrayCont = [
1362
                                $arrayCont = [
1401
                                    'firstname'             => $user->first_name,
1363
                                    'firstname'             => $user->first_name,
1402
                                    'lastname'              => $user->last_name,
1364
                                    'lastname'              => $user->last_name,
1403
                                    'other_user_firstname'  => '',
1365
                                    'other_user_firstname'  => '',
Línea 1406... Línea 1368...
1406
                                    'group_name'            => '',
1368
                                    'group_name'            => '',
1407
                                    'content'               => '',
1369
                                    'content'               => '',
1408
                                    'code'                  => '',
1370
                                    'code'                  => '',
1409
                                    'link'                  => '',
1371
                                    'link'                  => '',
1410
                                ];
1372
                                ];
1411
                                
1373
 
1412
                                $email = new QueueEmail($this->adapter);
1374
                                $email = new QueueEmail($this->adapter);
1413
                                $email->processEmailTemplate($emailTemplate, $arrayCont, $user->email, trim($user->first_name . ' ' . $user->last_name));
1375
                                $email->processEmailTemplate($emailTemplate, $arrayCont, $user->email, trim($user->first_name . ' ' . $user->last_name));
1414
                            }
1376
                            }
1415
                            
1377
 
1416
                            
1378
 
1417
                            $flashMessenger->addSuccessMessage('LABEL_YOUR_EMAIL_HAS_BEEN_VERIFIED_WE_ARE_VERIFYING_YOUR_INFORMATION');
1379
                            $flashMessenger->addSuccessMessage('LABEL_YOUR_EMAIL_HAS_BEEN_VERIFIED_WE_ARE_VERIFYING_YOUR_INFORMATION');
1418
                        }
1380
                        }
1419
   
-
 
1420
                    
-
 
1421
                    } else {
1381
                    } else {
1422
                        $this->logger->err('Verificación email - Ha ocurrido un error ', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
1382
                        $this->logger->err('Verificación email - Ha ocurrido un error ', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
1423
                        
1383
 
1424
                        $flashMessenger->addErrorMessage('ERROR_THERE_WAS_AN_ERROR');
1384
                        $flashMessenger->addErrorMessage('ERROR_THERE_WAS_AN_ERROR');
1425
                    }
1385
                    }
1426
                }
1386
                }
1427
            } else {
1387
            } else {
1428
                $this->logger->err('Verificación email - El código no existe ', ['ip' => Functions::getUserIP()]);
1388
                $this->logger->err('Verificación email - El código no existe ', ['ip' => Functions::getUserIP()]);
1429
                
1389
 
1430
                $flashMessenger->addErrorMessage('ERROR_ACTIVATION_CODE_IS_NOT_VALID');
1390
                $flashMessenger->addErrorMessage('ERROR_ACTIVATION_CODE_IS_NOT_VALID');
1431
            }
1391
            }
1432
            
-
 
1433
            return $this->redirect()->toRoute('home');    
-
 
Línea 1434... Línea -...
1434
 
-
 
1435
            
-
 
-
 
1392
 
1436
            
1393
            return $this->redirect()->toRoute('home');
1437
        } else {
1394
        } else {
1438
            $response = [
1395
            $response = [
1439
                'success' => false,
1396
                'success' => false,
1440
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1397
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1441
            ];
1398
            ];
1442
        }
1399
        }
1443
        
1400
 
1444
        return new JsonModel($response);
-
 
1445
        
1401
        return new JsonModel($response);
1446
    }
1402
    }
1447
   
1403
 
1448
                        
1404
 
1449
    
1405
 
1450
    public function onroomAction()
1406
    public function onroomAction()
1451
    {
1407
    {
1452
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
1408
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
1453
        $currentNetwork  = $currentNetworkPlugin->getNetwork();
1409
        $currentNetwork  = $currentNetworkPlugin->getNetwork();
1454
        
1410
 
1455
        
1411
 
1456
        
1412
 
1457
        $request = $this->getRequest();
1413
        $request = $this->getRequest();
1458
        
1414
 
1459
        if($request->isPost()) {
1415
        if ($request->isPost()) {
1460
            
1416
 
1461
            $dataPost = $request->getPost()->toArray();
1417
            $dataPost = $request->getPost()->toArray();
Línea 1462... Línea 1418...
1462
            
1418
 
1463
 
1419
 
1464
            $form = new  MoodleForm();
1420
            $form = new  MoodleForm();
1465
            $form->setData($dataPost);
1421
            $form->setData($dataPost);
1466
            if($form->isValid()) {
1422
            if ($form->isValid()) {
1467
                
1423
 
1468
                $dataPost   = (array) $form->getData();
1424
                $dataPost   = (array) $form->getData();
1469
                $username   = $dataPost['username'];
1425
                $username   = $dataPost['username'];
1470
                $password   = $dataPost['password'];
1426
                $password   = $dataPost['password'];
1471
                $timestamp  = $dataPost['timestamp'];
1427
                $timestamp  = $dataPost['timestamp'];
1472
                $rand       = $dataPost['rand'];
1428
                $rand       = $dataPost['rand'];
1473
                $data       = $dataPost['data'];
1429
                $data       = $dataPost['data'];
1474
                
1430
 
1475
                $config_username    = $this->config['leaderslinked.moodle.username'];
1431
                $config_username    = $this->config['leaderslinked.moodle.username'];
1476
                $config_password    = $this->config['leaderslinked.moodle.password'];
1432
                $config_password    = $this->config['leaderslinked.moodle.password'];
1477
                $config_rsa_n       = $this->config['leaderslinked.moodle.rsa_n'];
1433
                $config_rsa_n       = $this->config['leaderslinked.moodle.rsa_n'];
1478
                $config_rsa_d       = $this->config['leaderslinked.moodle.rsa_d'];
1434
                $config_rsa_d       = $this->config['leaderslinked.moodle.rsa_d'];
1479
                $config_rsa_e       = $this->config['leaderslinked.moodle.rsa_e'];
1435
                $config_rsa_e       = $this->config['leaderslinked.moodle.rsa_e'];
1480
                
1436
 
1481
                
1437
 
1482
                
1438
 
1483
                
1439
 
1484
                if(empty($username) || empty($password) || empty($timestamp) || empty($rand) || !is_integer($rand)) {
1440
                if (empty($username) || empty($password) || empty($timestamp) || empty($rand) || !is_integer($rand)) {
1485
                    echo json_encode(['success' => false, 'data' => 'ERROR_SECURITY1']) ;
1441
                    echo json_encode(['success' => false, 'data' => 'ERROR_SECURITY1']);
1486
                    exit;
1442
                    exit;
1487
                }
1443
                }
1488
                
1444
 
1489
                if($username != $config_username) {
1445
                if ($username != $config_username) {
1490
                    echo json_encode(['success' => false, 'data' => 'ERROR_SECURITY2']) ;
1446
                    echo json_encode(['success' => false, 'data' => 'ERROR_SECURITY2']);
1491
                    exit;
1447
                    exit;
1492
                }
1448
                }
1493
                
1449
 
1494
                $dt = \DateTime::createFromFormat('Y-m-d\TH:i:s', $timestamp);
1450
                $dt = \DateTime::createFromFormat('Y-m-d\TH:i:s', $timestamp);
1495
                if(!$dt) {
1451
                if (!$dt) {
1496
                    echo json_encode(['success' => false, 'data' => 'ERROR_SECURITY3']) ;
1452
                    echo json_encode(['success' => false, 'data' => 'ERROR_SECURITY3']);
1497
                    exit;
1453
                    exit;
1498
                }
1454
                }
1499
                
1455
 
1500
                $t0 = $dt->getTimestamp();
1456
                $t0 = $dt->getTimestamp();
1501
                $t1 = strtotime('-5 minutes');
1457
                $t1 = strtotime('-5 minutes');
1502
                $t2 = strtotime('+5 minutes');
1458
                $t2 = strtotime('+5 minutes');
1503
                
1459
 
1504
                if($t0 < $t1 || $t0 > $t2) {
1460
                if ($t0 < $t1 || $t0 > $t2) {
1505
                    //echo json_encode(['success' => false, 'data' => 'ERROR_SECURITY4']) ;
1461
                    //echo json_encode(['success' => false, 'data' => 'ERROR_SECURITY4']) ;
1506
                    //exit;
1462
                    //exit;
1507
                }
1463
                }
1508
                
1464
 
1509
                if(!password_verify( $username.'-'. $config_password . '-' . $rand. '-' . $timestamp, $password)) {
1465
                if (!password_verify($username . '-' . $config_password . '-' . $rand . '-' . $timestamp, $password)) {
1510
                    echo json_encode(['success' => false, 'data' => 'ERROR_SECURITY5']) ;
1466
                    echo json_encode(['success' => false, 'data' => 'ERROR_SECURITY5']);
1511
                    exit;
1467
                    exit;
1512
                }
1468
                }
1513
                
1469
 
1514
                if(empty($data)) {
1470
                if (empty($data)) {
1515
                    echo json_encode(['success' => false, 'data' => 'ERROR_PARAMETERS1']) ;
1471
                    echo json_encode(['success' => false, 'data' => 'ERROR_PARAMETERS1']);
1516
                    exit;
1472
                    exit;
1517
                }
1473
                }
1518
                
1474
 
1519
                $data = base64_decode($data);
1475
                $data = base64_decode($data);
1520
                if(empty($data)) {
1476
                if (empty($data)) {
1521
                    echo json_encode(['success' => false, 'data' => 'ERROR_PARAMETERS2']) ;
1477
                    echo json_encode(['success' => false, 'data' => 'ERROR_PARAMETERS2']);
1522
                    exit;
1478
                    exit;
1523
                }
1479
                }
1524
                
1480
 
1525
                
1481
 
1526
                try {
1482
                try {
1527
                    $rsa = Rsa::getInstance();
1483
                    $rsa = Rsa::getInstance();
1528
                    $data = $rsa->decrypt($data,  $config_rsa_d,  $config_rsa_n);
-
 
1529
                } catch (\Throwable $e)
1484
                    $data = $rsa->decrypt($data,  $config_rsa_d,  $config_rsa_n);
1530
                {
1485
                } catch (\Throwable $e) {
1531
                    echo json_encode(['success' => false, 'data' => 'ERROR_PARAMETERS3']) ;
1486
                    echo json_encode(['success' => false, 'data' => 'ERROR_PARAMETERS3']);
1532
                    exit;
1487
                    exit;
1533
                }
1488
                }
1534
                
1489
 
1535
                $data = (array) json_decode($data);
1490
                $data = (array) json_decode($data);
1536
                if(empty($data)) {
1491
                if (empty($data)) {
1537
                    echo json_encode(['success' => false, 'data' => 'ERROR_PARAMETERS4']) ;
1492
                    echo json_encode(['success' => false, 'data' => 'ERROR_PARAMETERS4']);
1538
                    exit;
1493
                    exit;
1539
                }
1494
                }
1540
                
1495
 
1541
                $email      = isset($data['email']) ? Functions::sanitizeFilterString($data['email']) : '';
1496
                $email      = isset($data['email']) ? Functions::sanitizeFilterString($data['email']) : '';
1542
                $first_name = isset($data['first_name']) ? Functions::sanitizeFilterString($data['first_name']) : '';
1497
                $first_name = isset($data['first_name']) ? Functions::sanitizeFilterString($data['first_name']) : '';
1543
                $last_name  = isset($data['last_name']) ? Functions::sanitizeFilterString($data['last_name']) : '';
1498
                $last_name  = isset($data['last_name']) ? Functions::sanitizeFilterString($data['last_name']) : '';
1544
                
1499
 
1545
                if(!filter_var($email, FILTER_VALIDATE_EMAIL) || empty($first_name) || empty($last_name)) {
1500
                if (!filter_var($email, FILTER_VALIDATE_EMAIL) || empty($first_name) || empty($last_name)) {
1546
                    echo json_encode(['success' => false, 'data' => 'ERROR_PARAMETERS5']) ;
1501
                    echo json_encode(['success' => false, 'data' => 'ERROR_PARAMETERS5']);
1547
                    exit;
1502
                    exit;
1548
                }
1503
                }
1549
                
1504
 
1550
                $userMapper = UserMapper::getInstance($this->adapter);
1505
                $userMapper = UserMapper::getInstance($this->adapter);
1551
                $user = $userMapper->fetchOneByEmail($email);
1506
                $user = $userMapper->fetchOneByEmail($email);
1552
                if(!$user) {
1507
                if (!$user) {
1553
                    
1508
 
1554
                    
1509
 
1555
                    $user = new User();
1510
                    $user = new User();
1556
                    $user->network_id = $currentNetwork->id;
1511
                    $user->network_id = $currentNetwork->id;
1557
                    $user->blocked = User::BLOCKED_NO;
1512
                    $user->blocked = User::BLOCKED_NO;
Línea 1562... Línea 1517...
1562
                    $user->login_attempt = 0;
1517
                    $user->login_attempt = 0;
1563
                    $user->password = '-NO-PASSWORD-';
1518
                    $user->password = '-NO-PASSWORD-';
1564
                    $user->usertype_id = UserType::USER;
1519
                    $user->usertype_id = UserType::USER;
1565
                    $user->status = User::STATUS_ACTIVE;
1520
                    $user->status = User::STATUS_ACTIVE;
1566
                    $user->show_in_search = User::SHOW_IN_SEARCH_YES;
1521
                    $user->show_in_search = User::SHOW_IN_SEARCH_YES;
1567
                    
1522
 
1568
                    if($userMapper->insert($user)) {
1523
                    if ($userMapper->insert($user)) {
1569
                        echo json_encode(['success' => false, 'data' => $userMapper->getError()]) ;
1524
                        echo json_encode(['success' => false, 'data' => $userMapper->getError()]);
1570
                        exit;
1525
                        exit;
1571
                    }
1526
                    }
1572
                    
1527
 
1573
                    
1528
 
1574
                    
1529
 
1575
                    
1530
 
1576
                    $filename   =trim( isset($data['avatar_filename']) ? filter_var($data['avatar_filename'], FILTER_SANITIZE_EMAIL) : '');
1531
                    $filename   = trim(isset($data['avatar_filename']) ? filter_var($data['avatar_filename'], FILTER_SANITIZE_EMAIL) : '');
1577
                    $content    = isset($data['avatar_content']) ? Functions::sanitizeFilterString($data['avatar_content']) : '';
1532
                    $content    = isset($data['avatar_content']) ? Functions::sanitizeFilterString($data['avatar_content']) : '';
1578
                    
1533
 
1579
                    if($filename && $content) {
1534
                    if ($filename && $content) {
1580
                        $source = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $filename;
1535
                        $source = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $filename;
1581
                        try {
1536
                        try {
1582
                            file_put_contents($source, base64_decode($content));
1537
                            file_put_contents($source, base64_decode($content));
1583
                            if (file_exists($source)) {
1538
                            if (file_exists($source)) {
1584
                                $target_path = $this->config['leaderslinked.fullpath.user'] . $user->uuid;
1539
                                $target_path = $this->config['leaderslinked.fullpath.user'] . $user->uuid;
1585
                                list( $target_width, $target_height ) = explode('x', $this->config['leaderslinked.image_sizes.user_size']);
1540
                                list($target_width, $target_height) = explode('x', $this->config['leaderslinked.image_sizes.user_size']);
1586
                                
1541
 
1587
                                $target_filename    = 'user-' . uniqid() . '.png';
1542
                                $target_filename    = 'user-' . uniqid() . '.png';
1588
                                $crop_to_dimensions = true;
1543
                                $crop_to_dimensions = true;
1589
                                
1544
 
1590
                                if(!Image::uploadImage($source, $target_path, $target_filename, $target_width, $target_height, $crop_to_dimensions)) {
1545
                                if (!Image::uploadImage($source, $target_path, $target_filename, $target_width, $target_height, $crop_to_dimensions)) {
1591
                                    return new JsonModel([
1546
                                    return new JsonModel([
1592
                                        'success'   => false,
1547
                                        'success'   => false,
1593
                                        'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
1548
                                        'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
1594
                                    ]);
1549
                                    ]);
1595
                                }
1550
                                }
1596
                                
1551
 
1597
                                $user->image = $target_filename;
1552
                                $user->image = $target_filename;
1598
                                $userMapper->updateImage($user);
1553
                                $userMapper->updateImage($user);
1599
                            }
1554
                            }
1600
                        } catch(\Throwable $e) {
1555
                        } catch (\Throwable $e) {
1601
                            
-
 
1602
                        } finally {
1556
                        } finally {
1603
                            if(file_exists($source)) {
1557
                            if (file_exists($source)) {
1604
                                unlink($source);
1558
                                unlink($source);
1605
                            }
1559
                            }
1606
                        }
1560
                        }
1607
                    }
1561
                    }
1608
                    
-
 
1609
                }
1562
                }
1610
                
1563
 
1611
                $auth = new AuthEmailAdapter($this->adapter);
1564
                $auth = new AuthEmailAdapter($this->adapter);
1612
                $auth->setData($email);
1565
                $auth->setData($email);
1613
                
1566
 
1614
                $result = $auth->authenticate();
1567
                $result = $auth->authenticate();
1615
                if($result->getCode() == AuthResult::SUCCESS) {
1568
                if ($result->getCode() == AuthResult::SUCCESS) {
1616
                    return $this->redirect()->toRoute('dashboard');
1569
                    return $this->redirect()->toRoute('dashboard');
1617
                    
-
 
1618
                    
-
 
1619
                } else {
1570
                } else {
1620
                    $message = $result->getMessages()[0];
1571
                    $message = $result->getMessages()[0];
-
 
1572
                    if (!in_array($message, [
1621
                    if(!in_array($message, ['ERROR_USER_NOT_FOUND', 'ERROR_USER_EMAIL_HASNT_BEEN_VARIFIED', 'ERROR_USER_IS_BLOCKED',
1573
                        'ERROR_USER_NOT_FOUND', 'ERROR_USER_EMAIL_HASNT_BEEN_VARIFIED', 'ERROR_USER_IS_BLOCKED',
1622
                        'ERROR_USER_IS_INACTIVE', 'ERROR_ENTERED_PASS_INCORRECT_USER_IS_BLOCKED', 'ERROR_ENTERED_PASS_INCORRECT_2',
1574
                        'ERROR_USER_IS_INACTIVE', 'ERROR_ENTERED_PASS_INCORRECT_USER_IS_BLOCKED', 'ERROR_ENTERED_PASS_INCORRECT_2',
1623
                        'ERROR_ENTERED_PASS_INCORRECT_1'])) {
1575
                        'ERROR_ENTERED_PASS_INCORRECT_1'
1624
                        
-
 
1625
                        
-
 
-
 
1576
                    ])) {
1626
                    }
1577
                    }
1627
                    
1578
 
1628
                    switch($message)
1579
                    switch ($message) {
1629
                    {
-
 
1630
                        case 'ERROR_USER_NOT_FOUND' :
1580
                        case 'ERROR_USER_NOT_FOUND':
1631
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Email no existe', ['ip' => Functions::getUserIP()]);
1581
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Email no existe', ['ip' => Functions::getUserIP()]);
1632
                            break;
1582
                            break;
1633
                            
1583
 
1634
                        case 'ERROR_USER_EMAIL_HASNT_BEEN_VARIFIED' :
1584
                        case 'ERROR_USER_EMAIL_HASNT_BEEN_VARIFIED':
1635
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Email no verificado', ['ip' => Functions::getUserIP()]);
1585
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Email no verificado', ['ip' => Functions::getUserIP()]);
1636
                            break;
1586
                            break;
1637
                            
1587
 
1638
                        case 'ERROR_USER_IS_BLOCKED' :
1588
                        case 'ERROR_USER_IS_BLOCKED':
1639
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Usuario bloqueado', ['ip' => Functions::getUserIP()]);
1589
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Usuario bloqueado', ['ip' => Functions::getUserIP()]);
1640
                            break;
1590
                            break;
1641
                            
1591
 
1642
                        case 'ERROR_USER_IS_INACTIVE' :
1592
                        case 'ERROR_USER_IS_INACTIVE':
1643
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Usuario inactivo', ['ip' => Functions::getUserIP()]);
1593
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Usuario inactivo', ['ip' => Functions::getUserIP()]);
1644
                            break;
1594
                            break;
1645
                            
1595
 
1646
                            
1596
 
1647
                        case 'ERROR_ENTERED_PASS_INCORRECT_USER_IS_BLOCKED':
1597
                        case 'ERROR_ENTERED_PASS_INCORRECT_USER_IS_BLOCKED':
1648
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - 3er Intento Usuario bloqueado', ['ip' => Functions::getUserIP()]);
1598
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - 3er Intento Usuario bloqueado', ['ip' => Functions::getUserIP()]);
1649
                            break;
1599
                            break;
1650
                            
1600
 
1651
                            
1601
 
1652
                        case 'ERROR_ENTERED_PASS_INCORRECT_2' :
1602
                        case 'ERROR_ENTERED_PASS_INCORRECT_2':
1653
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - 1er Intento', ['ip' => Functions::getUserIP()]);
1603
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - 1er Intento', ['ip' => Functions::getUserIP()]);
1654
                            break;
1604
                            break;
1655
                            
1605
 
1656
                            
1606
 
1657
                        case 'ERROR_ENTERED_PASS_INCORRECT_1' :
1607
                        case 'ERROR_ENTERED_PASS_INCORRECT_1':
1658
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - 2do Intento', ['ip' => Functions::getUserIP()]);
1608
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - 2do Intento', ['ip' => Functions::getUserIP()]);
1659
                            break;
1609
                            break;
1660
                            
1610
 
1661
                            
1611
 
1662
                        default :
1612
                        default:
1663
                            $message = 'ERROR_UNKNOWN';
1613
                            $message = 'ERROR_UNKNOWN';
1664
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Error desconocido', ['ip' => Functions::getUserIP()]);
1614
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Error desconocido', ['ip' => Functions::getUserIP()]);
1665
                            break;
1615
                            break;
1666
                            
-
 
1667
                            
-
 
1668
                    }
1616
                    }
1669
                    
1617
 
1670
                    
1618
 
1671
                    
1619
 
1672
                    
1620
 
1673
                    return new JsonModel( [
1621
                    return new JsonModel([
1674
                        'success'   => false,
1622
                        'success'   => false,
1675
                        'data'   => $message
1623
                        'data'   => $message
1676
                    ]);
1624
                    ]);
1677
                }
1625
                }
1678
                
-
 
1679
                
-
 
1680
                
-
 
1681
                
-
 
1682
            } else {
1626
            } else {
1683
                $messages = [];
1627
                $messages = [];
1684
                
1628
 
1685
                
1629
 
1686
                
1630
 
1687
                $form_messages = (array) $form->getMessages();
1631
                $form_messages = (array) $form->getMessages();
1688
                foreach($form_messages  as $fieldname => $field_messages)
1632
                foreach ($form_messages  as $fieldname => $field_messages) {
1689
                {
-
 
1690
                    
1633
 
1691
                    $messages[$fieldname] = array_values($field_messages);
1634
                    $messages[$fieldname] = array_values($field_messages);
1692
                }
1635
                }
1693
                
1636
 
1694
                return new JsonModel([
1637
                return new JsonModel([
1695
                    'success'   => false,
1638
                    'success'   => false,
1696
                    'data'   => $messages
1639
                    'data'   => $messages
1697
                ]);
1640
                ]);
1698
            }
1641
            }
1699
            
-
 
1700
        } else {
1642
        } else {
1701
            $data = [
1643
            $data = [
1702
                'success' => false,
1644
                'success' => false,
1703
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1645
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1704
            ];
1646
            ];
1705
            
1647
 
1706
            return new JsonModel($data);
1648
            return new JsonModel($data);
1707
        }
1649
        }
1708
        
1650
 
1709
        return new JsonModel($data);
1651
        return new JsonModel($data);
1710
    }
1652
    }
1711
    
1653
 
1712
    public function csrfAction()
1654
    public function csrfAction()
1713
    {
1655
    {
1714
        $request = $this->getRequest();
1656
        $request = $this->getRequest();
1715
        if($request->isGet()) {
1657
        if ($request->isGet()) {
1716
            
1658
 
1717
            $token = md5(uniqid('CSFR-' . mt_rand(), true));
1659
            $token = md5(uniqid('CSFR-' . mt_rand(), true));
1718
            $_SESSION['token'] = $token;
1660
            $_SESSION['token'] = $token;
1719
            
1661
 
1720
            
1662
 
1721
            return new JsonModel([
1663
            return new JsonModel([
1722
                'success' => true,
1664
                'success' => true,
1723
                'data' => $token
1665
                'data' => $token
1724
            ]);
1666
            ]);
1725
        
-
 
1726
        
-
 
1727
        } else {
1667
        } else {
1728
            return new JsonModel([
1668
            return new JsonModel([
1729
                'success' => false,
1669
                'success' => false,
1730
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1670
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1731
            ]);
1671
            ]);
1732
        }
1672
        }
1733
        
-
 
1734
        
-
 
1735
    }
1673
    }
1736
    
1674
 
1737
    public function impersonateAction()
1675
    public function impersonateAction()
1738
    {
1676
    {
1739
        $request = $this->getRequest();
1677
        $request = $this->getRequest();
1740
        if($request->isGet()) {
1678
        if ($request->isGet()) {
1741
            $user_uuid  = Functions::sanitizeFilterString($this->params()->fromQuery('user_uuid'));
1679
            $user_uuid  = Functions::sanitizeFilterString($this->params()->fromQuery('user_uuid'));
1742
            $rand       = filter_var($this->params()->fromQuery('rand'), FILTER_SANITIZE_NUMBER_INT);
1680
            $rand       = filter_var($this->params()->fromQuery('rand'), FILTER_SANITIZE_NUMBER_INT);
1743
            $timestamp  = filter_var($this->params()->fromQuery('time'), FILTER_SANITIZE_NUMBER_INT);
1681
            $timestamp  = filter_var($this->params()->fromQuery('time'), FILTER_SANITIZE_NUMBER_INT);
1744
            $password   = Functions::sanitizeFilterString($this->params()->fromQuery('password'));
1682
            $password   = Functions::sanitizeFilterString($this->params()->fromQuery('password'));
1745
            
1683
 
1746
            
1684
 
1747
            if(!$user_uuid || !$rand || !$timestamp || !$password ) {
1685
            if (!$user_uuid || !$rand || !$timestamp || !$password) {
1748
                throw new \Exception('ERROR_PARAMETERS_ARE_INVALID');
1686
                throw new \Exception('ERROR_PARAMETERS_ARE_INVALID');
1749
            }
1687
            }
1750
            
1688
 
1751
            
1689
 
1752
            $currentUserPlugin = $this->plugin('currentUserPlugin');
1690
            $currentUserPlugin = $this->plugin('currentUserPlugin');
1753
            $currentUserPlugin->clearIdentity();
1691
            $currentUserPlugin->clearIdentity();
1754
            
1692
 
1755
            
1693
 
1756
            $authAdapter = new AuthImpersonateAdapter($this->adapter, $this->config);
1694
            $authAdapter = new AuthImpersonateAdapter($this->adapter, $this->config);
1757
            $authAdapter->setDataAdmin($user_uuid, $password, $timestamp, $rand);
1695
            $authAdapter->setDataAdmin($user_uuid, $password, $timestamp, $rand);
1758
            
1696
 
1759
            $authService = new AuthenticationService();
1697
            $authService = new AuthenticationService();
1760
            $result = $authService->authenticate($authAdapter);
1698
            $result = $authService->authenticate($authAdapter);
1761
            
1699
 
1762
            
1700
 
1763
            if($result->getCode() == AuthResult::SUCCESS) {
1701
            if ($result->getCode() == AuthResult::SUCCESS) {
1764
                return $this->redirect()->toRoute('dashboard');
1702
                return $this->redirect()->toRoute('dashboard');
1765
            } else {
1703
            } else {
1766
                throw new \Exception($result->getMessages()[0]);
1704
                throw new \Exception($result->getMessages()[0]);
1767
            }
1705
            }
1768
        }
1706
        }
1769
        
1707
 
1770
        return new JsonModel([
1708
        return new JsonModel([
1771
            'success' => false,
1709
            'success' => false,
1772
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1710
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1773
        ]);
1711
        ]);
1774
    }
1712
    }
1775
   
-
 
1776
}
1713
}