1 |
www |
1 |
<?php
|
|
|
2 |
declare(strict_types=1);
|
|
|
3 |
|
|
|
4 |
namespace LeadersLinked\Controller;
|
|
|
5 |
|
|
|
6 |
use Laminas\Db\Adapter\AdapterInterface;
|
|
|
7 |
|
|
|
8 |
|
16768 |
efrain |
9 |
|
1 |
www |
10 |
use Laminas\Mvc\Controller\AbstractActionController;
|
|
|
11 |
use Laminas\Log\LoggerInterface;
|
|
|
12 |
|
|
|
13 |
use Laminas\View\Model\ViewModel;
|
|
|
14 |
use Laminas\View\Model\JsonModel;
|
|
|
15 |
use LeadersLinked\Library\Functions;
|
|
|
16 |
use LeadersLinked\Mapper\UserMapper;
|
|
|
17 |
use LeadersLinked\Mapper\UserPasswordMapper;
|
|
|
18 |
|
|
|
19 |
use LeadersLinked\Model\User;
|
|
|
20 |
use LeadersLinked\Form\ChangePasswordForm;
|
|
|
21 |
use LeadersLinked\Model\CompanyUser;
|
|
|
22 |
use LeadersLinked\Mapper\CompanyUserMapper;
|
|
|
23 |
use LeadersLinked\Mapper\CompanyUserRoleMapper;
|
|
|
24 |
use LeadersLinked\Mapper\RoleMapper;
|
|
|
25 |
use LeadersLinked\Model\UserType;
|
|
|
26 |
use LeadersLinked\Model\UserPassword;
|
|
|
27 |
use PhpOffice\PhpSpreadsheet\IOFactory;
|
|
|
28 |
use LeadersLinked\Form\UserUploadForm;
|
|
|
29 |
use LeadersLinked\Mapper\CompanyServiceMapper;
|
|
|
30 |
use LeadersLinked\Model\CompanyService;
|
|
|
31 |
use LeadersLinked\Model\Role;
|
|
|
32 |
use LeadersLinked\Mapper\CompanyRoleMapper;
|
|
|
33 |
use LeadersLinked\Model\CompanyUserRole;
|
|
|
34 |
use LeadersLinked\Model\Notification;
|
|
|
35 |
use LeadersLinked\Model\EmailTemplate;
|
|
|
36 |
use LeadersLinked\Mapper\NotificationMapper;
|
|
|
37 |
use LeadersLinked\Mapper\UserNotificationSettingMapper;
|
|
|
38 |
use LeadersLinked\Mapper\EmailTemplateMapper;
|
|
|
39 |
use LeadersLinked\Library\QueueEmail;
|
15351 |
efrain |
40 |
use LeadersLinked\Mapper\NetworkMapper;
|
|
|
41 |
use LeadersLinked\Model\Network;
|
15460 |
efrain |
42 |
use LeadersLinked\Mapper\CompanyMapper;
|
|
|
43 |
use LeadersLinked\Mapper\ConnectionMapper;
|
|
|
44 |
use LeadersLinked\Model\Connection;
|
|
|
45 |
use LeadersLinked\Mapper\CompanyFollowerMapper;
|
|
|
46 |
use LeadersLinked\Model\CompanyFollower;
|
|
|
47 |
use LeadersLinked\Mapper\CountryMapper;
|
|
|
48 |
use LeadersLinked\Mapper\LocationMapper;
|
|
|
49 |
use LeadersLinked\Model\Location;
|
16248 |
efrain |
50 |
use LeadersLinked\Form\User\ChangeTypeForm;
|
16299 |
efrain |
51 |
use LeadersLinked\Form\User\NetworkDataForm;
|
16768 |
efrain |
52 |
use LeadersLinked\Cache\CacheInterface;
|
|
|
53 |
use LeadersLinked\Cache\CacheImpl;
|
1 |
www |
54 |
|
|
|
55 |
class UserController extends AbstractActionController
|
|
|
56 |
{
|
|
|
57 |
/**
|
|
|
58 |
*
|
16769 |
efrain |
59 |
* @var \Laminas\Db\Adapter\AdapterInterface
|
1 |
www |
60 |
*/
|
|
|
61 |
private $adapter;
|
|
|
62 |
|
|
|
63 |
/**
|
|
|
64 |
*
|
16769 |
efrain |
65 |
* @var \LeadersLinked\Cache\CacheInterface
|
1 |
www |
66 |
*/
|
16769 |
efrain |
67 |
private $cache;
|
|
|
68 |
|
|
|
69 |
|
|
|
70 |
/**
|
|
|
71 |
*
|
|
|
72 |
* @var \Laminas\Log\LoggerInterface
|
|
|
73 |
*/
|
1 |
www |
74 |
private $logger;
|
|
|
75 |
|
|
|
76 |
/**
|
|
|
77 |
*
|
|
|
78 |
* @var array
|
|
|
79 |
*/
|
|
|
80 |
private $config;
|
|
|
81 |
|
16769 |
efrain |
82 |
|
16768 |
efrain |
83 |
/**
|
16769 |
efrain |
84 |
*
|
|
|
85 |
* @var \Laminas\Mvc\I18n\Translator
|
16768 |
efrain |
86 |
*/
|
16769 |
efrain |
87 |
private $translator;
|
1 |
www |
88 |
|
16768 |
efrain |
89 |
|
1 |
www |
90 |
/**
|
|
|
91 |
*
|
16769 |
efrain |
92 |
* @param \Laminas\Db\Adapter\AdapterInterface $adapter
|
|
|
93 |
* @param \LeadersLinked\Cache\CacheInterface $cache
|
|
|
94 |
* @param \Laminas\Log\LoggerInterface LoggerInterface $logger
|
1 |
www |
95 |
* @param array $config
|
16769 |
efrain |
96 |
* @param \Laminas\Mvc\I18n\Translator $translator
|
1 |
www |
97 |
*/
|
16769 |
efrain |
98 |
public function __construct($adapter, $cache, $logger, $config, $translator)
|
1 |
www |
99 |
{
|
16769 |
efrain |
100 |
$this->adapter = $adapter;
|
|
|
101 |
$this->cache = $cache;
|
|
|
102 |
$this->logger = $logger;
|
|
|
103 |
$this->config = $config;
|
|
|
104 |
$this->translator = $translator;
|
1 |
www |
105 |
}
|
|
|
106 |
|
|
|
107 |
public function indexAction()
|
|
|
108 |
{
|
|
|
109 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
110 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
111 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
112 |
|
15351 |
efrain |
113 |
$currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
|
16299 |
efrain |
114 |
$currentNetwork = $currentNetworkPlugin->getNetwork();
|
15351 |
efrain |
115 |
|
|
|
116 |
|
1 |
www |
117 |
$request = $this->getRequest();
|
|
|
118 |
|
|
|
119 |
if($request->isGet())
|
|
|
120 |
|
|
|
121 |
|
|
|
122 |
$headers = $request->getHeaders();
|
|
|
123 |
|
|
|
124 |
$isJson = false;
|
|
|
125 |
if($headers->has('Accept')) {
|
|
|
126 |
$accept = $headers->get('Accept');
|
|
|
127 |
|
|
|
128 |
$prioritized = $accept->getPrioritized();
|
|
|
129 |
|
|
|
130 |
foreach($prioritized as $key => $value) {
|
|
|
131 |
$raw = trim($value->getRaw());
|
|
|
132 |
|
|
|
133 |
if(!$isJson) {
|
|
|
134 |
$isJson = strpos($raw, 'json');
|
|
|
135 |
}
|
|
|
136 |
|
|
|
137 |
}
|
|
|
138 |
}
|
|
|
139 |
|
|
|
140 |
if($isJson) {
|
|
|
141 |
{
|
16299 |
efrain |
142 |
$network_id = $this->params()->fromQuery('network_id');
|
|
|
143 |
if($currentUser->is_super_user == User::IS_SUPER_USER_YES) {
|
|
|
144 |
|
|
|
145 |
$networkMapper = NetworkMapper::getInstance($this->adapter);
|
|
|
146 |
$network = $networkMapper->fetchOneByUuid($network_id);
|
|
|
147 |
if(!$network) {
|
|
|
148 |
$network = $currentNetwork;
|
|
|
149 |
}
|
|
|
150 |
} else {
|
|
|
151 |
$network = $currentNetwork;
|
|
|
152 |
|
|
|
153 |
}
|
|
|
154 |
|
|
|
155 |
|
15351 |
efrain |
156 |
|
1 |
www |
157 |
$search = $this->params()->fromQuery('search', []);
|
16766 |
efrain |
158 |
$search = empty($search['value']) ? '' : Functions::sanitizeFilterString($search['value']);
|
1 |
www |
159 |
|
3343 |
efrain |
160 |
//$page = intval($this->params()->fromQuery('start', 1), 10);
|
|
|
161 |
//$records_x_page = intval($this->params()->fromQuery('length', 10), 10);
|
|
|
162 |
|
1 |
www |
163 |
$records_x_page = intval($this->params()->fromQuery('length', 10), 10);
|
3343 |
efrain |
164 |
$page = (intval($this->params()->fromQuery('start', 1), 10)/$records_x_page)+1;
|
|
|
165 |
|
1 |
www |
166 |
$order = $this->params()->fromQuery('order', []);
|
|
|
167 |
$order_field = empty($order[0]['column']) ? 99 : intval($order[0]['column'], 10);
|
16766 |
efrain |
168 |
$order_direction = empty($order[0]['dir']) ? 'ASC' : strtoupper(Functions::sanitizeFilterString($order[0]['dir']));
|
1 |
www |
169 |
|
|
|
170 |
$fields = ['first_name', 'last_name', 'email'];
|
|
|
171 |
$order_field = isset($fields[$order_field]) ? $fields[$order_field] : 'first_name';
|
|
|
172 |
|
|
|
173 |
if(!in_array($order_direction, ['ASC', 'DESC'])) {
|
|
|
174 |
$order_direction = 'ASC';
|
|
|
175 |
}
|
|
|
176 |
|
|
|
177 |
|
|
|
178 |
if($currentCompany) {
|
|
|
179 |
$companyUserRoleMapper = CompanyUserRoleMapper::getInstance($this->adapter);
|
|
|
180 |
|
|
|
181 |
$roles = [];
|
|
|
182 |
$roleMapper = RoleMapper::getInstance($this->adapter);
|
|
|
183 |
$records = $roleMapper->fetchAll();
|
|
|
184 |
foreach ($records as $record)
|
|
|
185 |
{
|
|
|
186 |
$roles[ $record->id ] = $record->name;
|
|
|
187 |
}
|
|
|
188 |
|
|
|
189 |
|
|
|
190 |
//Usuarios cuando el nivel es empresa
|
|
|
191 |
|
|
|
192 |
$acl = $this->getEvent()->getViewModel()->getVariable('acl');
|
|
|
193 |
$allowUnblock = $acl->isAllowed($currentUser->usertype_id, 'users/unblock');
|
|
|
194 |
$allowChangePassword = $acl->isAllowed($currentUser->usertype_id, 'users/change-password');
|
|
|
195 |
|
|
|
196 |
$allowAccept = $acl->isAllowed($currentUser->usertype_id, 'users/accept') ? 1 : 0;
|
|
|
197 |
$allowCancel = $acl->isAllowed($currentUser->usertype_id, 'users/cancel') ? 1 : 0;
|
|
|
198 |
$allowReject = $acl->isAllowed($currentUser->usertype_id, 'users/reject') ? 1 : 0;
|
|
|
199 |
$allowEdit = $acl->isAllowed($currentUser->usertype_id, 'users/edit') ? 1 : 0;
|
|
|
200 |
|
16248 |
efrain |
201 |
|
1 |
www |
202 |
|
16766 |
efrain |
203 |
$status = Functions::sanitizeFilterString($this->params()->fromQuery('status'));
|
1 |
www |
204 |
if(!in_array($status, [
|
|
|
205 |
CompanyUser::STATUS_ACCEPTED,
|
|
|
206 |
CompanyUser::STATUS_ADMIN_WILL_ADD,
|
|
|
207 |
CompanyUser::STATUS_CANCELLED,
|
|
|
208 |
CompanyUser::STATUS_PENDING,
|
|
|
209 |
CompanyUser::STATUS_REJECTED,
|
|
|
210 |
CompanyUser::STATUS_SENT,
|
|
|
211 |
])) {
|
|
|
212 |
$status = '';
|
|
|
213 |
}
|
|
|
214 |
|
|
|
215 |
|
|
|
216 |
|
|
|
217 |
$userMapper = UserMapper::getInstance($this->adapter);
|
|
|
218 |
$companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
|
|
|
219 |
|
16767 |
efrain |
220 |
$paginator = $userMapper->fetchAllDataTableByCompanyId($currentCompany->id, $search, $status, $page, $records_x_page, $order_field, $order_direction);
|
1 |
www |
221 |
|
|
|
222 |
$items = [];
|
|
|
223 |
$records = $paginator->getCurrentItems();
|
|
|
224 |
|
|
|
225 |
foreach($records as $record)
|
|
|
226 |
{
|
|
|
227 |
|
|
|
228 |
$actions = [];
|
15351 |
efrain |
229 |
$actions['link_profile'] = 'https://'. $network->main_hostname . '/profile/view/' . $record['uuid'];
|
1 |
www |
230 |
|
|
|
231 |
|
|
|
232 |
|
|
|
233 |
|
|
|
234 |
$details = [];
|
|
|
235 |
switch ($record['status'])
|
|
|
236 |
{
|
|
|
237 |
|
|
|
238 |
case CompanyUser::STATUS_PENDING :
|
|
|
239 |
$details['status'] = 'LABEL_PENDING';
|
|
|
240 |
$actions['link_accept'] = $allowAccept ? $this->url()->fromRoute('users/accept', ['id' => $record['uuid']]) : '';
|
|
|
241 |
$actions['link_reject'] = $allowReject ? $this->url()->fromRoute('users/reject', ['id' => $record['uuid']]) : '';
|
|
|
242 |
break;
|
|
|
243 |
|
|
|
244 |
case CompanyUser::STATUS_ACCEPTED :
|
|
|
245 |
$details['status'] = 'LABEL_ACCEPTED';
|
|
|
246 |
if($record['creator'] == CompanyUser::CREATOR_NO) {
|
|
|
247 |
$actions['link_edit'] = $allowEdit ? $this->url()->fromRoute('users/edit', ['id' => $record['uuid']]) : '';
|
|
|
248 |
|
|
|
249 |
|
|
|
250 |
|
|
|
251 |
$actions['link_cancel'] = $allowCancel ? $this->url()->fromRoute('users/cancel', ['id' => $record['uuid']]) : '';
|
|
|
252 |
}
|
|
|
253 |
|
|
|
254 |
break;
|
|
|
255 |
|
|
|
256 |
case CompanyUser::STATUS_ADMIN_WILL_ADD :
|
|
|
257 |
$details['status'] = 'LABEL_ADMIN_WILL_ADD';
|
|
|
258 |
$actions['link_cancel'] = $allowCancel ? $this->url()->fromRoute('users/cancel', ['id' => $record['uuid']]) : '';
|
|
|
259 |
$actions['link_edit'] = $allowEdit ? $this->url()->fromRoute('users/edit', ['id' => $record['uuid']]) : '';
|
|
|
260 |
|
|
|
261 |
break;
|
|
|
262 |
|
|
|
263 |
case CompanyUser::STATUS_SENT :
|
|
|
264 |
$details['status'] = 'LABEL_INVITED';
|
|
|
265 |
$actions['link_accept'] = $allowAccept ? $this->url()->fromRoute('users/accept', ['id' => $record['uuid']]) : '';
|
|
|
266 |
$actions['link_reject'] = $allowReject ? $this->url()->fromRoute('users/reject', ['id' => $record['uuid']]) : '';
|
|
|
267 |
break;
|
|
|
268 |
|
|
|
269 |
case CompanyUser::STATUS_REJECTED :
|
|
|
270 |
$actions['link_accept'] = $allowAccept ? $this->url()->fromRoute('users/accept', ['id' => $record['uuid']]) : '';
|
|
|
271 |
$details['status'] = 'LABEL_REJECTED';
|
|
|
272 |
break;
|
|
|
273 |
|
|
|
274 |
case CompanyUser::STATUS_CANCELLED :
|
|
|
275 |
$actions['link_accept'] = $allowAccept ? $this->url()->fromRoute('users/accept', ['id' => $record['uuid']]) : '';
|
|
|
276 |
$details['status'] = 'LABEL_CANCELLED';
|
|
|
277 |
break;
|
|
|
278 |
|
|
|
279 |
default :
|
|
|
280 |
$details['status'] = '';
|
|
|
281 |
break;
|
|
|
282 |
|
|
|
283 |
}
|
|
|
284 |
|
|
|
285 |
$totalOtherCompanies = $companyUserMapper->fetchCountOtherCompaniesByCompanyIdAndUserId($currentCompany->id, $record['id']);
|
|
|
286 |
if(!$totalOtherCompanies) {
|
|
|
287 |
|
|
|
288 |
$actions['link_change_password'] = $allowChangePassword ? $this->url()->fromRoute('users/change-password', ['id' => $record['uuid'] ]) : '';
|
|
|
289 |
if($record['blocked'] == User::BLOCKED_YES ) {
|
|
|
290 |
$actions['link_unblock'] = $allowUnblock ? $this->url()->fromRoute('users/unblock', ['id' => $record['uuid'] ]) : '';
|
|
|
291 |
}
|
|
|
292 |
}
|
|
|
293 |
|
|
|
294 |
if($record['blocked'] == User::BLOCKED_YES ) {
|
|
|
295 |
$details['blocked'] = 'LABEL_YES';
|
|
|
296 |
} else if($record['blocked'] == User::BLOCKED_NO ) {
|
|
|
297 |
$details['blocked'] = 'LABEL_NO';
|
|
|
298 |
}
|
|
|
299 |
if($record['email_verified'] == User::EMAIL_VERIFIED_YES ) {
|
|
|
300 |
$details['email_verified'] = 'LABEL_YES';
|
|
|
301 |
|
|
|
302 |
} else if($record['email_verified'] == User::EMAIL_VERIFIED_NO ) {
|
|
|
303 |
$details['email_verified'] = 'LABEL_NO';
|
|
|
304 |
}
|
|
|
305 |
$details['login_attempt'] = $record['login_attempt'];
|
|
|
306 |
|
|
|
307 |
|
|
|
308 |
$company_user_roles = $companyUserRoleMapper->fetchAllByCompanyIdAndUserId($currentCompany->id, $record['id']);
|
|
|
309 |
|
|
|
310 |
$details['roles'] = [];
|
|
|
311 |
|
|
|
312 |
if($record['creator'] == CompanyUser::CREATOR_YES) {
|
|
|
313 |
$details['roles'][] = 'LABEL_ALL_PERMITS';
|
|
|
314 |
$details['creator'] = 'LABEL_YES' ;
|
|
|
315 |
} else {
|
|
|
316 |
$details['creator'] = 'LABEL_NO';
|
|
|
317 |
foreach($company_user_roles as $company_user_role)
|
|
|
318 |
{
|
|
|
319 |
$role = $roles[ $company_user_role->role_id ];
|
|
|
320 |
$details['roles'][] = $role;
|
|
|
321 |
|
|
|
322 |
}
|
|
|
323 |
}
|
|
|
324 |
|
|
|
325 |
|
|
|
326 |
$details['backend'] = $record['backend'] == CompanyUser::BACKEND_YES ? 'LABEL_YES' : 'LABEL_NO';
|
|
|
327 |
|
|
|
328 |
|
|
|
329 |
|
|
|
330 |
|
|
|
331 |
|
|
|
332 |
|
|
|
333 |
$item = [
|
|
|
334 |
'first_name' => $record['first_name'] ,
|
|
|
335 |
'last_name' => $record['last_name'],
|
|
|
336 |
'email' => $record['email'],
|
|
|
337 |
'details' => $details,
|
|
|
338 |
'actions' => $actions ,
|
|
|
339 |
];
|
|
|
340 |
|
|
|
341 |
array_push($items, $item);
|
|
|
342 |
}
|
|
|
343 |
} else {
|
|
|
344 |
//Usuario cuando el nivel es administrador
|
|
|
345 |
|
|
|
346 |
|
|
|
347 |
|
|
|
348 |
$acl = $this->getEvent()->getViewModel()->getVariable('acl');
|
|
|
349 |
$allowUnblock = $acl->isAllowed($currentUser->usertype_id, 'users/unblock');
|
|
|
350 |
$allowChangePassword = $acl->isAllowed($currentUser->usertype_id, 'users/change-password');
|
16248 |
efrain |
351 |
$allowChangeType = $acl->isAllowed($currentUser->usertype_id, 'users/change-type') ? 1 : 0;
|
1 |
www |
352 |
|
16248 |
efrain |
353 |
|
|
|
354 |
|
1 |
www |
355 |
$userMapper = UserMapper::getInstance($this->adapter);
|
15455 |
efrain |
356 |
$paginator = $userMapper->fetchAllDataTableByNetworkId($network->id, $search, $page, $records_x_page, $order_field, $order_direction);
|
1 |
www |
357 |
|
|
|
358 |
$items = [];
|
|
|
359 |
$records = $paginator->getCurrentItems();
|
|
|
360 |
|
|
|
361 |
foreach($records as $record)
|
|
|
362 |
{
|
|
|
363 |
$actions = [];
|
|
|
364 |
|
16299 |
efrain |
365 |
if($currentNetwork->id == $record->network_id) {
|
1 |
www |
366 |
|
16299 |
efrain |
367 |
$actions['link_profile'] = 'https://'. $network->main_hostname . '/profile/view/' . $record->uuid;
|
|
|
368 |
} else {
|
|
|
369 |
$actions['link_profile'] = '';
|
|
|
370 |
}
|
|
|
371 |
|
1 |
www |
372 |
$details = [] ;
|
|
|
373 |
if($record->status == User::STATUS_ACTIVE ) {
|
|
|
374 |
$details['status'] = 'LABEL_ACTIVE';
|
|
|
375 |
} else if($record->status == User::STATUS_INACTIVE ) {
|
|
|
376 |
$details['status'] = 'LABEL_INACTIVE';
|
|
|
377 |
}
|
|
|
378 |
if($record->blocked == User::BLOCKED_YES ) {
|
|
|
379 |
$details['blocked'] = 'LABEL_YES';
|
|
|
380 |
} else if($record->blocked == User::BLOCKED_NO ) {
|
|
|
381 |
$details['blocked'] = 'LABEL_NO';
|
|
|
382 |
}
|
|
|
383 |
if($record->email_verified == User::EMAIL_VERIFIED_YES ) {
|
|
|
384 |
$details['email_verified'] = 'LABEL_YES';
|
|
|
385 |
|
|
|
386 |
} else if($record->email_verified == User::EMAIL_VERIFIED_NO ) {
|
|
|
387 |
$details['email_verified'] = 'LABEL_NO';
|
|
|
388 |
}
|
16248 |
efrain |
389 |
|
|
|
390 |
if($record->usertype_id == UserType::ADMIN) {
|
|
|
391 |
$details['user_type'] = 'LABEL_ADMINISTRATOR';
|
|
|
392 |
} else if($record->usertype_id == UserType::USER) {
|
|
|
393 |
$details['user_type'] = 'LABEL_USER';
|
|
|
394 |
}
|
|
|
395 |
|
1 |
www |
396 |
$details['login_attempt'] = $record->login_attempt;
|
|
|
397 |
|
|
|
398 |
|
|
|
399 |
$actions['link_change_password'] = $allowChangePassword ? $this->url()->fromRoute('users/change-password', ['id' => $record->uuid ]) : '';
|
|
|
400 |
$actions['link_unblock'] = $allowUnblock && $record->blocked == User::BLOCKED_YES ? $this->url()->fromRoute('users/unblock', ['id' => $record->uuid ]) : '';
|
16248 |
efrain |
401 |
$actions['link_change_type'] = $record->is_super_user == User::IS_SUPER_USER_NO && $allowChangeType ? $this->url()->fromRoute('users/change-type', ['id' => $record->uuid ]) : '';
|
|
|
402 |
|
|
|
403 |
|
1 |
www |
404 |
$item = [
|
|
|
405 |
'first_name' => $record->first_name,
|
|
|
406 |
'last_name' => $record->last_name,
|
|
|
407 |
'email' => $record->email,
|
|
|
408 |
'details' => $details,
|
|
|
409 |
'actions' => $actions
|
|
|
410 |
];
|
|
|
411 |
|
|
|
412 |
array_push($items, $item);
|
|
|
413 |
}
|
|
|
414 |
}
|
|
|
415 |
}
|
|
|
416 |
|
|
|
417 |
return new JsonModel([
|
|
|
418 |
'success' => true,
|
|
|
419 |
'data' => [
|
|
|
420 |
'items' => $items,
|
|
|
421 |
'total' => $paginator->getTotalItemCount(),
|
|
|
422 |
]
|
|
|
423 |
]);
|
|
|
424 |
|
|
|
425 |
|
|
|
426 |
|
|
|
427 |
}
|
|
|
428 |
else if($request->isGet()) {
|
|
|
429 |
$this->layout()->setTemplate('layout/layout-backend');
|
|
|
430 |
$viewModel = new ViewModel();
|
|
|
431 |
|
15460 |
efrain |
432 |
|
16299 |
efrain |
433 |
$networks = [];
|
|
|
434 |
$networkMapper = NetworkMapper::getInstance($this->adapter);
|
|
|
435 |
|
|
|
436 |
if($currentUser->is_super_user == User::IS_SUPER_USER_YES) {
|
|
|
437 |
$records = $networkMapper->fetchAll();
|
|
|
438 |
foreach($records as $record)
|
|
|
439 |
{
|
|
|
440 |
$networks[ $record->uuid ] = $record->name;
|
|
|
441 |
}
|
|
|
442 |
|
|
|
443 |
} else {
|
|
|
444 |
$networks[ $currentNetwork->uuid ] = $currentNetwork->name;
|
|
|
445 |
|
|
|
446 |
}
|
|
|
447 |
|
|
|
448 |
|
|
|
449 |
$formFilter = new NetworkDataForm($networks);
|
15460 |
efrain |
450 |
$formUploadUsers = new UserUploadForm();
|
1 |
www |
451 |
$formChangePassword = new ChangePasswordForm();
|
16248 |
efrain |
452 |
$formChangeType = new ChangeTypeForm();
|
|
|
453 |
|
1 |
www |
454 |
$company = $currentUserPlugin->getCompany();
|
|
|
455 |
if($company) {
|
|
|
456 |
$viewModel->setTemplate('leaders-linked/users/company.phtml');
|
15460 |
efrain |
457 |
|
1 |
www |
458 |
} else {
|
|
|
459 |
$viewModel->setTemplate('leaders-linked/users/index.phtml');
|
|
|
460 |
}
|
15460 |
efrain |
461 |
$viewModel->setVariables([
|
|
|
462 |
'formUploadUsers' => $formUploadUsers,
|
|
|
463 |
'formChangePassword' => $formChangePassword,
|
16248 |
efrain |
464 |
'formChangeType' => $formChangeType,
|
16299 |
efrain |
465 |
'formFilter' => $formFilter
|
15460 |
efrain |
466 |
] );
|
1 |
www |
467 |
return $viewModel ;
|
|
|
468 |
|
|
|
469 |
} else {
|
|
|
470 |
return new JsonModel([
|
|
|
471 |
'success' => false,
|
|
|
472 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
473 |
]);;
|
|
|
474 |
}
|
|
|
475 |
}
|
|
|
476 |
/*
|
|
|
477 |
public function addAction()
|
|
|
478 |
{
|
|
|
479 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
480 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
481 |
|
|
|
482 |
$request = $this->getRequest();
|
|
|
483 |
|
|
|
484 |
|
|
|
485 |
if($request->isPost()) {
|
|
|
486 |
$form = new AddForm($this->adapter);
|
|
|
487 |
$dataPost = $request->getPost()->toArray();
|
|
|
488 |
|
|
|
489 |
$form->setData($dataPost);
|
|
|
490 |
|
|
|
491 |
if($form->isValid()) {
|
|
|
492 |
$dataPost = (array) $form->getData();
|
|
|
493 |
|
|
|
494 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
495 |
$user = new User();
|
|
|
496 |
$hydrator->hydrate($dataPost, $user);
|
|
|
497 |
|
|
|
498 |
|
|
|
499 |
$userMapper = UserMapper::getInstance($this->adapter);
|
|
|
500 |
$result = $userMapper->insert($user);
|
|
|
501 |
|
|
|
502 |
if($result) {
|
|
|
503 |
$this->logger->info('Se agrego el usuario ' . $user->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
|
|
504 |
|
|
|
505 |
$data = [
|
|
|
506 |
'success' => true,
|
|
|
507 |
'data' => 'LABEL_RECORD_ADDED'
|
|
|
508 |
];
|
|
|
509 |
} else {
|
|
|
510 |
$data = [
|
|
|
511 |
'success' => false,
|
|
|
512 |
'data' => $userMapper->getError()
|
|
|
513 |
];
|
|
|
514 |
|
|
|
515 |
}
|
|
|
516 |
|
|
|
517 |
return new JsonModel($data);
|
|
|
518 |
|
|
|
519 |
} else {
|
|
|
520 |
$messages = [];
|
|
|
521 |
$form_messages = (array) $form->getMessages();
|
|
|
522 |
foreach($form_messages as $fieldname => $field_messages)
|
|
|
523 |
{
|
|
|
524 |
|
|
|
525 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
526 |
}
|
|
|
527 |
|
|
|
528 |
return new JsonModel([
|
|
|
529 |
'success' => false,
|
|
|
530 |
'data' => $messages
|
|
|
531 |
]);
|
|
|
532 |
}
|
|
|
533 |
|
|
|
534 |
} else {
|
|
|
535 |
$data = [
|
|
|
536 |
'success' => false,
|
|
|
537 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
538 |
];
|
|
|
539 |
|
|
|
540 |
return new JsonModel($data);
|
|
|
541 |
}
|
|
|
542 |
|
|
|
543 |
return new JsonModel($data);
|
|
|
544 |
}
|
|
|
545 |
|
|
|
546 |
public function editAction()
|
|
|
547 |
{
|
|
|
548 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
549 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
550 |
|
|
|
551 |
$request = $this->getRequest();
|
|
|
552 |
$id = $this->params()->fromRoute('id');
|
|
|
553 |
|
|
|
554 |
|
|
|
555 |
if(!$id) {
|
|
|
556 |
$data = [
|
|
|
557 |
'success' => false,
|
|
|
558 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
559 |
];
|
|
|
560 |
|
|
|
561 |
return new JsonModel($data);
|
|
|
562 |
}
|
|
|
563 |
|
|
|
564 |
$userMapper = UserMapper::getInstance($this->adapter);
|
|
|
565 |
$user = $userMapper->fetchOne($id);
|
|
|
566 |
if(!$user) {
|
|
|
567 |
$data = [
|
|
|
568 |
'success' => false,
|
|
|
569 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
570 |
];
|
|
|
571 |
|
|
|
572 |
return new JsonModel($data);
|
|
|
573 |
}
|
|
|
574 |
|
|
|
575 |
if($request->isPost()) {
|
|
|
576 |
$form = new EditForm($this->adapter);
|
|
|
577 |
$dataPost = $request->getPost()->toArray();
|
|
|
578 |
|
|
|
579 |
$form->setData($dataPost);
|
|
|
580 |
|
|
|
581 |
if($form->isValid()) {
|
|
|
582 |
$dataPost = (array) $form->getData();
|
|
|
583 |
|
|
|
584 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
585 |
$hydrator->hydrate($dataPost, $user);
|
|
|
586 |
$result = $userMapper->update($user);
|
|
|
587 |
|
|
|
588 |
if($result) {
|
|
|
589 |
$this->logger->info('Se actualizo el usuario ' . $user->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
|
|
590 |
|
|
|
591 |
$data = [
|
|
|
592 |
'success' => true,
|
|
|
593 |
'data' => 'LABEL_RECORD_UPDATED'
|
|
|
594 |
];
|
|
|
595 |
} else {
|
|
|
596 |
$data = [
|
|
|
597 |
'success' => false,
|
|
|
598 |
'data' => $userMapper->getError()
|
|
|
599 |
];
|
|
|
600 |
}
|
|
|
601 |
|
|
|
602 |
return new JsonModel($data);
|
|
|
603 |
|
|
|
604 |
} else {
|
|
|
605 |
$messages = [];
|
|
|
606 |
$form_messages = (array) $form->getMessages();
|
|
|
607 |
foreach($form_messages as $fieldname => $field_messages)
|
|
|
608 |
{
|
|
|
609 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
610 |
}
|
|
|
611 |
|
|
|
612 |
return new JsonModel([
|
|
|
613 |
'success' => false,
|
|
|
614 |
'data' => $messages
|
|
|
615 |
]);
|
|
|
616 |
}
|
|
|
617 |
} else if ($request->isGet()) {
|
|
|
618 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
619 |
|
|
|
620 |
$data = [
|
|
|
621 |
'success' => true,
|
|
|
622 |
'data' => $hydrator->extract($user)
|
|
|
623 |
];
|
|
|
624 |
|
|
|
625 |
return new JsonModel($data);
|
|
|
626 |
} else {
|
|
|
627 |
$data = [
|
|
|
628 |
'success' => false,
|
|
|
629 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
630 |
];
|
|
|
631 |
|
|
|
632 |
return new JsonModel($data);
|
|
|
633 |
}
|
|
|
634 |
|
|
|
635 |
return new JsonModel($data);
|
|
|
636 |
}
|
|
|
637 |
|
|
|
638 |
public function deleteAction()
|
|
|
639 |
{
|
|
|
640 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
641 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
642 |
|
|
|
643 |
$request = $this->getRequest();
|
|
|
644 |
$id = $this->params()->fromRoute('id');
|
|
|
645 |
|
|
|
646 |
if(!$id) {
|
|
|
647 |
$data = [
|
|
|
648 |
'success' => false,
|
|
|
649 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
650 |
];
|
|
|
651 |
|
|
|
652 |
return new JsonModel($data);
|
|
|
653 |
}
|
|
|
654 |
|
|
|
655 |
|
|
|
656 |
$userMapper = UserMapper::getInstance($this->adapter);
|
|
|
657 |
$user = $userMapper->fetchOne($id);
|
|
|
658 |
if(!$user) {
|
|
|
659 |
$data = [
|
|
|
660 |
'success' => false,
|
|
|
661 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
662 |
];
|
|
|
663 |
|
|
|
664 |
return new JsonModel($data);
|
|
|
665 |
}
|
|
|
666 |
|
|
|
667 |
if($request->isPost()) {
|
|
|
668 |
$result = $userMapper->delete($user);
|
|
|
669 |
if($result) {
|
|
|
670 |
$this->logger->info('Se borro el usuario ' . $user->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
|
|
671 |
|
|
|
672 |
$data = [
|
|
|
673 |
'success' => true,
|
|
|
674 |
'data' => 'LABEL_RECORD_DELETED'
|
|
|
675 |
];
|
|
|
676 |
} else {
|
|
|
677 |
|
|
|
678 |
$data = [
|
|
|
679 |
'success' => false,
|
|
|
680 |
'data' => $userMapper->getError()
|
|
|
681 |
];
|
|
|
682 |
|
|
|
683 |
return new JsonModel($data);
|
|
|
684 |
}
|
|
|
685 |
|
|
|
686 |
} else {
|
|
|
687 |
$data = [
|
|
|
688 |
'success' => false,
|
|
|
689 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
690 |
];
|
|
|
691 |
|
|
|
692 |
return new JsonModel($data);
|
|
|
693 |
}
|
|
|
694 |
|
|
|
695 |
return new JsonModel($data);
|
|
|
696 |
}*/
|
|
|
697 |
|
|
|
698 |
public function unblockAction()
|
|
|
699 |
{
|
|
|
700 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
701 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
702 |
$request = $this->getRequest();
|
|
|
703 |
|
|
|
704 |
|
|
|
705 |
if($request->isPost()) {
|
|
|
706 |
|
|
|
707 |
$uuid = $this->params()->fromRoute('id');
|
|
|
708 |
if(!$uuid) {
|
|
|
709 |
return new JsonModel([
|
|
|
710 |
'success' => false,
|
|
|
711 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
712 |
]);
|
|
|
713 |
}
|
|
|
714 |
|
|
|
715 |
$userMapper = UserMapper::getInstance($this->adapter);
|
|
|
716 |
$user = $userMapper->fetchOneByUuid($uuid);
|
|
|
717 |
|
|
|
718 |
if(!$user) {
|
|
|
719 |
return new JsonModel([
|
|
|
720 |
'success' => false,
|
|
|
721 |
'data' => 'ERROR_USER_NOT_FOUND'
|
|
|
722 |
]);
|
|
|
723 |
}
|
|
|
724 |
|
|
|
725 |
if($user->blocked == User::BLOCKED_NO) {
|
|
|
726 |
return new JsonModel([
|
|
|
727 |
'success' => false,
|
|
|
728 |
'data' => 'ERROR_USER_IS_NOT_BLOCKED'
|
|
|
729 |
]);
|
|
|
730 |
}
|
|
|
731 |
|
|
|
732 |
|
|
|
733 |
|
|
|
734 |
$result = $userMapper->unblock($user);
|
|
|
735 |
if($result) {
|
|
|
736 |
$this->logger->info('El usuario : ' . $user->email . ' ha sido desbloqueado ', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
|
|
737 |
|
|
|
738 |
return new JsonModel([
|
|
|
739 |
'success' => true,
|
|
|
740 |
'data' => 'LABEL_USER_HAS_BEEN_UNBLOCKED',
|
|
|
741 |
]);
|
|
|
742 |
} else {
|
|
|
743 |
|
|
|
744 |
return new JsonModel([
|
|
|
745 |
'success' => false,
|
|
|
746 |
'data' => $userMapper->getError()
|
|
|
747 |
]);
|
|
|
748 |
}
|
|
|
749 |
|
|
|
750 |
|
|
|
751 |
}
|
|
|
752 |
|
|
|
753 |
|
|
|
754 |
|
|
|
755 |
return new JsonModel([
|
|
|
756 |
'success' => false,
|
|
|
757 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
758 |
]);
|
|
|
759 |
}
|
|
|
760 |
|
129 |
efrain |
761 |
public function emailVerifyAction()
|
|
|
762 |
{
|
|
|
763 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
764 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
765 |
$request = $this->getRequest();
|
|
|
766 |
|
|
|
767 |
|
|
|
768 |
if($request->isPost()) {
|
|
|
769 |
|
|
|
770 |
$uuid = $this->params()->fromRoute('id');
|
|
|
771 |
if(!$uuid) {
|
|
|
772 |
return new JsonModel([
|
|
|
773 |
'success' => false,
|
|
|
774 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
775 |
]);
|
|
|
776 |
}
|
|
|
777 |
|
|
|
778 |
$userMapper = UserMapper::getInstance($this->adapter);
|
|
|
779 |
$user = $userMapper->fetchOneByUuid($uuid);
|
|
|
780 |
|
|
|
781 |
if(!$user) {
|
|
|
782 |
return new JsonModel([
|
|
|
783 |
'success' => false,
|
|
|
784 |
'data' => 'ERROR_USER_NOT_FOUND'
|
|
|
785 |
]);
|
|
|
786 |
}
|
|
|
787 |
|
|
|
788 |
if($user->blocked == User::BLOCKED_NO) {
|
|
|
789 |
return new JsonModel([
|
|
|
790 |
'success' => false,
|
|
|
791 |
'data' => 'ERROR_USER_IS_NOT_PENDING_FOR_EMAIL_VERIFY'
|
|
|
792 |
]);
|
|
|
793 |
}
|
|
|
794 |
|
|
|
795 |
|
|
|
796 |
|
|
|
797 |
$result = $userMapper->emailVerifyAndActive($user);
|
|
|
798 |
if($result) {
|
|
|
799 |
$this->logger->info('El usuario : ' . $user->email . ' ha sido desbloqueado ', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
|
|
800 |
|
|
|
801 |
return new JsonModel([
|
|
|
802 |
'success' => true,
|
|
|
803 |
'data' => 'LABEL_USER_HAS_BEEN_UNBLOCKED',
|
|
|
804 |
]);
|
|
|
805 |
} else {
|
|
|
806 |
|
|
|
807 |
return new JsonModel([
|
|
|
808 |
'success' => false,
|
|
|
809 |
'data' => $userMapper->getError()
|
|
|
810 |
]);
|
|
|
811 |
}
|
|
|
812 |
|
|
|
813 |
|
|
|
814 |
}
|
|
|
815 |
|
|
|
816 |
|
|
|
817 |
|
|
|
818 |
return new JsonModel([
|
|
|
819 |
'success' => false,
|
|
|
820 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
821 |
]);
|
|
|
822 |
}
|
|
|
823 |
|
1 |
www |
824 |
public function changePasswordAction()
|
|
|
825 |
{
|
|
|
826 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
827 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
828 |
|
|
|
829 |
$request = $this->getRequest();
|
|
|
830 |
|
|
|
831 |
if($request->isGet()) {
|
|
|
832 |
$uuid = $this->params()->fromRoute('id');
|
|
|
833 |
if(!$uuid) {
|
|
|
834 |
return new JsonModel([
|
|
|
835 |
'success' => false,
|
|
|
836 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
837 |
]);
|
|
|
838 |
}
|
|
|
839 |
|
|
|
840 |
$userMapper = UserMapper::getInstance($this->adapter);
|
|
|
841 |
$user = $userMapper->fetchOneByUuid($uuid);
|
|
|
842 |
|
|
|
843 |
|
|
|
844 |
|
|
|
845 |
if($user) {
|
|
|
846 |
return new JsonModel([
|
|
|
847 |
'success' => true,
|
|
|
848 |
'data' => [
|
|
|
849 |
'first_name' => $user->first_name,
|
|
|
850 |
'last_name' => $user->last_name,
|
|
|
851 |
'email' => $user->email,
|
|
|
852 |
]
|
|
|
853 |
]);
|
|
|
854 |
} else {
|
|
|
855 |
return new JsonModel([
|
|
|
856 |
'success' => false,
|
|
|
857 |
'data' => 'ERROR_USER_NOT_FOUND'
|
|
|
858 |
]);
|
|
|
859 |
}
|
|
|
860 |
|
|
|
861 |
}
|
|
|
862 |
|
|
|
863 |
if($request->isPost()) {
|
|
|
864 |
|
|
|
865 |
$uuid = $this->params()->fromRoute('id');
|
|
|
866 |
if(!$uuid) {
|
|
|
867 |
return new JsonModel([
|
|
|
868 |
'success' => false,
|
|
|
869 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
870 |
]);
|
|
|
871 |
}
|
|
|
872 |
|
|
|
873 |
$userMapper = UserMapper::getInstance($this->adapter);
|
|
|
874 |
$user = $userMapper->fetchOneByUuid($uuid);
|
|
|
875 |
|
|
|
876 |
if(!$user) {
|
|
|
877 |
return new JsonModel([
|
|
|
878 |
'success' => false,
|
|
|
879 |
'data' => 'ERROR_USER_NOT_FOUND'
|
|
|
880 |
]);
|
|
|
881 |
}
|
|
|
882 |
|
|
|
883 |
|
|
|
884 |
$dataPost = $request->getPost()->toArray();
|
|
|
885 |
$form = new ChangePasswordForm();
|
|
|
886 |
$form->setData($dataPost);
|
|
|
887 |
|
|
|
888 |
if($form->isValid()) {
|
|
|
889 |
|
|
|
890 |
|
|
|
891 |
|
|
|
892 |
$data = (array) $form->getData();
|
|
|
893 |
$password = $data['password'];
|
|
|
894 |
|
|
|
895 |
|
|
|
896 |
|
|
|
897 |
$userPasswordMapper = UserPasswordMapper::getInstance($this->adapter);
|
|
|
898 |
$userPasswords = $userPasswordMapper->fetchAllByUserId($user->id);
|
|
|
899 |
|
|
|
900 |
$oldPassword = false;
|
|
|
901 |
foreach($userPasswords as $userPassword)
|
|
|
902 |
{
|
|
|
903 |
if(password_verify($password, $userPassword->password) || (md5($password) == $userPassword->password))
|
|
|
904 |
{
|
|
|
905 |
$oldPassword = true;
|
|
|
906 |
break;
|
|
|
907 |
}
|
|
|
908 |
}
|
|
|
909 |
|
|
|
910 |
if($oldPassword) {
|
|
|
911 |
$this->logger->err('Cambio de contraseña del usuario - error contraseña ya utilizada anteriormente', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
|
|
912 |
|
|
|
913 |
return new JsonModel([
|
|
|
914 |
'success' => false,
|
|
|
915 |
'data' => 'ERROR_PASSWORD_HAS_ALREADY_BEEN_USED'
|
|
|
916 |
|
|
|
917 |
]);
|
|
|
918 |
} else {
|
|
|
919 |
$password_hash = password_hash($password, PASSWORD_DEFAULT);
|
|
|
920 |
|
|
|
921 |
|
|
|
922 |
$result = $userMapper->updatePassword($user, $password_hash);
|
|
|
923 |
if($result) {
|
|
|
924 |
$this->logger->info('Cambio de contraseña del usuario realizado', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
|
|
925 |
|
|
|
926 |
|
|
|
927 |
return new JsonModel([
|
|
|
928 |
'success' => true,
|
|
|
929 |
'data' => 'LABEL_YOUR_PASSWORD_HAS_BEEN_UPDATED'
|
|
|
930 |
|
|
|
931 |
]);
|
|
|
932 |
} else {
|
|
|
933 |
$this->logger->err('Cambio de contraseña del usuario - error desconocido', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
|
|
934 |
|
|
|
935 |
return new JsonModel([
|
|
|
936 |
'success' => true,
|
|
|
937 |
'data' => 'ERROR_THERE_WAS_AN_ERROR'
|
|
|
938 |
|
|
|
939 |
]);
|
|
|
940 |
}
|
|
|
941 |
}
|
|
|
942 |
|
|
|
943 |
} else {
|
|
|
944 |
$messages = [];
|
|
|
945 |
|
|
|
946 |
$form_messages = (array) $form->getMessages();
|
|
|
947 |
foreach($form_messages as $fieldname => $field_messages)
|
|
|
948 |
{
|
|
|
949 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
950 |
}
|
|
|
951 |
|
|
|
952 |
return new JsonModel([
|
|
|
953 |
'success' => false,
|
|
|
954 |
'data' => $messages
|
|
|
955 |
]);
|
|
|
956 |
}
|
|
|
957 |
|
|
|
958 |
}
|
|
|
959 |
|
|
|
960 |
|
|
|
961 |
|
|
|
962 |
return new JsonModel([
|
|
|
963 |
'success' => false,
|
|
|
964 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
965 |
]);
|
|
|
966 |
}
|
|
|
967 |
|
|
|
968 |
public function cancelAction()
|
|
|
969 |
{
|
|
|
970 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
971 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
972 |
|
|
|
973 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
974 |
|
|
|
975 |
$request = $this->getRequest();
|
|
|
976 |
|
|
|
977 |
|
|
|
978 |
if($request->isPost()) {
|
|
|
979 |
|
|
|
980 |
$uuid = $this->params()->fromRoute('id');
|
|
|
981 |
if(!$uuid) {
|
|
|
982 |
return new JsonModel([
|
|
|
983 |
'success' => false,
|
|
|
984 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
985 |
]);
|
|
|
986 |
}
|
|
|
987 |
|
|
|
988 |
$userMapper = UserMapper::getInstance($this->adapter);
|
|
|
989 |
$user = $userMapper->fetchOneByUuid($uuid);
|
|
|
990 |
|
|
|
991 |
if(!$user) {
|
|
|
992 |
return new JsonModel([
|
|
|
993 |
'success' => false,
|
|
|
994 |
'data' => 'ERROR_USER_COMPANY_NOT_FOUND'
|
|
|
995 |
]);
|
|
|
996 |
}
|
|
|
997 |
|
|
|
998 |
$companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
|
|
|
999 |
$companyUser = $companyUserMapper->fetchOneByCompanyIdAndUserId($currentCompany->id, $user->id);
|
|
|
1000 |
|
|
|
1001 |
if(!$companyUser) {
|
|
|
1002 |
return new JsonModel([
|
|
|
1003 |
'success' => false,
|
|
|
1004 |
'data' => 'ERROR_USER_NOT_FOUND'
|
|
|
1005 |
]);
|
|
|
1006 |
}
|
|
|
1007 |
|
|
|
1008 |
|
|
|
1009 |
if(!in_array($companyUser->status, [ CompanyUser::STATUS_ADMIN_WILL_ADD, CompanyUser::STATUS_ACCEPTED])) {
|
|
|
1010 |
return new JsonModel([
|
|
|
1011 |
'success' => false,
|
|
|
1012 |
'data' => 'ERROR_USER_COMPANY_WRONG_STATUS'
|
|
|
1013 |
]);
|
|
|
1014 |
}
|
|
|
1015 |
|
|
|
1016 |
$companyUser->status = CompanyUser::STATUS_CANCELLED;
|
|
|
1017 |
$result = $companyUserMapper->update($companyUser);
|
|
|
1018 |
if($result) {
|
|
|
1019 |
$this->logger->info('La relación del usuario : ' . $user->email . ' con la empresa : ' . $currentCompany->name . ' ha sido cancelada ', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
|
|
1020 |
|
|
|
1021 |
return new JsonModel([
|
|
|
1022 |
'success' => true,
|
|
|
1023 |
'data' => 'LABEL_USER_COMPANY_HAS_BEEN_CANCELLED',
|
|
|
1024 |
]);
|
|
|
1025 |
} else {
|
|
|
1026 |
|
|
|
1027 |
return new JsonModel([
|
|
|
1028 |
'success' => false,
|
|
|
1029 |
'data' => $userMapper->getError()
|
|
|
1030 |
]);
|
|
|
1031 |
}
|
|
|
1032 |
|
|
|
1033 |
|
|
|
1034 |
}
|
|
|
1035 |
|
|
|
1036 |
|
|
|
1037 |
|
|
|
1038 |
return new JsonModel([
|
|
|
1039 |
'success' => false,
|
|
|
1040 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
1041 |
]);
|
|
|
1042 |
}
|
|
|
1043 |
|
|
|
1044 |
public function acceptAction()
|
|
|
1045 |
{
|
|
|
1046 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
1047 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
1048 |
|
|
|
1049 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
1050 |
|
|
|
1051 |
$request = $this->getRequest();
|
|
|
1052 |
|
|
|
1053 |
|
|
|
1054 |
if($request->isPost()) {
|
|
|
1055 |
|
|
|
1056 |
$uuid = $this->params()->fromRoute('id');
|
|
|
1057 |
if(!$uuid) {
|
|
|
1058 |
return new JsonModel([
|
|
|
1059 |
'success' => false,
|
|
|
1060 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
1061 |
]);
|
|
|
1062 |
}
|
|
|
1063 |
|
|
|
1064 |
$userMapper = UserMapper::getInstance($this->adapter);
|
|
|
1065 |
$user = $userMapper->fetchOneByUuid($uuid);
|
|
|
1066 |
|
|
|
1067 |
if(!$user) {
|
|
|
1068 |
return new JsonModel([
|
|
|
1069 |
'success' => false,
|
|
|
1070 |
'data' => 'ERROR_USER_NOT_FOUND'
|
|
|
1071 |
]);
|
|
|
1072 |
}
|
|
|
1073 |
|
|
|
1074 |
$companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
|
|
|
1075 |
$companyUser = $companyUserMapper->fetchOneByCompanyIdAndUserId($currentCompany->id, $user->id);
|
|
|
1076 |
|
|
|
1077 |
if(!$companyUser) {
|
|
|
1078 |
return new JsonModel([
|
|
|
1079 |
'success' => false,
|
|
|
1080 |
'data' => 'ERROR_USER_NOT_FOUND'
|
|
|
1081 |
]);
|
|
|
1082 |
}
|
|
|
1083 |
|
|
|
1084 |
if($companyUser->status != CompanyUser::STATUS_PENDING
|
|
|
1085 |
&& $companyUser->status != CompanyUser::STATUS_SENT
|
|
|
1086 |
&& $companyUser->status != CompanyUser::STATUS_CANCELLED
|
|
|
1087 |
&& $companyUser->status != CompanyUser::STATUS_REJECTED) {
|
|
|
1088 |
return new JsonModel([
|
|
|
1089 |
'success' => false,
|
|
|
1090 |
'data' => 'ERROR_USER_COMPANY_WRONG_STATUS'
|
|
|
1091 |
]);
|
|
|
1092 |
}
|
|
|
1093 |
|
|
|
1094 |
$companyUser->status = CompanyUser::STATUS_ACCEPTED;
|
|
|
1095 |
$result = $companyUserMapper->update($companyUser);
|
|
|
1096 |
if($result) {
|
|
|
1097 |
$this->logger->info('La relación del usuario : ' . $user->email . ' con la empresa : ' . $currentCompany->name . ' ha sido aceptada ', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
|
|
1098 |
|
|
|
1099 |
return new JsonModel([
|
|
|
1100 |
'success' => true,
|
|
|
1101 |
'data' => 'LABEL_USER_COMPANY_HAS_BEEN_ACCEPTED'
|
|
|
1102 |
]);
|
|
|
1103 |
} else {
|
|
|
1104 |
|
|
|
1105 |
return new JsonModel([
|
|
|
1106 |
'success' => false,
|
|
|
1107 |
'data' => $userMapper->getError()
|
|
|
1108 |
]);
|
|
|
1109 |
}
|
|
|
1110 |
|
|
|
1111 |
|
|
|
1112 |
}
|
|
|
1113 |
|
|
|
1114 |
|
|
|
1115 |
|
|
|
1116 |
return new JsonModel([
|
|
|
1117 |
'success' => false,
|
|
|
1118 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
1119 |
]);
|
|
|
1120 |
}
|
|
|
1121 |
|
|
|
1122 |
public function rejectAction()
|
|
|
1123 |
{
|
|
|
1124 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
1125 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
1126 |
|
|
|
1127 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
1128 |
|
|
|
1129 |
$request = $this->getRequest();
|
|
|
1130 |
|
|
|
1131 |
|
|
|
1132 |
if($request->isPost()) {
|
|
|
1133 |
|
|
|
1134 |
$uuid = $this->params()->fromRoute('id');
|
|
|
1135 |
if(!$uuid) {
|
|
|
1136 |
return new JsonModel([
|
|
|
1137 |
'success' => false,
|
|
|
1138 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
1139 |
]);
|
|
|
1140 |
}
|
|
|
1141 |
|
|
|
1142 |
$userMapper = UserMapper::getInstance($this->adapter);
|
|
|
1143 |
$user = $userMapper->fetchOneByUuid($uuid);
|
|
|
1144 |
|
|
|
1145 |
if(!$user) {
|
|
|
1146 |
return new JsonModel([
|
|
|
1147 |
'success' => false,
|
|
|
1148 |
'data' => 'ERROR_USER_NOT_FOUND'
|
|
|
1149 |
]);
|
|
|
1150 |
}
|
|
|
1151 |
|
|
|
1152 |
$companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
|
|
|
1153 |
$companyUser = $companyUserMapper->fetchOneByCompanyIdAndUserId($currentCompany->id, $user->id);
|
|
|
1154 |
|
|
|
1155 |
if(!$companyUser) {
|
|
|
1156 |
return new JsonModel([
|
|
|
1157 |
'success' => false,
|
|
|
1158 |
'data' => 'ERROR_USER_COMPANY_NOT_FOUND'
|
|
|
1159 |
]);
|
|
|
1160 |
}
|
|
|
1161 |
|
|
|
1162 |
if($companyUser->status != CompanyUser::STATUS_PENDING
|
|
|
1163 |
&& $companyUser->status != CompanyUser::STATUS_SENT) {
|
|
|
1164 |
return new JsonModel([
|
|
|
1165 |
'success' => false,
|
|
|
1166 |
'data' => 'ERROR_USER_COMPANY_WRONG_STATUS'
|
|
|
1167 |
]);
|
|
|
1168 |
}
|
|
|
1169 |
|
|
|
1170 |
$companyUser->status = CompanyUser::STATUS_REJECTED;
|
|
|
1171 |
$result = $companyUserMapper->update($companyUser);
|
|
|
1172 |
if($result) {
|
|
|
1173 |
$this->logger->info('La relación del usuario : ' . $user->email . ' con la empresa : ' . $currentCompany->name . ' ha sido rechazada ', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
|
|
1174 |
|
|
|
1175 |
return new JsonModel([
|
|
|
1176 |
'success' => true,
|
|
|
1177 |
'data' => 'LABEL_USER_COMPANY_HAS_BEEN_REJECTED',
|
|
|
1178 |
]);
|
|
|
1179 |
} else {
|
|
|
1180 |
|
|
|
1181 |
return new JsonModel([
|
|
|
1182 |
'success' => false,
|
|
|
1183 |
'data' => $userMapper->getError()
|
|
|
1184 |
]);
|
|
|
1185 |
}
|
|
|
1186 |
|
|
|
1187 |
|
|
|
1188 |
}
|
|
|
1189 |
|
|
|
1190 |
|
|
|
1191 |
|
|
|
1192 |
return new JsonModel([
|
|
|
1193 |
'success' => false,
|
|
|
1194 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
1195 |
]);
|
|
|
1196 |
}
|
|
|
1197 |
|
|
|
1198 |
public function inviteAction()
|
|
|
1199 |
{
|
|
|
1200 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
1201 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
1202 |
|
15351 |
efrain |
1203 |
|
|
|
1204 |
|
1 |
www |
1205 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
1206 |
|
|
|
1207 |
$request = $this->getRequest();
|
|
|
1208 |
|
|
|
1209 |
if($request->isGet()) {
|
|
|
1210 |
|
16766 |
efrain |
1211 |
$search = Functions::sanitizeFilterString($this->params()->fromQuery('search')) ;
|
1 |
www |
1212 |
if(strlen($search) >= 3) {
|
|
|
1213 |
|
|
|
1214 |
$userMapper = UserMapper::getInstance($this->adapter);
|
|
|
1215 |
$records = $userMapper->fetchAllSuggestForInvitationByCompanyId($currentCompany->id, $search);
|
|
|
1216 |
|
|
|
1217 |
$users = [];
|
|
|
1218 |
foreach($records as $record)
|
|
|
1219 |
{
|
|
|
1220 |
array_push($users, [
|
|
|
1221 |
'value' => $record->uuid,
|
|
|
1222 |
'text' => trim($record->first_name . ' ' . $record->last_name) . ' (' . $record->email . ')'
|
|
|
1223 |
|
|
|
1224 |
]);
|
|
|
1225 |
}
|
|
|
1226 |
|
|
|
1227 |
return new JsonModel([
|
|
|
1228 |
'success' => true,
|
|
|
1229 |
'data' => $users
|
|
|
1230 |
]);
|
|
|
1231 |
|
|
|
1232 |
|
|
|
1233 |
|
|
|
1234 |
|
|
|
1235 |
} else {
|
|
|
1236 |
return new JsonModel([
|
|
|
1237 |
'success' => true,
|
|
|
1238 |
'data' => [
|
|
|
1239 |
|
|
|
1240 |
]
|
|
|
1241 |
]);
|
|
|
1242 |
}
|
|
|
1243 |
|
|
|
1244 |
|
|
|
1245 |
|
|
|
1246 |
|
|
|
1247 |
|
|
|
1248 |
|
|
|
1249 |
} else if($request->isPost()) {
|
|
|
1250 |
|
|
|
1251 |
$uuid = $this->params()->fromPost('id');
|
|
|
1252 |
if(!$uuid) {
|
|
|
1253 |
return new JsonModel([
|
|
|
1254 |
'success' => false,
|
|
|
1255 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
1256 |
]);
|
|
|
1257 |
}
|
|
|
1258 |
|
|
|
1259 |
$userMapper = UserMapper::getInstance($this->adapter);
|
|
|
1260 |
$user = $userMapper->fetchOneByUuid($uuid);
|
|
|
1261 |
|
|
|
1262 |
if(!$user) {
|
|
|
1263 |
return new JsonModel([
|
|
|
1264 |
'success' => false,
|
|
|
1265 |
'data' => 'ERROR_USER_NOT_FOUND'
|
|
|
1266 |
]);
|
|
|
1267 |
}
|
|
|
1268 |
|
|
|
1269 |
if($user->status != User::STATUS_ACTIVE) {
|
|
|
1270 |
return new JsonModel([
|
|
|
1271 |
'success' => false,
|
|
|
1272 |
'data' => 'ERROR_USER_IS_INACTIVE'
|
|
|
1273 |
]);
|
|
|
1274 |
}
|
|
|
1275 |
|
|
|
1276 |
|
|
|
1277 |
|
|
|
1278 |
|
|
|
1279 |
|
|
|
1280 |
$companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
|
|
|
1281 |
$companyUser = $companyUserMapper->fetchOneByCompanyIdAndUserId($currentCompany->id, $user->id);
|
|
|
1282 |
|
|
|
1283 |
if($companyUser && $companyUser->status == CompanyUser::STATUS_ACCEPTED) {
|
|
|
1284 |
return new JsonModel([
|
|
|
1285 |
'success' => false,
|
|
|
1286 |
'data' => 'ERROR_USER_COMPANY_FOUND'
|
|
|
1287 |
]);
|
|
|
1288 |
}
|
15351 |
efrain |
1289 |
$networkMapper = NetworkMapper::getInstance($this->adapter);
|
|
|
1290 |
$network = $networkMapper->fetchOne($currentUser->network_id);
|
1 |
www |
1291 |
|
|
|
1292 |
|
|
|
1293 |
if($companyUser) {
|
|
|
1294 |
|
15351 |
efrain |
1295 |
|
|
|
1296 |
if($network->default == Network::DEFAULT_YES) {
|
|
|
1297 |
$companyUser->status = CompanyUser::STATUS_ADMIN_WILL_ADD;
|
|
|
1298 |
} else {
|
|
|
1299 |
$companyUser->status = CompanyUser::STATUS_ACCEPTED;
|
|
|
1300 |
}
|
1 |
www |
1301 |
$result = $companyUserMapper->update($companyUser);
|
|
|
1302 |
|
|
|
1303 |
} else {
|
15351 |
efrain |
1304 |
|
|
|
1305 |
|
1 |
www |
1306 |
$companyUser = new CompanyUser();
|
|
|
1307 |
$companyUser->company_id = $currentCompany->id;
|
|
|
1308 |
$companyUser->backend = CompanyUser::BACKEND_NO;
|
|
|
1309 |
$companyUser->creator = CompanyUser::CREATOR_NO;
|
|
|
1310 |
$companyUser->owner = CompanyUser::OWNER_NO;
|
15351 |
efrain |
1311 |
|
|
|
1312 |
if($network->default == Network::DEFAULT_YES) {
|
|
|
1313 |
$companyUser->status = CompanyUser::STATUS_ADMIN_WILL_ADD;
|
|
|
1314 |
} else {
|
|
|
1315 |
$companyUser->status = CompanyUser::STATUS_ACCEPTED;
|
|
|
1316 |
}
|
|
|
1317 |
|
|
|
1318 |
|
1 |
www |
1319 |
$companyUser->status = CompanyUser::STATUS_ADMIN_WILL_ADD;
|
|
|
1320 |
$companyUser->user_id = $user->id;
|
|
|
1321 |
|
|
|
1322 |
|
|
|
1323 |
|
|
|
1324 |
$result = $companyUserMapper->insert($companyUser);
|
|
|
1325 |
}
|
|
|
1326 |
|
|
|
1327 |
|
|
|
1328 |
|
|
|
1329 |
if($result) {
|
|
|
1330 |
|
|
|
1331 |
|
|
|
1332 |
$notification = new Notification();
|
|
|
1333 |
$notification->type = Notification::TYPE_RECEIVE_INVITATION_COMPANY;
|
|
|
1334 |
$notification->read = Notification::NO;
|
|
|
1335 |
$notification->user_id = $user->id;
|
|
|
1336 |
$notification->company_id = $currentCompany->id;
|
|
|
1337 |
$notification->message = 'LABEL_NOTIFICATION_RECEIVE_INVITATION_COMPANY';
|
|
|
1338 |
$notification->url = 'company/view/' . $currentCompany->uuid;
|
|
|
1339 |
|
|
|
1340 |
$notificationMapper = NotificationMapper::getInstance($this->adapter);
|
|
|
1341 |
$notificationMapper->insert($notification);
|
|
|
1342 |
|
|
|
1343 |
$userNotificationMapper = UserNotificationSettingMapper::getInstance($this->adapter);
|
|
|
1344 |
$userNotification = $userNotificationMapper->fetchOne($user->id);
|
|
|
1345 |
|
|
|
1346 |
if($userNotification && $userNotification->receive_invitation_company)
|
|
|
1347 |
{
|
|
|
1348 |
$emailTemplateMapper = EmailTemplateMapper::getInstance($this->adapter);
|
15351 |
efrain |
1349 |
$emailTemplate = $emailTemplateMapper->fetchOneByCodeAndNetworkId(EmailTemplate::CODE_RECEIVE_INVITATION_COMPANY, $currentUser->network_id);
|
1 |
www |
1350 |
|
15351 |
efrain |
1351 |
if($emailTemplate)
|
|
|
1352 |
{
|
|
|
1353 |
$company_profile_url = 'https://'. $network->main_hostname . '/company/view/' . $currentCompany->uuid;
|
1 |
www |
1354 |
|
|
|
1355 |
|
|
|
1356 |
$arrayCont = [
|
|
|
1357 |
'firstname' => $currentUser->first_name,
|
|
|
1358 |
'lastname' => $currentUser->last_name,
|
|
|
1359 |
'other_user_firstname' => $user->first_name,
|
|
|
1360 |
'other_user_lastname' => $user->last_name,
|
|
|
1361 |
'company_name' => $currentCompany->name,
|
|
|
1362 |
'group_name' => '',
|
|
|
1363 |
'content' => '',
|
|
|
1364 |
'code' => '',
|
|
|
1365 |
'link' => $company_profile_url,
|
|
|
1366 |
];
|
|
|
1367 |
|
|
|
1368 |
$email = new QueueEmail($this->adapter);
|
|
|
1369 |
$email->processEmailTemplate($emailTemplate, $arrayCont, $user->email, trim($user->first_name . ' ' . $user->last_name));
|
|
|
1370 |
}
|
|
|
1371 |
}
|
|
|
1372 |
|
|
|
1373 |
|
|
|
1374 |
$this->logger->info('La empresa : ' . $currentCompany->name . ' envio al usuario : ' . $user->email . ' una invitación ', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
|
|
1375 |
|
15351 |
efrain |
1376 |
if($network->default == Network::DEFAULT_YES) {
|
|
|
1377 |
return new JsonModel([
|
|
|
1378 |
'success' => true,
|
|
|
1379 |
'data' => 'LABEL_USER_COMPANY_HAS_BEEN_CREATED',
|
|
|
1380 |
]);
|
|
|
1381 |
} else {
|
|
|
1382 |
return new JsonModel([
|
|
|
1383 |
'success' => true,
|
|
|
1384 |
'data' => 'LABEL_USER_COMPANY_HAS_BEEN_INVITED_SENT',
|
|
|
1385 |
]);
|
|
|
1386 |
}
|
|
|
1387 |
|
|
|
1388 |
|
1 |
www |
1389 |
} else {
|
|
|
1390 |
|
|
|
1391 |
return new JsonModel([
|
|
|
1392 |
'success' => false,
|
|
|
1393 |
'data' => $userMapper->getError()
|
|
|
1394 |
]);
|
|
|
1395 |
}
|
|
|
1396 |
|
|
|
1397 |
|
|
|
1398 |
}
|
|
|
1399 |
|
|
|
1400 |
|
|
|
1401 |
|
|
|
1402 |
return new JsonModel([
|
|
|
1403 |
'success' => false,
|
|
|
1404 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
1405 |
]);
|
|
|
1406 |
}
|
|
|
1407 |
|
|
|
1408 |
|
|
|
1409 |
public function deleteAction()
|
|
|
1410 |
{
|
|
|
1411 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
1412 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
1413 |
|
|
|
1414 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
1415 |
|
|
|
1416 |
$request = $this->getRequest();
|
|
|
1417 |
|
|
|
1418 |
|
|
|
1419 |
if($request->isPost()) {
|
|
|
1420 |
|
|
|
1421 |
$uuid = $this->params()->fromRoute('id');
|
|
|
1422 |
if(!$uuid) {
|
|
|
1423 |
return new JsonModel([
|
|
|
1424 |
'success' => false,
|
|
|
1425 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
1426 |
]);
|
|
|
1427 |
}
|
|
|
1428 |
|
|
|
1429 |
$userMapper = UserMapper::getInstance($this->adapter);
|
|
|
1430 |
$user = $userMapper->fetchOneByUuid($uuid);
|
|
|
1431 |
|
|
|
1432 |
if(!$user) {
|
|
|
1433 |
return new JsonModel([
|
|
|
1434 |
'success' => false,
|
|
|
1435 |
'data' => 'ERROR_USER_NOT_FOUND'
|
|
|
1436 |
|
|
|
1437 |
]);
|
|
|
1438 |
}
|
|
|
1439 |
|
|
|
1440 |
$companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
|
|
|
1441 |
$companyUser = $companyUserMapper->fetchOneByCompanyIdAndUserId($currentCompany->id, $user->id);
|
|
|
1442 |
|
|
|
1443 |
if($companyUser) {
|
|
|
1444 |
return new JsonModel([
|
|
|
1445 |
'success' => false,
|
|
|
1446 |
'data' => 'ERROR_USER_COMPANY_NOT_FOUND'
|
|
|
1447 |
]);
|
|
|
1448 |
}
|
|
|
1449 |
|
|
|
1450 |
|
|
|
1451 |
if(!$currentCompany->internal) {
|
|
|
1452 |
return new JsonModel([
|
|
|
1453 |
'success' => false,
|
|
|
1454 |
'data' => 'ERROR_INTERNAL_COMPANY_ONLY'
|
|
|
1455 |
]);
|
|
|
1456 |
}
|
|
|
1457 |
|
|
|
1458 |
|
|
|
1459 |
|
|
|
1460 |
$result = $companyUserMapper->delete($companyUser->id);
|
|
|
1461 |
if($result) {
|
|
|
1462 |
$this->logger->info('La relación del usuario : ' . $user->email . ' con la empresa : ' . $currentCompany->name . ' ha sido eliminada ', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
|
|
1463 |
|
|
|
1464 |
return new JsonModel([
|
|
|
1465 |
'success' => true,
|
|
|
1466 |
'data' => 'LABEL_USER_COMPANY_HAS_BEEN_DELETED',
|
|
|
1467 |
]);
|
|
|
1468 |
} else {
|
|
|
1469 |
|
|
|
1470 |
return new JsonModel([
|
|
|
1471 |
'success' => false,
|
|
|
1472 |
'data' => $userMapper->getError()
|
|
|
1473 |
]);
|
|
|
1474 |
}
|
|
|
1475 |
|
|
|
1476 |
|
|
|
1477 |
}
|
|
|
1478 |
|
|
|
1479 |
|
|
|
1480 |
|
|
|
1481 |
return new JsonModel([
|
|
|
1482 |
'success' => false,
|
|
|
1483 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
1484 |
]);
|
|
|
1485 |
}
|
|
|
1486 |
|
|
|
1487 |
|
|
|
1488 |
public function uploadAction()
|
|
|
1489 |
{
|
|
|
1490 |
$request = $this->getRequest();
|
|
|
1491 |
|
15459 |
efrain |
1492 |
$currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
|
|
|
1493 |
$currentNetwork = $currentNetworkPlugin->getNetwork();
|
|
|
1494 |
|
1 |
www |
1495 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
1496 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
1497 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
1498 |
|
|
|
1499 |
$request = $this->getRequest();
|
|
|
1500 |
|
|
|
1501 |
if($request->isPost()) {
|
|
|
1502 |
|
16766 |
efrain |
1503 |
$step = Functions::sanitizeFilterString($this->params()->fromPost('step'));
|
1 |
www |
1504 |
if($step == 'validation') {
|
|
|
1505 |
$userMapper = UserMapper::getInstance($this->adapter);
|
|
|
1506 |
$companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
|
|
|
1507 |
|
|
|
1508 |
$form = new UserUploadForm();
|
|
|
1509 |
$dataPost = array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
|
|
|
1510 |
|
|
|
1511 |
$form->setData($dataPost);
|
|
|
1512 |
|
|
|
1513 |
if($form->isValid()) {
|
|
|
1514 |
|
|
|
1515 |
$file = $_FILES['file'];
|
|
|
1516 |
$tmp_filename = $file['tmp_name'];
|
|
|
1517 |
$final_filename = 'data/' . $file['name'];
|
|
|
1518 |
|
|
|
1519 |
if(!move_uploaded_file($tmp_filename, $final_filename)) {
|
|
|
1520 |
return new JsonModel([
|
|
|
1521 |
'success' => false,
|
|
|
1522 |
'data' => 'ERROR_UPLOAD_FILE'
|
|
|
1523 |
]);
|
|
|
1524 |
}
|
|
|
1525 |
|
|
|
1526 |
|
|
|
1527 |
$users = [];
|
|
|
1528 |
|
|
|
1529 |
|
|
|
1530 |
$spreadsheet = IOFactory::load($final_filename);
|
|
|
1531 |
$records = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
|
|
|
1532 |
|
|
|
1533 |
$emails = [];
|
|
|
1534 |
|
|
|
1535 |
foreach($records as $record)
|
|
|
1536 |
{
|
|
|
1537 |
//A = Nombre B = Apellidos C = Email D = contraseña
|
|
|
1538 |
|
15460 |
efrain |
1539 |
|
16766 |
efrain |
1540 |
$first_name = Functions::sanitizeFilterString($record['A']);
|
|
|
1541 |
$last_name = Functions::sanitizeFilterString($record['B']);
|
15460 |
efrain |
1542 |
$email = trim(filter_var($record['C'], FILTER_SANITIZE_EMAIL));
|
|
|
1543 |
|
16766 |
efrain |
1544 |
$password = Functions::sanitizeFilterString($record['D']);
|
|
|
1545 |
$isAdult = strtolower(Functions::sanitizeFilterString($record['E']));
|
|
|
1546 |
$country = strtolower(Functions::sanitizeFilterString($record['F']));
|
15460 |
efrain |
1547 |
|
1 |
www |
1548 |
|
|
|
1549 |
if(empty($first_name) || empty($last_name) || !filter_var($email, FILTER_VALIDATE_EMAIL) || empty($password)) {
|
|
|
1550 |
continue;
|
|
|
1551 |
}
|
|
|
1552 |
|
|
|
1553 |
if(!in_array($email, $emails)) {
|
|
|
1554 |
|
|
|
1555 |
$user = $userMapper->fetchOneByEmail($email);
|
|
|
1556 |
|
|
|
1557 |
array_push($emails, $email);
|
|
|
1558 |
array_push($users, [
|
|
|
1559 |
'first_name' => $first_name,
|
|
|
1560 |
'last_name' => $last_name,
|
|
|
1561 |
'password' => $password,
|
|
|
1562 |
'email' => $email,
|
15460 |
efrain |
1563 |
'is_adult' => $isAdult,
|
|
|
1564 |
'country' => $country,
|
|
|
1565 |
|
1 |
www |
1566 |
]);
|
|
|
1567 |
}
|
|
|
1568 |
|
|
|
1569 |
|
|
|
1570 |
|
|
|
1571 |
|
|
|
1572 |
|
|
|
1573 |
}
|
|
|
1574 |
|
|
|
1575 |
$key = md5($currentUser->id . '-' . microtime(true));
|
|
|
1576 |
$this->cache->setItem($key, serialize($users));
|
|
|
1577 |
|
|
|
1578 |
return new JsonModel([
|
|
|
1579 |
'success' => true,
|
|
|
1580 |
'data' => [
|
|
|
1581 |
'key' => $key,
|
|
|
1582 |
'items' => $users,
|
|
|
1583 |
]
|
|
|
1584 |
]);
|
|
|
1585 |
|
16954 |
efrain |
1586 |
@unlink($final_filename);
|
1 |
www |
1587 |
|
|
|
1588 |
|
|
|
1589 |
} else {
|
|
|
1590 |
$messages = [];
|
|
|
1591 |
$form_messages = (array) $form->getMessages();
|
|
|
1592 |
foreach($form_messages as $fieldname => $field_messages)
|
|
|
1593 |
{
|
|
|
1594 |
|
|
|
1595 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
1596 |
}
|
|
|
1597 |
|
|
|
1598 |
return new JsonModel([
|
|
|
1599 |
'success' => false,
|
|
|
1600 |
'data' => $messages
|
|
|
1601 |
]);
|
|
|
1602 |
}
|
|
|
1603 |
} else if($step == 'process') {
|
|
|
1604 |
|
16766 |
efrain |
1605 |
$key = Functions::sanitizeFilterString($this->params()->fromPost('key'));
|
1 |
www |
1606 |
if(!$key) {
|
|
|
1607 |
return new JsonModel([
|
|
|
1608 |
'success' => false,
|
|
|
1609 |
'data' => 'ERROR_CACHE_KEY_EMPTY'
|
|
|
1610 |
]);
|
|
|
1611 |
}
|
|
|
1612 |
|
|
|
1613 |
$value = $this->cache->getItem($key);
|
|
|
1614 |
if(!$value) {
|
|
|
1615 |
|
|
|
1616 |
return new JsonModel([
|
|
|
1617 |
'success' => false,
|
|
|
1618 |
'data' => 'ERROR_CACHE_NOT_FOUND'
|
|
|
1619 |
]);
|
|
|
1620 |
}
|
|
|
1621 |
|
|
|
1622 |
$records = unserialize($value);
|
|
|
1623 |
if(!$records) {
|
|
|
1624 |
return new JsonModel([
|
|
|
1625 |
'success' => false,
|
|
|
1626 |
'data' => 'ERROR_CACHE_INVALID'
|
|
|
1627 |
]);
|
|
|
1628 |
}
|
|
|
1629 |
|
15460 |
efrain |
1630 |
$locationMapper = LocationMapper::getInstance($this->adapter);
|
|
|
1631 |
$countryMapper = CountryMapper::getInstance($this->adapter);
|
|
|
1632 |
|
|
|
1633 |
|
|
|
1634 |
$networkMapper = NetworkMapper::getInstance($this->adapter);
|
|
|
1635 |
$networkDefault = $networkMapper->fetchOneByDefault();
|
|
|
1636 |
|
1 |
www |
1637 |
$userMapper = UserMapper::getInstance($this->adapter);
|
|
|
1638 |
$userPasswordMapper = UserPasswordMapper::getInstance($this->adapter);
|
15460 |
efrain |
1639 |
|
1 |
www |
1640 |
|
15460 |
efrain |
1641 |
$user_ids_in_default_network = [];
|
|
|
1642 |
|
|
|
1643 |
|
1 |
www |
1644 |
$users_created = 0;
|
|
|
1645 |
$user_ids = [];
|
|
|
1646 |
foreach($records as $record)
|
|
|
1647 |
{
|
|
|
1648 |
$first_name = $record['first_name'];
|
|
|
1649 |
$last_name = $record['last_name'];
|
|
|
1650 |
$password = $record['password'];
|
|
|
1651 |
$email = $record['email'];
|
|
|
1652 |
|
|
|
1653 |
|
16286 |
efrain |
1654 |
$user = $userMapper->fetchOneByEmailAndNetworkId($email, $currentNetwork->id);
|
1 |
www |
1655 |
if(!$user) {
|
|
|
1656 |
$password_hash = password_hash($password, PASSWORD_DEFAULT);
|
|
|
1657 |
|
|
|
1658 |
$user = new User();
|
15459 |
efrain |
1659 |
$user->network_id = $currentNetwork->id;
|
1 |
www |
1660 |
$user->blocked = User::BLOCKED_NO;
|
|
|
1661 |
$user->email_verified = User::EMAIL_VERIFIED_YES;
|
|
|
1662 |
$user->email = $email;
|
|
|
1663 |
$user->first_name = $first_name;
|
|
|
1664 |
$user->last_name = $last_name;
|
|
|
1665 |
$user->password = $password_hash;
|
|
|
1666 |
$user->login_attempt = 0;
|
|
|
1667 |
$user->usertype_id = UserType::USER;
|
|
|
1668 |
$user->status = User::STATUS_ACTIVE;
|
15460 |
efrain |
1669 |
$user->is_adult = $record['is_adult'] == 'y' ? User::IS_ADULT_YES : User::IS_ADULT_NO;
|
1 |
www |
1670 |
|
|
|
1671 |
$result = $userMapper->insert($user);
|
|
|
1672 |
if($result) {
|
15460 |
efrain |
1673 |
$users_created++;
|
|
|
1674 |
|
16286 |
efrain |
1675 |
$country_code = trim($record['country']);
|
15460 |
efrain |
1676 |
|
16286 |
efrain |
1677 |
if($country_code) {
|
|
|
1678 |
$country = $countryMapper->fetchOneByCodeOrCountry($record['country']);
|
|
|
1679 |
if($country) {
|
15460 |
efrain |
1680 |
|
16286 |
efrain |
1681 |
$location = new Location();
|
|
|
1682 |
$location->formatted_address = $country->country;
|
|
|
1683 |
$location->country = $country->country;
|
|
|
1684 |
if($locationMapper->insert($location)) {
|
|
|
1685 |
|
|
|
1686 |
$user->location_id = $location->id;
|
|
|
1687 |
$userMapper->updateLocation($user);
|
|
|
1688 |
}
|
|
|
1689 |
|
15460 |
efrain |
1690 |
}
|
16286 |
efrain |
1691 |
} else {
|
|
|
1692 |
$country_code = '';
|
15460 |
efrain |
1693 |
}
|
|
|
1694 |
|
1 |
www |
1695 |
$userPassword = new UserPassword();
|
|
|
1696 |
$userPassword->user_id = $user->id;
|
|
|
1697 |
$userPassword->password = $password_hash;
|
|
|
1698 |
$userPasswordMapper->insert($userPassword);
|
15460 |
efrain |
1699 |
|
|
|
1700 |
|
|
|
1701 |
if($currentNetwork->default == Network::DEFAULT_YES) {
|
|
|
1702 |
array_push($user_ids_in_default_network, $user->id);
|
|
|
1703 |
} else {
|
|
|
1704 |
|
|
|
1705 |
|
|
|
1706 |
|
|
|
1707 |
if($user->is_adult == User::IS_ADULT_YES) {
|
|
|
1708 |
|
|
|
1709 |
$userInDefaultNetwork = $userMapper->fetchOneByEmailAndNetworkId($user->email, $networkDefault->id);
|
|
|
1710 |
if($userInDefaultNetwork) {
|
|
|
1711 |
|
|
|
1712 |
array_push($user_ids_in_default_network, $userInDefaultNetwork->id);
|
|
|
1713 |
|
|
|
1714 |
if($userInDefaultNetwork->email_verified == User::EMAIL_VERIFIED_NO || $userInDefaultNetwork->status != User::STATUS_ACTIVE) {
|
|
|
1715 |
$userInDefaultNetwork->email_verified = User::EMAIL_VERIFIED_YES;
|
|
|
1716 |
$userInDefaultNetwork->status != User::STATUS_ACTIVE;
|
|
|
1717 |
|
|
|
1718 |
if(!$userMapper->update($userInDefaultNetwork)) {
|
|
|
1719 |
continue;
|
|
|
1720 |
}
|
|
|
1721 |
}
|
|
|
1722 |
|
|
|
1723 |
|
|
|
1724 |
} else {
|
|
|
1725 |
$userInDefaultNetwork = new User();
|
|
|
1726 |
$userInDefaultNetwork->network_id = $networkDefault->id;
|
|
|
1727 |
$userInDefaultNetwork->blocked = User::BLOCKED_NO;
|
|
|
1728 |
$userInDefaultNetwork->email_verified = User::EMAIL_VERIFIED_YES;
|
|
|
1729 |
$userInDefaultNetwork->email = $email;
|
|
|
1730 |
$userInDefaultNetwork->first_name = $first_name;
|
|
|
1731 |
$userInDefaultNetwork->last_name = $last_name;
|
|
|
1732 |
$userInDefaultNetwork->password = $password_hash;
|
|
|
1733 |
$userInDefaultNetwork->login_attempt = 0;
|
|
|
1734 |
$userInDefaultNetwork->usertype_id = UserType::USER;
|
|
|
1735 |
$userInDefaultNetwork->status = User::STATUS_ACTIVE;
|
|
|
1736 |
$userInDefaultNetwork->is_adult = User::IS_ADULT_YES;
|
|
|
1737 |
$result = $userMapper->insert($userInDefaultNetwork);
|
|
|
1738 |
if($result) {
|
|
|
1739 |
array_push($user_ids_in_default_network, $userInDefaultNetwork->id);
|
|
|
1740 |
|
|
|
1741 |
if($country) {
|
|
|
1742 |
|
|
|
1743 |
$location = new Location();
|
|
|
1744 |
$location->formatted_address = $country->country;
|
|
|
1745 |
$location->country = $country->country;
|
|
|
1746 |
if($locationMapper->insert($location)) {
|
|
|
1747 |
|
|
|
1748 |
$userInDefaultNetwork->location_id = $location->id;
|
|
|
1749 |
$userMapper->updateLocation($userInDefaultNetwork);
|
|
|
1750 |
}
|
|
|
1751 |
|
|
|
1752 |
}
|
|
|
1753 |
|
|
|
1754 |
|
|
|
1755 |
$userPassword = new UserPassword();
|
|
|
1756 |
$userPassword->user_id = $userInDefaultNetwork->id;
|
|
|
1757 |
$userPassword->password = $password_hash;
|
|
|
1758 |
$userPasswordMapper->insert($userPassword);
|
|
|
1759 |
}
|
|
|
1760 |
|
|
|
1761 |
}
|
|
|
1762 |
|
|
|
1763 |
|
|
|
1764 |
}
|
|
|
1765 |
|
|
|
1766 |
|
|
|
1767 |
}
|
|
|
1768 |
|
|
|
1769 |
|
|
|
1770 |
|
|
|
1771 |
|
|
|
1772 |
|
|
|
1773 |
|
1 |
www |
1774 |
} else {
|
|
|
1775 |
continue;
|
|
|
1776 |
}
|
129 |
efrain |
1777 |
} else {
|
|
|
1778 |
if($user->email_verified == User::EMAIL_VERIFIED_NO || $user->status != User::STATUS_ACTIVE) {
|
|
|
1779 |
$user->email_verified = User::EMAIL_VERIFIED_YES;
|
|
|
1780 |
$user->status != User::STATUS_ACTIVE;
|
|
|
1781 |
|
|
|
1782 |
if(!$userMapper->update($user)) {
|
|
|
1783 |
continue;
|
|
|
1784 |
}
|
|
|
1785 |
}
|
1 |
www |
1786 |
}
|
|
|
1787 |
|
15460 |
efrain |
1788 |
array_push($user_ids, $user->id);
|
|
|
1789 |
|
|
|
1790 |
}
|
|
|
1791 |
|
|
|
1792 |
if($currentCompany) {
|
|
|
1793 |
|
|
|
1794 |
$companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
|
|
|
1795 |
|
|
|
1796 |
$company_users_created = 0;
|
|
|
1797 |
|
|
|
1798 |
foreach($user_ids as $user_id)
|
|
|
1799 |
{
|
|
|
1800 |
$companyUser = $companyUserMapper->fetchOneByCompanyIdAndUserId($currentCompany->id, $user_id);
|
|
|
1801 |
if(!$companyUser) {
|
|
|
1802 |
|
|
|
1803 |
$companyUser = new CompanyUser();
|
|
|
1804 |
$companyUser->company_id = $currentCompany->id;
|
|
|
1805 |
$companyUser->user_id = $user_id;
|
|
|
1806 |
$companyUser->backend = CompanyUser::BACKEND_NO;
|
|
|
1807 |
$companyUser->creator = CompanyUser::CREATOR_NO;
|
|
|
1808 |
$companyUser->owner = CompanyUser::OWNER_NO;
|
|
|
1809 |
|
|
|
1810 |
if($currentNetwork->default == Network::DEFAULT_YES) {
|
|
|
1811 |
$companyUser->status = CompanyUser::STATUS_ADMIN_WILL_ADD;
|
|
|
1812 |
} else {
|
|
|
1813 |
$companyUser->status = CompanyUser::STATUS_ACCEPTED;
|
|
|
1814 |
}
|
|
|
1815 |
|
|
|
1816 |
if($companyUserMapper->insert($companyUser)) {
|
|
|
1817 |
$company_users_created++;
|
|
|
1818 |
}
|
|
|
1819 |
|
|
|
1820 |
}
|
|
|
1821 |
|
1 |
www |
1822 |
}
|
15460 |
efrain |
1823 |
|
|
|
1824 |
$this->logger->info('Se agregaron ' . $users_created . ' usuarios la empresa ' . $currentCompany->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
|
|
1825 |
|
|
|
1826 |
|
|
|
1827 |
|
|
|
1828 |
} else {
|
|
|
1829 |
|
|
|
1830 |
$this->logger->info('Se agregaron ' . $users_created . ' usuarios a la red', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
|
|
1831 |
|
1 |
www |
1832 |
}
|
|
|
1833 |
|
15460 |
efrain |
1834 |
if($user_ids_in_default_network) {
|
|
|
1835 |
$companyMapper = CompanyMapper::getInstance($this->adapter);
|
|
|
1836 |
$companyToFollower = $companyMapper->fetchOneDefaultForFollowers();
|
|
|
1837 |
|
|
|
1838 |
$companyFollowerMapper = CompanyFollowerMapper::getInstance($this->adapter);
|
|
|
1839 |
|
|
|
1840 |
$userToConnection = $userMapper->fetchOneDefaultForConnection();
|
|
|
1841 |
|
|
|
1842 |
|
|
|
1843 |
$connectionMapper = ConnectionMapper::getInstance($this->adapter);
|
|
|
1844 |
|
|
|
1845 |
foreach($user_ids_in_default_network as $user_id)
|
|
|
1846 |
{
|
|
|
1847 |
if($userToConnection) {
|
|
|
1848 |
$connection = $connectionMapper->fetchOneByUserId1AndUserId2($user_id, $userToConnection->id);
|
|
|
1849 |
if(!$connection) {
|
|
|
1850 |
$connection = new Connection();
|
|
|
1851 |
$connection->request_from = $user_id;
|
|
|
1852 |
$connection->request_to = $userToConnection->id;
|
|
|
1853 |
$connection->status = Connection::STATUS_ACCEPTED;
|
|
|
1854 |
|
|
|
1855 |
$connectionMapper->insert($connection);
|
|
|
1856 |
} else {
|
|
|
1857 |
if($connection->status == Connection::STATUS_SENT) {
|
|
|
1858 |
$connectionMapper->approve($connection);
|
|
|
1859 |
}
|
|
|
1860 |
}
|
|
|
1861 |
}
|
1 |
www |
1862 |
|
15460 |
efrain |
1863 |
if($companyToFollower) {
|
|
|
1864 |
$companyFollower = $companyFollowerMapper->fetchOneByCompanyIdAndUserId($companyToFollower->id, $user_id);
|
|
|
1865 |
if(!$companyFollower) {
|
|
|
1866 |
$companyFollower = new CompanyFollower();
|
|
|
1867 |
$companyFollower->company_id = $companyToFollower->id;
|
|
|
1868 |
$companyFollower->follower_id = $user_id;
|
|
|
1869 |
|
|
|
1870 |
$companyFollowerMapper->insert($companyFollower);
|
|
|
1871 |
|
|
|
1872 |
}
|
1 |
www |
1873 |
}
|
|
|
1874 |
|
|
|
1875 |
}
|
|
|
1876 |
|
15460 |
efrain |
1877 |
|
|
|
1878 |
|
|
|
1879 |
|
1 |
www |
1880 |
}
|
|
|
1881 |
|
|
|
1882 |
|
15460 |
efrain |
1883 |
|
1 |
www |
1884 |
return new JsonModel([
|
|
|
1885 |
'success' => true,
|
|
|
1886 |
'data' => [
|
|
|
1887 |
'users_created' => $users_created
|
|
|
1888 |
]
|
|
|
1889 |
]);
|
|
|
1890 |
|
|
|
1891 |
|
|
|
1892 |
|
|
|
1893 |
|
|
|
1894 |
} else {
|
|
|
1895 |
return new JsonModel([
|
|
|
1896 |
'success' => false,
|
|
|
1897 |
'data' => 'ERROR_PARAMETERS_ARE_INVALID'
|
|
|
1898 |
]);
|
|
|
1899 |
}
|
|
|
1900 |
|
|
|
1901 |
|
|
|
1902 |
|
|
|
1903 |
|
|
|
1904 |
}
|
|
|
1905 |
|
|
|
1906 |
return new JsonModel([
|
|
|
1907 |
'success' => false,
|
|
|
1908 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
1909 |
]);
|
|
|
1910 |
}
|
|
|
1911 |
|
|
|
1912 |
|
|
|
1913 |
public function editAction()
|
|
|
1914 |
{
|
|
|
1915 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
1916 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
1917 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
1918 |
|
|
|
1919 |
$request = $this->getRequest();
|
|
|
1920 |
$uuid = $this->params()->fromRoute('id');
|
|
|
1921 |
|
|
|
1922 |
|
|
|
1923 |
if(!$uuid) {
|
|
|
1924 |
$data = [
|
|
|
1925 |
'success' => false,
|
|
|
1926 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
1927 |
];
|
|
|
1928 |
|
|
|
1929 |
return new JsonModel($data);
|
|
|
1930 |
}
|
|
|
1931 |
|
|
|
1932 |
$userMapper = UserMapper::getInstance($this->adapter);
|
|
|
1933 |
$user = $userMapper->fetchOneByUuid($uuid);
|
|
|
1934 |
if(!$user) {
|
|
|
1935 |
$data = [
|
|
|
1936 |
'success' => false,
|
|
|
1937 |
'data' => 'ERROR_COMPANY_NOT_FOUND'
|
|
|
1938 |
];
|
|
|
1939 |
|
|
|
1940 |
return new JsonModel($data);
|
|
|
1941 |
}
|
|
|
1942 |
|
|
|
1943 |
$companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
|
|
|
1944 |
$companyUser = $companyUserMapper->fetchOneByCompanyIdAndUserId($currentCompany->id, $user->id);
|
|
|
1945 |
if(!$companyUser) {
|
|
|
1946 |
return new JsonModel([
|
|
|
1947 |
'success' => false,
|
|
|
1948 |
'data' => 'ERROR_COMPANY_USER_NOT_FOUND'
|
|
|
1949 |
]);
|
|
|
1950 |
|
|
|
1951 |
}
|
|
|
1952 |
|
|
|
1953 |
if($companyUser->status != CompanyUser::STATUS_ACCEPTED && $companyUser->status != CompanyUser::STATUS_ADMIN_WILL_ADD) {
|
|
|
1954 |
return new JsonModel([
|
|
|
1955 |
'success' => false,
|
|
|
1956 |
'data' => 'ERROR_COMPANY_USER_IS_NOT_ACTIVE'
|
|
|
1957 |
]);
|
|
|
1958 |
}
|
|
|
1959 |
|
|
|
1960 |
|
|
|
1961 |
|
|
|
1962 |
|
|
|
1963 |
if($request->isPost()) {
|
|
|
1964 |
|
|
|
1965 |
$companyRoleMapper = CompanyRoleMapper::getInstance($this->adapter);
|
|
|
1966 |
$companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
|
|
|
1967 |
$companyUserRoleMapper = CompanyUserRoleMapper::getInstance($this->adapter);
|
|
|
1968 |
|
16766 |
efrain |
1969 |
$backend = Functions::sanitizeFilterString($this->params()->fromPost('backend') );
|
1 |
www |
1970 |
$companyUser->backend = $backend == CompanyUser::BACKEND_YES ? CompanyUser::BACKEND_YES : CompanyUser::BACKEND_NO;
|
|
|
1971 |
$companyUserMapper->update($companyUser);
|
|
|
1972 |
|
|
|
1973 |
|
|
|
1974 |
$roleMapper = RoleMapper::getInstance($this->adapter);
|
|
|
1975 |
$roles = $roleMapper->fetchAll();
|
|
|
1976 |
|
|
|
1977 |
|
|
|
1978 |
foreach($roles as $role)
|
|
|
1979 |
{
|
|
|
1980 |
$companyRole = $companyRoleMapper->fetchOneByCompanyIdAndRoleId($currentCompany->id, $role->id);
|
|
|
1981 |
if(!$companyRole) {
|
|
|
1982 |
$companyUserRoleMapper->deleteByCompanyIdAndRoleId($currentCompany->id, $role->id);
|
|
|
1983 |
continue;
|
|
|
1984 |
}
|
|
|
1985 |
|
|
|
1986 |
$checked = filter_var( $this->params()->fromPost('checked' . $role->id), FILTER_SANITIZE_NUMBER_INT);
|
|
|
1987 |
|
16943 |
efrain |
1988 |
|
|
|
1989 |
|
1 |
www |
1990 |
if($checked) {
|
|
|
1991 |
|
|
|
1992 |
$companyUserRole = $companyUserRoleMapper->fetchOneByCompanyIdAndUserIdAndRoleId($currentCompany->id, $user->id, $role->id);
|
|
|
1993 |
if(!$companyUserRole) {
|
|
|
1994 |
|
|
|
1995 |
$companyUserRole = new CompanyUserRole();
|
|
|
1996 |
$companyUserRole->company_id = $currentCompany->id;
|
|
|
1997 |
$companyUserRole->role_id = $role->id;
|
|
|
1998 |
$companyUserRole->user_id = $user->id;
|
|
|
1999 |
|
|
|
2000 |
$companyUserRoleMapper->insert($companyUserRole);
|
|
|
2001 |
|
|
|
2002 |
}
|
|
|
2003 |
|
|
|
2004 |
|
|
|
2005 |
|
|
|
2006 |
|
|
|
2007 |
} else {
|
|
|
2008 |
|
|
|
2009 |
$companyUserRoleMapper->deleteByCompanyIdAndUserIdAndRoleId($currentCompany->id, $user->id, $role->id);
|
|
|
2010 |
}
|
|
|
2011 |
}
|
|
|
2012 |
|
|
|
2013 |
$this->logger->info('Se actualizo los roles del usuario : ' . $user->email . ' en la empresa ' . $currentCompany->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
|
|
2014 |
|
|
|
2015 |
return new JsonModel([
|
|
|
2016 |
'success' => true,
|
|
|
2017 |
'data' => 'LABEL_RECORD_UPDATED'
|
|
|
2018 |
]);
|
|
|
2019 |
|
|
|
2020 |
|
|
|
2021 |
} else if ($request->isGet()) {
|
|
|
2022 |
$companyServiceMapper = CompanyServiceMapper::getInstance($this->adapter);
|
|
|
2023 |
|
|
|
2024 |
$roleMapper = RoleMapper::getInstance($this->adapter);
|
|
|
2025 |
$records = $roleMapper->fetchAll();
|
|
|
2026 |
|
4 |
efrain |
2027 |
|
|
|
2028 |
|
1 |
www |
2029 |
$companyRoleMapper = CompanyRoleMapper::getInstance($this->adapter);
|
|
|
2030 |
$companyUserRoleMapper = CompanyUserRoleMapper::getInstance($this->adapter);
|
|
|
2031 |
|
|
|
2032 |
$roles = [];
|
|
|
2033 |
foreach($records as $record)
|
|
|
2034 |
{
|
|
|
2035 |
if($record->creator == Role::CREATOR_YES) {
|
|
|
2036 |
continue;
|
|
|
2037 |
}
|
|
|
2038 |
|
|
|
2039 |
if($record->service_id) {
|
|
|
2040 |
$companyService = $companyServiceMapper->fetchOneByCompanyIdAndServiceId($currentCompany->id, $record->service_id);
|
|
|
2041 |
if(!$companyService || $companyService->status == CompanyService::INACTIVE) {
|
|
|
2042 |
continue;
|
|
|
2043 |
}
|
|
|
2044 |
|
|
|
2045 |
}
|
|
|
2046 |
|
|
|
2047 |
|
|
|
2048 |
|
|
|
2049 |
$companyRole = $companyRoleMapper->fetchOneByCompanyIdAndRoleId($currentCompany->id, $record->id);
|
|
|
2050 |
if(!$companyRole) {
|
|
|
2051 |
continue;
|
|
|
2052 |
}
|
|
|
2053 |
|
|
|
2054 |
$companyUserRole = $companyUserRoleMapper->fetchOneByCompanyIdAndUserIdAndRoleId($currentCompany->id, $user->id, $record->id);
|
|
|
2055 |
|
|
|
2056 |
|
|
|
2057 |
$roles[ $record->id ] = [
|
|
|
2058 |
'id' => $record->id,
|
|
|
2059 |
'name' => $record->name,
|
|
|
2060 |
'fixed' => $record->creator == Role::CREATOR_YES ? true : false,
|
|
|
2061 |
'checked' => $companyUserRole ? true : false,
|
|
|
2062 |
];
|
4 |
efrain |
2063 |
|
|
|
2064 |
|
1 |
www |
2065 |
}
|
|
|
2066 |
|
|
|
2067 |
|
|
|
2068 |
|
|
|
2069 |
$data = [
|
|
|
2070 |
'success' => true,
|
|
|
2071 |
'data' => [
|
|
|
2072 |
'backend' => $companyUser->backend == CompanyUser::BACKEND_YES ? 1 : 0,
|
|
|
2073 |
'roles' => $roles,
|
|
|
2074 |
] ,
|
|
|
2075 |
];
|
|
|
2076 |
|
|
|
2077 |
|
|
|
2078 |
|
|
|
2079 |
return new JsonModel($data);
|
|
|
2080 |
} else {
|
|
|
2081 |
$data = [
|
|
|
2082 |
'success' => false,
|
|
|
2083 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
2084 |
];
|
|
|
2085 |
|
|
|
2086 |
return new JsonModel($data);
|
|
|
2087 |
}
|
|
|
2088 |
|
|
|
2089 |
return new JsonModel($data);
|
|
|
2090 |
}
|
|
|
2091 |
|
|
|
2092 |
|
16248 |
efrain |
2093 |
public function changeTypeAction()
|
|
|
2094 |
{
|
|
|
2095 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
2096 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
2097 |
|
|
|
2098 |
$request = $this->getRequest();
|
|
|
2099 |
|
|
|
2100 |
if($request->isGet()) {
|
|
|
2101 |
$uuid = $this->params()->fromRoute('id');
|
|
|
2102 |
if(!$uuid) {
|
|
|
2103 |
return new JsonModel([
|
|
|
2104 |
'success' => false,
|
|
|
2105 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
2106 |
]);
|
|
|
2107 |
}
|
|
|
2108 |
|
|
|
2109 |
$userMapper = UserMapper::getInstance($this->adapter);
|
|
|
2110 |
$user = $userMapper->fetchOneByUuid($uuid);
|
|
|
2111 |
|
|
|
2112 |
|
|
|
2113 |
|
|
|
2114 |
if($user) {
|
|
|
2115 |
return new JsonModel([
|
|
|
2116 |
'success' => true,
|
|
|
2117 |
'data' => [
|
|
|
2118 |
'usertype_id' => $user->usertype_id,
|
|
|
2119 |
]
|
|
|
2120 |
]);
|
|
|
2121 |
} else {
|
|
|
2122 |
return new JsonModel([
|
|
|
2123 |
'success' => false,
|
|
|
2124 |
'data' => 'ERROR_USER_NOT_FOUND'
|
|
|
2125 |
]);
|
|
|
2126 |
}
|
|
|
2127 |
|
|
|
2128 |
}
|
|
|
2129 |
|
|
|
2130 |
if($request->isPost()) {
|
|
|
2131 |
|
|
|
2132 |
$uuid = $this->params()->fromRoute('id');
|
|
|
2133 |
if(!$uuid) {
|
|
|
2134 |
return new JsonModel([
|
|
|
2135 |
'success' => false,
|
|
|
2136 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
2137 |
]);
|
|
|
2138 |
}
|
|
|
2139 |
|
|
|
2140 |
$userMapper = UserMapper::getInstance($this->adapter);
|
|
|
2141 |
$user = $userMapper->fetchOneByUuid($uuid);
|
|
|
2142 |
|
|
|
2143 |
if(!$user) {
|
|
|
2144 |
return new JsonModel([
|
|
|
2145 |
'success' => false,
|
|
|
2146 |
'data' => 'ERROR_USER_NOT_FOUND'
|
|
|
2147 |
]);
|
|
|
2148 |
}
|
|
|
2149 |
|
|
|
2150 |
|
|
|
2151 |
$dataPost = $request->getPost()->toArray();
|
|
|
2152 |
$form = new ChangeTypeForm();
|
|
|
2153 |
$form->setData($dataPost);
|
|
|
2154 |
|
|
|
2155 |
if($form->isValid()) {
|
|
|
2156 |
$dataPost = (array) $form->getData();
|
|
|
2157 |
|
|
|
2158 |
$result = $userMapper->updateUserTypeId($user, $dataPost['usertype_id']);
|
|
|
2159 |
if($result) {
|
|
|
2160 |
$this->logger->info('Cambio del tipo de usuario realizado por realizado', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
|
|
2161 |
|
|
|
2162 |
|
|
|
2163 |
return new JsonModel([
|
|
|
2164 |
'success' => true,
|
|
|
2165 |
'data' => 'LABEL_USER_CHANGE_TYPE_HAS_BEEN_UPDATED'
|
|
|
2166 |
|
|
|
2167 |
]);
|
|
|
2168 |
} else {
|
|
|
2169 |
$this->logger->err('Cambio del tipo de usuario - error desconocido', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
|
|
2170 |
|
|
|
2171 |
return new JsonModel([
|
|
|
2172 |
'success' => true,
|
|
|
2173 |
'data' => 'ERROR_THERE_WAS_AN_ERROR'
|
|
|
2174 |
|
|
|
2175 |
]);
|
|
|
2176 |
|
|
|
2177 |
}
|
|
|
2178 |
|
|
|
2179 |
} else {
|
|
|
2180 |
$messages = [];
|
|
|
2181 |
|
|
|
2182 |
$form_messages = (array) $form->getMessages();
|
|
|
2183 |
foreach($form_messages as $fieldname => $field_messages)
|
|
|
2184 |
{
|
|
|
2185 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
2186 |
}
|
|
|
2187 |
|
|
|
2188 |
return new JsonModel([
|
|
|
2189 |
'success' => false,
|
|
|
2190 |
'data' => $messages
|
|
|
2191 |
]);
|
|
|
2192 |
}
|
|
|
2193 |
|
|
|
2194 |
}
|
|
|
2195 |
|
|
|
2196 |
|
|
|
2197 |
|
|
|
2198 |
return new JsonModel([
|
|
|
2199 |
'success' => false,
|
|
|
2200 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
2201 |
]);
|
|
|
2202 |
}
|
|
|
2203 |
|
|
|
2204 |
|
1 |
www |
2205 |
}
|