/** * Add method * * @return \Cake\Network\Response|void Redirects on successful add, renders view otherwise. */ public function add() { $this->request->allowMethod(['ajax']); $alerta = $this->Alertas->newEntity(); $codLocal = $this->request->data['codLocal']; $equipamento = $this->Alertas->Equipamentos->find()->where(['tombo' => $this->request->data['tomboEquipamento']])->contain(['Locals'])->all()->first(); $bolsistas = UsersController::getBolistas($codLocal); if ($this->request->is('ajax')) { date_default_timezone_set("America/Fortaleza"); $alerta = $this->Alertas->patchEntity($alerta, $this->request->data); $alerta->dataAlerta = date('Y-m-d H:i:s'); if ($this->Alertas->save($alerta)) { if (!empty($bolsistas)) { foreach ($bolsistas as $bolsista) { $data = ['alerta' => $alerta, 'nome' => $bolsista->nome, 'email' => $bolsista->email, 'equipamento' => $equipamento, 'data' => $this->request->data]; $this->mailer($data, 'alerta', 'SGL - Alerta de Equipamento'); $bolsistaAlertas = $this->Alertas->BolsistasAlertas->newEntity(); $bolsistaAlertas->alerta_id = $alerta->id; $bolsistaAlertas->matricula_bolsista = $bolsista->matricula; $this->Alertas->BolsistasAlertas->save($bolsistaAlertas); } } echo 'Cadastrado'; } else { echo 'Erro'; } } $this->set(compact('alerta')); $this->set('_serialize', ['alerta']); }
public function changeProfilePicture($id) { $user = $this->Users->get($id); $profilePic = UsersController::getProfilePic($user); if ($this->request->is(['patch', 'post', 'put'])) { $filename = $this->getFilename($user->id); move_uploaded_file($_FILES['profilePic']['tmp_name'], $this->usersFolder . $filename); $user->photo = $filename; if ($this->Users->save($user)) { $this->Flash->success(__('The profile picture has been updated')); return $this->redirect(['controller' => 'Users', 'action' => 'edit', $user->id]); } $this->Flash->error(__('Error')); } $this->set(['user' => $user, 'profilePic' => $profilePic]); }
public function isAuthorized($user) { if ($this->request->action === 'index') { if (isset($user['role']) && $user['role'] === 'Administrador' || $user['role'] === 'Suporte') { return true; } return false; } if ($this->request->action === 'cadastrar') { if (isset($user['role'])) { return true; } return false; } if ($this->request->action === 'add') { if (isset($user['role']) && $user['role'] === 'Administrador') { return true; } return false; } if ($this->request->action === 'view') { if (isset($user['role'])) { return true; } return false; } if ($this->request->action === 'editar') { if (isset($user['role'])) { return true; } return false; } if ($this->request->action === 'edit') { if (isset($user['role']) && $user['role'] === 'Administrador') { return true; } return false; } if ($this->request->action === 'delete') { if (isset($user['role']) && $user['role'] === 'Administrador' || $user['role'] === 'Professor' || $user['role'] === 'Bolsista') { return true; } return false; } if ($this->request->action === 'find') { if (isset($user['role'])) { return true; } return false; } if ($this->request->action === 'alterarResponsavel') { if (isset($user['role']) && $user['role'] === 'Administrador' || $user['role'] === 'Professor' || $user['role'] === 'Bolsista') { return true; } return false; } if ($this->request->action === 'relatorio') { $tomboEquipamento = $this->request->params['pass']['0']; $equipamento = $this->Equipamentos->find()->where(['tombo' => $tomboEquipamento])->contain(['Locals', 'Users'])->first(); if (isset($user['role']) && $user['role'] === 'Administrador' || $user['role'] === 'Suporte' || UsersController::isCoordenador($user, $equipamento->codLocal) || $equipamento->responsavel === $user['matricula']) { return true; } return false; } if ($this->request->action === 'alterarStatus') { return true; } }
public function isAuthorized($user) { if ($this->request->action === 'view') { $codLocal = $this->request->params['pass']['0']; $local = $this->Locals->find()->where(['codigo' => $codLocal])->first(); if (!strcmp($local->tipo, 'Almoxarifado')) { if (isset($user['role']) && $user['role'] === 'Administrador' || $user['role'] === 'Suporte') { return true; } return false; } return true; } if ($this->request->action === 'edit') { if (isset($user['role']) && $user['role'] === 'Administrador') { return true; } return false; } if ($this->request->action === 'moverEquipamentos') { if (isset($user['role']) && $user['role'] === 'Administrador') { return true; } return false; } if ($this->request->action === 'bolsista') { $codLocal = $this->request->params['pass']['0']; if (isset($user['role']) && UsersController::isCoordenador($user, $codLocal) || $user['role'] === 'Administrador') { return true; } return false; } if ($this->request->action === 'relatorio') { $codLocal = $this->request->params['pass']['0']; if (isset($user['role']) && UsersController::isCoordenador($user, $codLocal) || $user['role'] === 'Administrador' || $user['role'] === 'Suporte') { return true; } return false; } return parent::isAuthorized($user); }
public function testAuthentication() { $request = new RequestAggregate(new Post(['name' => 'aaa', 'password' => 'aaa'])); $controller = new UsersController($request); $controller->loadComponent('Auth'); }
public function viewFriendshipRequests() { $user = $this->Users->get($this->Auth->user()['id']); $this->loadModel('FriendRequests'); $results = $this->Users->find()->matching('States')->matching('Cities')->join(['table' => 'friend_requests', 'alias' => 'fr', 'type' => 'LEFT', 'conditions' => 'fr.user_requesting = users.id'])->where(['fr.user_requested' => $user->id]); $this->set(['user' => $user, 'friendshipRequest' => $this->getCountFriendshipRequests($user->id), 'profilePic' => UsersController::getProfilePic($user), 'results' => $results]); }
/** * Edit method * * @param string|null $id Task id. * @return void Redirects on successful edit, renders view otherwise. * @throws \Cake\Network\Exception\NotFoundException When record not found. */ public function edit($id = null) { $task = $this->Tasks->get($id, ['contain' => []]); if ($this->request->is(['patch', 'post', 'put'])) { $task = $this->Tasks->patchEntity($task, $this->request->data); $task->id = $id; $task->name = $this->request->data['name']; $task->project_id = $this->request->data['project_id']; $task->to_user = $this->request->data['to_user']; $task->cc_user = $this->request->data['cc_user']; $task->subject = $this->request->data['subject']; $task->modified_date = date('Y-m-d H:i:s'); $task->notification_type = $this->request->data['notification_type']; if ($task->notification_type == 'weekly') { $notification_value = $this->request->data['notification_value_weekly']; $notification_value = implode(",", $notification_value); } elseif ($task->notification_type == 'monthly') { $notification_value = $this->request->data['_notification_value_monthly']; } elseif ($task->notification_type == 'dates') { $notification_value = $this->request->data['_notification_value_date']; } else { $notification_value = ""; } $task->notification_value = $notification_value; $task->notification_time = strtotime($this->request->data['notification_time']); $task->status = $this->request->data['status']; if ($this->Tasks->save($task)) { //Add attach_id if ($this->request->data('attach_id') !== NULL) { $attach_id = $this->request->data['attach_id']; foreach ($attach_id as $att_id) { $TasksFileAttachTable = TableRegistry::get('TasksFileAttach'); //check if exists $query = $TasksFileAttachTable->find()->where(['TasksFileAttach.attachment_id' => $att_id, "TasksFileAttach.task_id" => $task->id]); $chk = $query->toArray(); if (count($chk) == 0) { $fileAttach = $TasksFileAttachTable->newEntity(); $fileAttach->user_id = $this->Auth->user('id'); $fileAttach->task_id = $task->id; $fileAttach->attachment_id = $att_id; $fileAttach->attach_date = date('Y-m-d H:i:s'); $fileAttach->description = ''; $TasksFileAttachTable->save($fileAttach); } } } $this->Flash->success(__('The task has been saved.')); return $this->redirect(['action' => 'index']); } else { $this->Flash->error(__('The task could not be saved. Please, try again.')); } } $projects = $this->Tasks->Projects->find('list', ['limit' => 200]); $users = $this->Tasks->Users->find('list', ['limit' => 200]); $this->set(compact('task', 'projects', 'users')); $this->set('_serialize', ['task']); $this->set('_sub_title', 'Edit task'); $projects = new ProjectsController(); $this->set('_all_projects', $projects->getbyuserid()); $users = new UsersController(); $this->set('_all_users', $users->getPublishUser()); $fileAttach = new TasksFileAttachController(); $this->set('_all_attach_file', $fileAttach->getTaskAttachFile($id)); $this->set('_id', $id); }
private static function getSecretFile() { $file_value = ''; if (is_file(UsersController::getKeyFilePath())) { $file_value = file_get_contents(UsersController::getKeyFilePath()); } return $file_value; }