Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev 15460 Rev 16248
Línea 45... Línea 45...
45
use LeadersLinked\Mapper\CompanyFollowerMapper;
45
use LeadersLinked\Mapper\CompanyFollowerMapper;
46
use LeadersLinked\Model\CompanyFollower;
46
use LeadersLinked\Model\CompanyFollower;
47
use LeadersLinked\Mapper\CountryMapper;
47
use LeadersLinked\Mapper\CountryMapper;
48
use LeadersLinked\Mapper\LocationMapper;
48
use LeadersLinked\Mapper\LocationMapper;
49
use LeadersLinked\Model\Location;
49
use LeadersLinked\Model\Location;
-
 
50
use LeadersLinked\Form\User\ChangeTypeForm;
Línea 50... Línea 51...
50
 
51
 
51
class UserController extends AbstractActionController
52
class UserController extends AbstractActionController
52
{
53
{
53
    /**
54
    /**
Línea 171... Línea 172...
171
                    $allowAccept    = $acl->isAllowed($currentUser->usertype_id, 'users/accept') ? 1 : 0;
172
                    $allowAccept    = $acl->isAllowed($currentUser->usertype_id, 'users/accept') ? 1 : 0;
172
                    $allowCancel    = $acl->isAllowed($currentUser->usertype_id, 'users/cancel') ? 1 : 0;
173
                    $allowCancel    = $acl->isAllowed($currentUser->usertype_id, 'users/cancel') ? 1 : 0;
173
                    $allowReject    = $acl->isAllowed($currentUser->usertype_id, 'users/reject') ? 1 : 0;
174
                    $allowReject    = $acl->isAllowed($currentUser->usertype_id, 'users/reject') ? 1 : 0;
174
                    $allowEdit     = $acl->isAllowed($currentUser->usertype_id, 'users/edit') ? 1 : 0;
175
                    $allowEdit     = $acl->isAllowed($currentUser->usertype_id, 'users/edit') ? 1 : 0;
Línea -... Línea 176...
-
 
176
                    
Línea 175... Línea 177...
175
                    
177
 
176
                    
178
                    
177
                    $status = filter_var($this->params()->fromQuery('status'), FILTER_SANITIZE_STRING);
179
                    $status = filter_var($this->params()->fromQuery('status'), FILTER_SANITIZE_STRING);
178
                    if(!in_array($status, [
180
                    if(!in_array($status, [
Línea 320... Línea 322...
320
          
322
          
321
                    
323
                    
322
                    $acl = $this->getEvent()->getViewModel()->getVariable('acl');
324
                    $acl = $this->getEvent()->getViewModel()->getVariable('acl');
-
 
325
                    $allowUnblock = $acl->isAllowed($currentUser->usertype_id, 'users/unblock');
-
 
326
                    $allowChangePassword = $acl->isAllowed($currentUser->usertype_id, 'users/change-password');
-
 
327
                    $allowChangeType   = $acl->isAllowed($currentUser->usertype_id, 'users/change-type') ? 1 : 0;
Línea 323... Línea 328...
323
                    $allowUnblock = $acl->isAllowed($currentUser->usertype_id, 'users/unblock');
328
                    
324
                    $allowChangePassword = $acl->isAllowed($currentUser->usertype_id, 'users/change-password');
329
                    
Línea 325... Línea 330...
325
                    
330
                    
Línea 350... Línea 355...
350
                            $details['email_verified'] = 'LABEL_YES';
355
                            $details['email_verified'] = 'LABEL_YES';
Línea 351... Línea 356...
351
                            
356
                            
352
                        } else if($record->email_verified == User::EMAIL_VERIFIED_NO ) {
357
                        } else if($record->email_verified == User::EMAIL_VERIFIED_NO ) {
353
                            $details['email_verified'] = 'LABEL_NO';
358
                            $details['email_verified'] = 'LABEL_NO';
-
 
359
                        }
-
 
360
                        
-
 
361
                        if($record->usertype_id == UserType::ADMIN) {
-
 
362
                            $details['user_type'] = 'LABEL_ADMINISTRATOR';
-
 
363
                        } else   if($record->usertype_id == UserType::USER) {
-
 
364
                            $details['user_type'] = 'LABEL_USER';
-
 
365
                        }
354
                        }
366
                        
Línea 355... Línea 367...
355
                        $details['login_attempt'] = $record->login_attempt;
367
                        $details['login_attempt'] = $record->login_attempt;
356
                        
368
                        
-
 
369
                        
357
                        
370
                        $actions['link_change_password'] = $allowChangePassword ? $this->url()->fromRoute('users/change-password', ['id' => $record->uuid ]) : '';
-
 
371
                        $actions['link_unblock'] = $allowUnblock && $record->blocked == User::BLOCKED_YES ? $this->url()->fromRoute('users/unblock', ['id' => $record->uuid ]) : '';
358
                        $actions['link_change_password'] = $allowChangePassword ? $this->url()->fromRoute('users/change-password', ['id' => $record->uuid ]) : '';
372
                        $actions['link_change_type'] =  $record->is_super_user == User::IS_SUPER_USER_NO && $allowChangeType ? $this->url()->fromRoute('users/change-type', ['id' => $record->uuid ]) : '';
359
                        $actions['link_unblock'] = $allowUnblock && $record->blocked == User::BLOCKED_YES ? $this->url()->fromRoute('users/unblock', ['id' => $record->uuid ]) : '';
-
 
360
 
-
 
361
                        $item = [
373
                        
362
                            
374
                        
363
                            
375
                        $item = [
364
                            'first_name' => $record->first_name,
376
                            'first_name' => $record->first_name,
365
                            'last_name' => $record->last_name,
377
                            'last_name' => $record->last_name,
Línea 389... Línea 401...
389
            $viewModel = new ViewModel();
401
            $viewModel = new ViewModel();
Línea 390... Línea 402...
390
            
402
            
391
            
403
            
-
 
404
            $formUploadUsers = new UserUploadForm();
-
 
405
            $formChangePassword = new ChangePasswordForm();
392
            $formUploadUsers = new UserUploadForm();
406
            $formChangeType = new ChangeTypeForm();
393
            $formChangePassword = new ChangePasswordForm();
407
            
394
            $company = $currentUserPlugin->getCompany();
408
            $company = $currentUserPlugin->getCompany();
Línea 395... Línea 409...
395
            if($company) {
409
            if($company) {
396
                $viewModel->setTemplate('leaders-linked/users/company.phtml');
410
                $viewModel->setTemplate('leaders-linked/users/company.phtml');
397
                 
411
                 
398
            } else { 
412
            } else { 
399
                $viewModel->setTemplate('leaders-linked/users/index.phtml');
413
                $viewModel->setTemplate('leaders-linked/users/index.phtml');
400
            }
414
            }
-
 
415
            $viewModel->setVariables([
401
            $viewModel->setVariables([
416
                'formUploadUsers' => $formUploadUsers,
402
                'formUploadUsers' => $formUploadUsers,
417
                'formChangePassword' => $formChangePassword,
Línea 403... Línea 418...
403
                'formChangePassword' => $formChangePassword,
418
                'formChangeType' => $formChangeType,
404
            ] );
419
            ] );
Línea 2017... Línea 2032...
2017
        
2032
        
2018
        return new JsonModel($data);
2033
        return new JsonModel($data);
Línea -... Línea 2034...
-
 
2034
    }
-
 
2035
    
-
 
2036
    
-
 
2037
    public function changeTypeAction()
-
 
2038
    {
-
 
2039
        $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
2040
        $currentUser = $currentUserPlugin->getUser();
-
 
2041
        
-
 
2042
        $request = $this->getRequest();
-
 
2043
        
-
 
2044
        if($request->isGet()) {
-
 
2045
            $uuid = $this->params()->fromRoute('id');
-
 
2046
            if(!$uuid) {
-
 
2047
                return new JsonModel([
-
 
2048
                    'success'   => false,
-
 
2049
                    'data'      => 'ERROR_INVALID_PARAMETER'
-
 
2050
                ]);
-
 
2051
            }
-
 
2052
            
-
 
2053
            $userMapper = UserMapper::getInstance($this->adapter);
-
 
2054
            $user = $userMapper->fetchOneByUuid($uuid);
-
 
2055
            
-
 
2056
            
-
 
2057
            
-
 
2058
            if($user) {
-
 
2059
                return new JsonModel([
-
 
2060
                    'success'   => true,
-
 
2061
                    'data'      => [
-
 
2062
                        'usertype_id' => $user->usertype_id,
-
 
2063
                    ]
-
 
2064
                ]);
-
 
2065
            } else {
-
 
2066
                return new JsonModel([
-
 
2067
                    'success'   => false,
-
 
2068
                    'data'      => 'ERROR_USER_NOT_FOUND'
-
 
2069
                ]);
-
 
2070
            }
-
 
2071
            
-
 
2072
        }
-
 
2073
        
-
 
2074
        if($request->isPost()) {
-
 
2075
            
-
 
2076
            $uuid = $this->params()->fromRoute('id');
-
 
2077
            if(!$uuid) {
-
 
2078
                return new JsonModel([
-
 
2079
                    'success'   => false,
-
 
2080
                    'data'      => 'ERROR_INVALID_PARAMETER'
-
 
2081
                ]);
-
 
2082
            }
-
 
2083
            
-
 
2084
            $userMapper = UserMapper::getInstance($this->adapter);
-
 
2085
            $user = $userMapper->fetchOneByUuid($uuid);
-
 
2086
            
-
 
2087
            if(!$user) {
-
 
2088
                return new JsonModel([
-
 
2089
                    'success'   => false,
-
 
2090
                    'data'      => 'ERROR_USER_NOT_FOUND'
-
 
2091
                ]);
-
 
2092
            }
-
 
2093
            
-
 
2094
            
-
 
2095
            $dataPost = $request->getPost()->toArray();
-
 
2096
            $form = new ChangeTypeForm();
-
 
2097
            $form->setData($dataPost);
-
 
2098
            
-
 
2099
            if($form->isValid()) {
-
 
2100
                $dataPost = (array) $form->getData();
-
 
2101
                
-
 
2102
                $result = $userMapper->updateUserTypeId($user, $dataPost['usertype_id']);
-
 
2103
                if($result) {
-
 
2104
                    $this->logger->info('Cambio del tipo de usuario realizado por realizado', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
-
 
2105
                        
-
 
2106
                        
-
 
2107
                    return new JsonModel([
-
 
2108
                        'success'   => true,
-
 
2109
                        'data'      => 'LABEL_USER_CHANGE_TYPE_HAS_BEEN_UPDATED'
-
 
2110
                            
-
 
2111
                    ]);
-
 
2112
                } else {
-
 
2113
                    $this->logger->err('Cambio del tipo de usuario - error desconocido', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
-
 
2114
                        
-
 
2115
                    return new JsonModel([
-
 
2116
                        'success'   => true,
-
 
2117
                        'data'      => 'ERROR_THERE_WAS_AN_ERROR'
-
 
2118
                            
-
 
2119
                    ]);
-
 
2120
 
-
 
2121
                }
-
 
2122
                
-
 
2123
            } else {
-
 
2124
                $messages = [];
-
 
2125
                
-
 
2126
                $form_messages = (array) $form->getMessages();
-
 
2127
                foreach($form_messages  as $fieldname => $field_messages)
-
 
2128
                {
-
 
2129
                    $messages[$fieldname] = array_values($field_messages);
-
 
2130
                }
-
 
2131
                
-
 
2132
                return new JsonModel([
-
 
2133
                    'success'   => false,
-
 
2134
                    'data'   => $messages
-
 
2135
                ]);
-
 
2136
            }
-
 
2137
            
-
 
2138
        }
-
 
2139
        
-
 
2140
        
-
 
2141
        
-
 
2142
        return new JsonModel([
-
 
2143
            'success' => false,
-
 
2144
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
-
 
2145
        ]);
2019
    }
2146
    }