示例#1
0
 /**
  *
  * @param type $id
  * @throws Exception
  */
 public function authUserById($id)
 {
     $user = Users::findFirstById($id);
     if ($user == false) {
         throw new Exception('The user does not exist');
     }
     $this->checkUserFlags($user);
     $userInfo['id'] = $user->id;
     $userInfo['cpf'] = $user->cpf;
     $userInfo['email'] = $user->email;
     $userInfo['userName'] = explode('@', $user->email)[0];
     $colaboradores = new Colaboradores();
     $colaborador = $colaboradores->getDadosFuncionario($user->cpf);
     $funcionarios = new Pfunc();
     $funcionario = $funcionarios->getDadosFuncionario($user->cpf);
     $infoColaborador = [];
     if ($funcionario) {
         $infoColaborador = array_merge($colaborador, $funcionario);
     }
     $profile = [];
     $userGroups = UsersGroups::find('userId = ' . $user->id);
     if (count($userGroups) > 0) {
         foreach ($userGroups as $userGroup) {
             $perfils = Perfils::find('groupId = ' . $userGroup->groupId);
             if (count($perfils) > 0) {
                 foreach ($perfils as $perfil) {
                     $profile[$perfil->modules->slug][$perfil->controllers->slug][$perfil->actions->slug] = $perfil->permission;
                 }
             }
         }
     }
     $perfils = Perfils::find('userId = ' . $user->id);
     if (count($perfils) > 0) {
         foreach ($perfils as $perfil) {
             $profile[$perfil->modules->slug][$perfil->controllers->slug][$perfil->actions->slug] = $perfil->actions->permission;
         }
     }
     $this->session->set('auth-identity', ['userInfo' => $userInfo, 'dadosERP' => $infoColaborador, 'profile' => $profile]);
 }
 /**
  * Deletes a perfil
  *
  * @param string $id
  */
 public function deleteAction()
 {
     try {
         if (!$this->request->isPost()) {
             throw new Exception('Acesso não permitido a essa action.');
         }
         if ($this->request->isAjax()) {
             $this->view->disable();
         }
         $id = $this->request->getPost('id');
         $perfil = Perfils::findFirstByid($id);
         if (!$perfil) {
             throw new Exception('Perfil não encontrado!');
         }
         if (!$perfil->delete()) {
             $msg = '';
             foreach ($perfil->getMessages() as $message) {
                 $msg .= $message . '<br />';
             }
             throw new Exception($msg);
         }
         echo 'ok';
     } catch (Exception $exc) {
         $this->flash->error($exc->getMessage());
         return $this->response->redirect('nucleo/perfils');
     }
 }