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