Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

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