Exemplo n.º 1
0
 public function editAction()
 {
     // action body
     $request = $this->getRequest();
     $postid = (int) $request->getParam('id');
     if (!Zend_Auth::getInstance()->hasIdentity()) {
         $this->_redirect('posts/view/id/' . $postid);
     }
     $identity = Zend_Auth::getInstance()->getIdentity();
     $acl = new Model_Acl();
     if ($acl->isAllowed($identity['Role'], 'posts', 'edit')) {
         $postForm = new Form_Post();
         $postModel = new Model_DbTable_Posts();
         if ($this->getRequest()->isPost()) {
             if ($postForm->isValid($request->getPost())) {
                 $postModel->updatePost($postForm->getValues());
                 $this->_redirect('posts/view/id/' . $postid);
             }
         } else {
             $result = $postModel->getPost($postid);
             $postForm->populate($result);
         }
         $this->view->postForm = $postForm;
     } else {
         var_dump($identity['Role']);
         //$this->_redirect('posts/view/id/'.$postid);
     }
 }
Exemplo n.º 2
0
 public function newAction()
 {
     $this->_form = new Mybase_Form_Project();
     $session = new Zend_Session_Namespace('Zend_Auth');
     $this->_form->populate(array('iduser' => $session->storage->iduser));
     $this->view->form = $this->_form;
     $formData = $this->getRequest()->getPost();
     if ($this->_request->isPost()) {
         if ($this->_form->isValid($formData)) {
             $lastInsertId = $this->_model->save($formData);
             $acl = new Model_Acl();
             if (isset($formData['img'])) {
                 $account = new Model_Account();
                 if (!is_dir(ROOT_PATH . '/public/files/' . $account->getId())) {
                     mkdir(ROOT_PATH . '/public/files/' . $account->getId());
                 }
                 mkdir(ROOT_PATH . '/public/files/' . $account->getId() . '/' . $lastInsertId . '/');
                 rename(ROOT_PATH . '/public/files/tmp/' . $formData['img'], ROOT_PATH . '/public/files/' . $account->getId() . '/' . $lastInsertId . '/' . $formData['img']);
             }
             $acl->createDefault($lastInsertId, $formData['iduser']);
             $this->_flash('New project has been successfully created', 'done');
             return $this->_redirect('/' . $lastInsertId . '/team');
         } else {
             $this->_flash('Formulář není vyplněn správně', 'error', false);
             $this->_form->populate($formData);
         }
     }
 }
Exemplo n.º 3
0
 public function deleteAction()
 {
     $roleId = $this->_getParam('id');
     $roleRow = $this->aclModel->getRoleById($roleId);
     if (!$roleRow or $roleRow->getIsSystemRole()) {
         throw new Exception('Invalid role');
     }
     $delete = $this->aclModel->deleteRole($roleRow);
     if (!$delete['status']) {
         $this->view->messageError = $delete['messageError'];
     }
     $this->_forward('index');
 }
Exemplo n.º 4
0
 /**
  * Check permissions before dispatch process
  *
  * @throws Zend_Auth_Adapter_Exception if answering the authentication query is impossible
  * @param Zend_Controller_Request_Abstract $request
  * @return void
  */
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     $resource = $request->getControllerName();
     $action = $request->getActionName();
     if ($this->_auth->hasIdentity()) {
         $identity = $this->_auth->getStorage()->read();
         $role = $identity->role;
     } else {
         $role = $this->_defaultRole;
     }
     if ($this->_acl->has($resource) && !$this->_acl->isAllowed($role, $resource, $action)) {
         $request->setControllerName('error')->setActionName('deny');
     }
 }
Exemplo n.º 5
0
 public function load_resources()
 {
     $res_selects = array();
     foreach (Model_Resources::getInstance()->find_all(Model_Resources::getInstance()->table()->idField()) as $res) {
         error_log(__METHOD__ . ': loading resource ' . $res->identity());
         $spec = array('label' => $res->title);
         $res_name = 'resource_' . $res->identity();
         $res_selects[] = $res_name;
         $spec['name'] = $res_name;
         $spec['multiOptions'] = self::$res_options;
         $select = new Zend_Form_Element_Select($spec);
         $domain = $this->get_domain();
         if ($domain && $domain->isSaved()) {
             if ($value = Model_Acl::find_acl($res, $domain)) {
                 error_log(__METHOD__ . ': value = ' . $value);
                 $select->setValue($value);
             } else {
                 error_log(__METHOD__ . ': no value for res = ' . $res->identity() . ', role = ' . $domain->identity());
             }
         } else {
             error_log(__METHOD__ . ': domain not saved');
         }
         $this->addElement($select);
     }
 }
Exemplo n.º 6
0
 public function preDispatch()
 {
     $roleUser = '******';
     if ($this->_auth->hasIdentity()) {
         $user = $this->_auth->getIdentity();
         $roleUser = is_object($user) ? $this->_auth->getIdentity()->getRole() : null;
     }
     $request = $this->_action->getRequest();
     $module = $request->getModuleName();
     $controller = $request->getControllerName();
     $this->_resourceName = $resource = $module . ':' . $controller;
     $privilege = $request->getActionName();
     if (!$this->_acl->has($this->_resourceName)) {
         $Acl = new Model_Acl();
         $Acl->createResource($module, $controller);
         $this->_resourceName = null;
     }
     if ($this->_acl->isAllowed($roleUser, $this->_resourceName, $privilege)) {
         return;
     }
     $classController = ucfirst($controller) . 'Controller';
     if ($module != 'default') {
         $classController = ucfirst($module) . '_' . $classController;
     }
     $classMethods = get_class_methods($classController);
     if (!in_array($privilege . 'Action', $classMethods) and $module != 'default') {
         throw new Exception('No action error: ' . $privilege);
     }
     /* Módulo default qualquer papel pode acessar */
     if ($module == 'default') {
         return;
     }
     $baseUrl = new Zend_View_Helper_BaseUrl();
     if ($this->_auth->hasIdentity()) {
         die("<b title='{$roleUser}, {$this->_resourceName}'>Sem acesso.</b>, <a href='" . $baseUrl->baseUrl('login/logout') . "'>tente novamente.</a>");
     }
     Zend_Layout::getMvcInstance()->setLayout('site');
     $request->setModuleName($this->_noacl['module'])->setControllerName($this->_noacl['controller'])->setActionName($this->_noacl['action'])->setParam('originalRequest', array('resource' => $resource, 'privilege' => $privilege, 'uri' => $request->getRequestUri(), 'role' => $roleUser))->setDispatched(false);
 }
Exemplo n.º 7
0
 public function __construct()
 {
     $acl = new Model_Acl();
     $identity = Zend_Auth::getInstance()->getIdentity();
     /*
      * Check whether they have access to it.
      */
     if (Zend_Auth::getInstance()->hasIdentity() && $acl->isAllowed($identity['Role'], 'comments', 'add')) {
         parent::__construct($options);
         $this->setName('Comments');
         $id = new Zend_Form_Element_Hidden('id');
         $name = new Zend_Form_Element_Text('name');
         $name->setLabel('Your Name')->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim')->addValidator('NotEmpty');
         $email = new Zend_Form_Element_Text('email');
         $email->setLabel('Email')->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim')->addValidator('NotEmpty');
         $webpage = new Zend_Form_Element_Text('webpage');
         $webpage->setLabel('Webpage')->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim')->addValidator('NotEmpty');
         $comment = new Zend_Form_Element_Textarea('comment');
         $comment->setLabel('Comments')->setRequired(true)->setAttrib('rows', 7)->setAttrib('cols', 30)->addFilter('StripTags')->addFilter('StringTrim')->addValidator('NotEmpty');
         $submit = new Zend_Form_Element_Submit('submit');
         $submit->setAttrib('id', 'submitbutton');
         $this->addElements(array($id, $name, $email, $webpage, $comment, $submit));
     }
 }
Exemplo n.º 8
0
 public function zupalmenus($pages = NULL)
 {
     $menu = $this->getView()->navigation()->menu();
     $menu->setAcl(Model_Acl::acl());
     if (is_null($pages)) {
         $pages = $this->pages();
     } else {
         error_log(print_r($pages, 1));
     }
     if (Model_Users::current_user()) {
         $menu->setRole(Model_Users::current_user()->role);
     } else {
         $menu->setRole('anonymous');
     }
     $router = Zend_Controller_Front::getInstance()->getRouter();
     $router = $router->getRoute('default');
     return $menu->renderMenu($pages, array('router' => $router));
 }
Exemplo n.º 9
0
 public function editAction()
 {
     $userId = $this->_getParam('id');
     $userRow = $this->userModel->getUserById($userId);
     if (!$userRow) {
         throw new Exception('Invalid user');
     }
     $this->view->userId = $userId;
     $this->_helper->viewRenderer->setRender('edit');
     $this->view->getAllPositions = $this->positionModel->getAll();
     $this->view->getAllEducation = $this->educationModel->getAll();
     $this->view->roles = $this->aclModel->getAllRoles();
     $listAdmin = false;
     if ($this->roleRow->getIsSystemAdmin() == 1) {
         $this->view->getAllRegional = $this->regionalModel->getAll();
         $listAdmin = true;
     }
     if ($this->aclModel->isAllowed($this->userAuth->getRole(), 'management:user', 'list-user-by-regional')) {
         if (!$listAdmin) {
             $userLocality = $this->userLocalityModel->getUserLocalityByUserId($this->userAuth->getUserId());
             $this->view->getAllRegional = $this->dbTable_Regional->getAllRegionalByOneRegionalServiceArea(null, $userLocality->getRegionalId());
         }
     }
     $userRowData['user'] = array('first_name' => $userRow->getFirstName(), 'surname' => $userRow->getSurname(), 'gender' => $userRow->getGender(), 'born_date' => $userRow->getBornDate(), 'position_id' => $userRow->getPositionId(), 'education_id' => $userRow->getEducationId(), 'email' => $userRow->getEmail(), 'cpf' => $userRow->getCpf(), 'login' => $userRow->getLogin(), 'status' => $userRow->getStatus(), 'password_hint' => $userRow->getPasswordHint());
     $this->view->registerRowData = $userRowData;
     $userLocalityRow = $this->userLocalityModel->getUserLocalityByUserId($userRow->getId());
     if ($userLocalityRow) {
         $this->view->registerRowData['userLocality']['regional_id'] = $userLocalityRow->getRegionalId();
     }
     $userRoleRow = $this->userRoleModel->getUserRoleByUserId($userRow->getId());
     $this->view->registerRowData['userRole']['role_id'] = $userRoleRow->getRoleId();
     if (!$this->getRequest()->isPost()) {
         return;
     }
     $registerRowData = $this->_getAllParams();
     $this->view->registerRowData = $registerRowData;
     $insert = $this->userModel->updateUserTransaction($registerRowData, $userRow);
     if (!$insert['status']) {
         $this->view->messageError = $insert['messageError'];
         return;
     }
     $this->view->itemSuccess = true;
     $this->view->loadUrlUser = $this->view->baseUrl('/management/user/success/itemUpdateSuccess/true/firstnameSuccess/' . urlencode($registerRowData['user']['first_name']));
 }
Exemplo n.º 10
0
 /**
  * Nastavuje opravneni pro podsekci projektu
  *
  * @param Zend_Acl $acl ACL objekt
  * @param Zend_Auth_Storage_Session $identity Objekt s identitou
  */
 private function _projectAcl($acl, $identity)
 {
     $aclModel = new Model_Acl();
     $dbData = $aclModel->getAllPerms($identity->email);
     foreach ($dbData as $aclData) {
         $perms = unserialize($aclData['permission']);
         foreach ($perms as $resource => $perm) {
             if (!$acl->has($aclData['idproject'] . '|' . $resource)) {
                 $acl->add(new Zend_Acl_Resource($aclData['idproject'] . '|' . $resource));
                 if ($perm & self::READ) {
                     $acl->allow($identity->email, $aclData['idproject'] . '|' . $resource, $this->_read);
                 }
                 if ($perm & self::CREATE) {
                     $acl->allow($identity->email, $aclData['idproject'] . '|' . $resource, $this->_create);
                 }
                 if ($perm & self::MANAGE) {
                     $acl->allow($identity->email, $aclData['idproject'] . '|' . $resource, $this->_manage);
                 }
                 $this->_resources[] = $aclData['idproject'] . '|' . $resource;
             }
         }
     }
 }
Exemplo n.º 11
0
 public static function isGestor($loggedUser = null)
 {
     if (!$loggedUser) {
         $loggedUser = Zend_Auth::getInstance()->getIdentity();
     }
     if (!$loggedUser) {
         return false;
     }
     $aclModel = new Model_Acl();
     $userRoleId = $loggedUser->getRoleId();
     $roleRow = $aclModel->getRoleById($userRoleId);
     if ($roleRow->getIsSystemAdmin() == 1) {
         return true;
     }
     $managerRoleId = Zend_Registry::get('config')->acl->roleGestorId;
     return $userRoleId == $managerRoleId;
 }
Exemplo n.º 12
0
 /**
  *
  * @param boolean $pReload
  * @return Zend_Acl
  */
 public static function acl($pReload = FALSE)
 {
     if ($pReload || is_null(self::$_acl)) {
         $acl = new Zend_Acl();
         foreach (Model_Resources::getInstance()->find_all() as $res) {
             $acl->add($res);
         }
         foreach (Model_Roles::getInstance()->find_all() as $role) {
             $acl->addRole($role);
         }
         foreach (self::getInstance()->find_all() as $grant) {
             if ($grant->allow) {
                 $acl->allow($grant->role, $grant->resource);
             } else {
                 $acl->deny($grant->role, $grant->resource);
             }
         }
         self::$_acl = $acl;
     }
     return self::$_acl;
 }
Exemplo n.º 13
0
 /**
  *
  * @param string $pResource
  * @return boolean
  */
 public function current_user_can($pResource)
 {
     if (self::current_user()) {
         return self::current_user()->can($pResource);
     } else {
         return Model_Acl::acl()->isAllowed('anonymous', $pResource);
     }
 }
Exemplo n.º 14
0
 public function createEnterpriseTransaction($ficha)
 {
     $AddressEnterprise = new Model_AddressEnterprise();
     $AddressPresident = new Model_AddressPresident();
     $President = new Model_President();
     $PresidentProgram = new Model_PresidentProgram();
     $User = new Model_User();
     $UserLocality = new Model_UserLocality();
     $Acl = new Model_Acl();
     $modelEntCatAwardCompetition = new Model_EnterpriseCategoryAwardCompetition();
     $modelLogCadastroEmpresa = new Model_LogCadastroEmpresa();
     //$Eligibility = new Model_Eligibility();
     // dados da Empresa
     $registerEnterpriseData = $ficha['enterprise'];
     $registerEnterpriseData['status'] = 'A';
     // dados endereço da Empresa
     $registerAddressEnterpriseData = $ficha['addressEnterprise'];
     // dados da presidente da Empresa
     $registerPresidentData = $ficha['president'];
     $registerPresidentData['gender'] = 'F';
     $registerPresidentData['created'] = date('Y-m-d');
     $registerPresidentData['hasnt_email'] = isset($ficha['enterprise']['hasnt_email']) ? $ficha['enterprise']['hasnt_email'] : 0;
     // dados endereço da Empresa
     $registerAddressPresidentData = $ficha['addressPresident'];
     // dados do program do presidente da Empresa
     $registerPresidentProgramData = isset($ficha['presidentProgram']) ? $ficha['presidentProgram'] : null;
     // dados do usuário
     $registerUserData = $ficha['user'];
     $registerUserData['login'] = $registerPresidentData['cpf'];
     $registerUserData['first_name'] = $registerPresidentData['name'];
     $registerUserData['surname'] = isset($registerPresidentData['nick_name']) ? $registerPresidentData['nick_name'] : null;
     $registerUserData['email'] = $registerPresidentData['email'];
     $registerUserData['status'] = 'A';
     $registerLogCadastro = isset($ficha['log_cadastro_empresa']) ? $ficha['log_cadastro_empresa'] : false;
     // start transaction externo
     Zend_Registry::get('db')->beginTransaction();
     try {
         $enterpriseEmail = isset($ficha['enterprise']['email_default']) ? $ficha['enterprise']['email_default'] : '';
         $hasntEmail = isset($ficha['enterprise']['hasnt_email']) ? $ficha['enterprise']['hasnt_email'] : 0;
         $this->validateEmail(NULL, $enterpriseEmail, $hasntEmail);
         $this->validateLandline($ficha['enterprise']['phone']);
         // Validação Categoria do Premio
         $insertCategoryAward = $this->validCategoryAward($registerEnterpriseData);
         if (!$insertCategoryAward['status']) {
             throw new Vtx_UserException($insertCategoryAward['messageError'], 10);
         }
         // 1.1 Insert Empresa
         $insertEnterprise = $this->createEnterprise($registerEnterpriseData);
         if (!$insertEnterprise['status']) {
             throw new Vtx_UserException($insertEnterprise['messageError'], 10);
         }
         // elegibilidade para questionario de diagnostico
         //$Eligibility->doDiagnosticoEligibility($insertEnterprise['row']);
         // 1.2 Insert Endereço da Empresa
         $registerAddressEnterpriseData['enterprise_id'] = $insertEnterprise['lastInsertId'];
         $insertAddressEnterprise = $AddressEnterprise->createAddressEnterprise($registerAddressEnterpriseData);
         if (!$insertAddressEnterprise['status']) {
             throw new Vtx_UserException($insertAddressEnterprise['messageError'], 10);
         }
         // validação dos campos NewsLetter da Candidata (President)
         $newsLetterValid = $President->isValidNewsletter($ficha['newsletter'], $registerPresidentData);
         if (!$newsLetterValid['status']) {
             throw new Vtx_UserException($newsLetterValid['messageError']);
         }
         // 2.1 Insert Presidente da Empresa
         $registerPresidentData['enterprise_id'] = $insertEnterprise['lastInsertId'];
         $insertPresident = $President->createPresident($registerPresidentData);
         if (!$insertPresident['status']) {
             throw new Vtx_UserException($insertPresident['messageError']);
         }
         $registerECAC = array();
         $registerECAC['enterprise_id'] = $insertEnterprise['lastInsertId'];
         $registerECAC['competition_id'] = Zend_Registry::get('configDb')->competitionId;
         $registerECAC['category_award_id'] = $registerEnterpriseData['category_award_id'];
         $insertECAC = $modelEntCatAwardCompetition->createECAC($registerECAC);
         if (!$insertECAC['status']) {
             throw new Vtx_UserException($insertECAC['messageError']);
         }
         // 2.2 Insert Endereço da Presidente
         $registerAddressPresidentData['president_id'] = $insertPresident['lastInsertId'];
         $insertAddressPresident = $AddressPresident->createAddressPresident($registerAddressPresidentData);
         if (!$insertAddressPresident['status']) {
             throw new Vtx_UserException($insertAddressPresident['messageError']);
         }
         // 2.3 Programa do Presidente da Empresa
         if ($registerPresidentProgramData) {
             $presidentId = $insertPresident['lastInsertId'];
             $createPresidentProgram = $PresidentProgram->createPresidentProgramByPresidentId($registerPresidentProgramData, $presidentId);
             if (!$createPresidentProgram['status']) {
                 throw new Vtx_UserException($createPresidentProgram['messageError']);
             }
         }
         // 3.1 Insert Responsável pelo preenchimento - usuário do sistema
         if (isset($registerUserData['set_login_cpf']) and $registerUserData['set_login_cpf'] == '1') {
             $registerUserData['login'] = $registerUserData['cpf'];
         }
         $insertUser = $User->createUser($registerUserData);
         if (!$insertUser['status']) {
             throw new Vtx_UserException($insertUser['messageError']);
         }
         // 4.1 Insert Relação UserLocality
         $registerUserLocalityData['user_id'] = $insertUser['lastInsertId'];
         $registerUserLocalityData['enterprise_id'] = $insertEnterprise['lastInsertId'];
         $insertUserLocality = $UserLocality->createUserLocality($registerUserLocalityData);
         if (!$insertUserLocality['status']) {
             throw new Vtx_UserException($insertUserLocality['messageError']);
         }
         $enterpriseEmail = isset($registerEnterpriseData['email_default']) ? $registerEnterpriseData['email_default'] : '';
         $presidentEmail = isset($registerPresidentData['email']) ? $registerPresidentData['email'] : '';
         if ($enterpriseEmail != '') {
             // Envia email com login/senha pro responsavel pelo cadastro
             $this->sendMail($enterpriseEmail, $registerUserData['first_name'], $insertEnterprise['lastInsertId']);
             if ($enterpriseEmail != $presidentEmail) {
                 $this->sendMail($presidentEmail, $registerPresidentData['name'], $insertEnterprise['lastInsertId']);
             }
         }
         // 5.1 Insert User Role
         $Acl->setUserRole($insertUser['lastInsertId'], Zend_Registry::get('config')->acl->roleEnterpriseId);
         // 6.1 Log Cadastro da Empresa
         if (!$registerLogCadastro) {
             $registerLogCadastro['user_id_log'] = $insertUser['lastInsertId'];
         }
         $logCadastroEmpresa['user_id_log'] = $registerLogCadastro['user_id_log'];
         $logCadastroEmpresa['enterprise_id'] = $insertEnterprise['lastInsertId'];
         $logCadastroEmpresa['programa_id'] = Zend_Registry::get('configDb')->competitionId;
         $logCadastroEmpresa['acao'] = 'aceite';
         $insertlogCadastroEmpresa = $modelLogCadastroEmpresa->createLogCadastroEmpresa($logCadastroEmpresa);
         if (!$insertlogCadastroEmpresa['status']) {
             throw new Vtx_UserException($insertlogCadastroEmpresa['messageError']);
         }
         // end transaction externo
         Zend_Registry::get('db')->commit();
         return array('status' => true, 'lastInsertIdKey' => $insertEnterprise['lastInsertIdKey']);
         //throw new Vtx_UserException("Chegou aqui - gravacao ate o fim codigo");
     } catch (Vtx_UserException $e) {
         Zend_Registry::get('db')->rollBack();
         return array('status' => false, 'messageError' => $e->getMessage(), 'errorCode' => $e->getCode());
     } catch (Exception $e) {
         Zend_Registry::get('db')->rollBack();
         throw new Exception($e);
     }
 }
Exemplo n.º 15
0
 /**
  *
  */
 public function roleseditexecuteAction()
 {
     $id = $this->_getParam('role_id');
     $params = array('role_id' => $id);
     $form = new Administer_Form_Zupalroles($id);
     if ($form->isValid($this->_getAllParams())) {
         $form->save();
         foreach (Model_Resources::getInstance()->findAll() as $res) {
             $resid = $res->identity();
             if ($resvalue = $this->_getParam("resource_{$resid}")) {
                 Model_Acl::getInstance()->set_acl($resid, $id, $resvalue);
             }
         }
         $params['message'] = 'Role Saved';
     } else {
         $params['error'] = 'Cannot save form';
         $params['reload'] = TRUE;
         $params = array_merge($this->_getAllParams(), $params);
     }
     $this->_forward('rolesedit', 'users', 'administer', $params);
 }