function add() { if (empty($this->data)) { $this->render(); } else { if ($this->Member->findByUsername($this->data['Member']['username'])) { $this->Member->invalidate('username'); $this->set('username_error', '用户名已经存在!'); } else { $this->cleanUpFields(); $this->data['Member']['password'] = md5($this->data['Member']['password']); $member_alias = $this->data['Member']['username']; if ($this->Member->save($this->data)) { $aro = new Aro(); $aro->create($this->Member->uid, 'Members', $this->data['Member']['username']); //把新增用户添加到"Members"组中 $aco = new Aco(); $aco->create($member_id, 3, $member_alias); $this->Acl->allow('Admins', $member_alias, '*'); $this->Acl->allow($this->Session->read('User.id'), $member_alias, '*'); $this->Session->setFlash('添加成功!'); $this->redirect('/teachers/index'); } else { $this->Session->setFlash('添加用户出错!'); } } } }
/** * add method * * @return void */ public function add() { if ($this->request->is('post')) { $this->Page->create(); if ($this->Page->save($this->request->data)) { //Edita o Model e o foreign_key do aco corresponente ao seu Page. $aco = new Aco(); $aco->create(); $aco_options = array('id' => $this->request->data['Page']['aco_id'], 'model' => 'Page', 'foreign_key' => $this->Page->id); $aco->save($aco_options); $this->Session->setFlash('Acesso controlado salvo com sucesso!', 'alert_success'); return $this->redirect(array('action' => 'index')); } else { $this->Session->setFlash('O Acesso controlado não pode ser salvo. Tente novamente!', 'alert_error'); } } }
/** * test After Save * * @return void */ public function testAfterSave() { $Post = new AclPost(); $data = array('Post' => array('author_id' => 1, 'title' => 'Acl Post', 'body' => 'post body', 'published' => 1)); $Post->save($data); $result = $this->Aco->find('first', array('conditions' => array('Aco.model' => 'Post', 'Aco.foreign_key' => $Post->id))); $this->assertTrue(is_array($result)); $this->assertEquals('Post', $result['Aco']['model']); $this->assertEquals($Post->id, $result['Aco']['foreign_key']); $aroData = array('Aro' => array('model' => 'AclPerson', 'foreign_key' => 2, 'parent_id' => null)); $this->Aro->save($aroData); $acoData = array('Aco' => array('model' => 'AclPerson', 'foreign_key' => 2, 'parent_id' => null)); $this->Aco->save($acoData); $Person = new AclPerson(); $data = array('AclPerson' => array('name' => 'Trent', 'mother_id' => 2, 'father_id' => 3)); $Person->save($data); $result = $this->Aro->find('first', array('conditions' => array('Aro.model' => 'AclPerson', 'Aro.foreign_key' => $Person->id))); $this->assertTrue(is_array($result)); $this->assertEquals(5, $result['Aro']['parent_id']); $node = $Person->node(array('model' => 'AclPerson', 'foreign_key' => 8), 'Aro'); $this->assertEquals(2, count($node)); $this->assertEquals(5, $node[0]['Aro']['parent_id']); $this->assertEquals(null, $node[1]['Aro']['parent_id']); $aroData = array('Aro' => array('model' => 'AclPerson', 'foreign_key' => 1, 'parent_id' => null)); $this->Aro->create(); $this->Aro->save($aroData); $acoData = array('Aco' => array('model' => 'AclPerson', 'foreign_key' => 1, 'parent_id' => null)); $this->Aco->create(); $this->Aco->save($acoData); $Person->read(null, 8); $Person->set('mother_id', 1); $Person->save(); $result = $this->Aro->find('first', array('conditions' => array('Aro.model' => 'AclPerson', 'Aro.foreign_key' => $Person->id))); $this->assertTrue(is_array($result)); $this->assertEquals(7, $result['Aro']['parent_id']); $node = $Person->node(array('model' => 'AclPerson', 'foreign_key' => 8), 'Aro'); $this->assertEquals(2, count($node)); $this->assertEquals(7, $node[0]['Aro']['parent_id']); $this->assertEquals(null, $node[1]['Aro']['parent_id']); }
/** * add method * * @return void */ public function add($acoId) { $aco = $this->Acl->Aco->findById($acoId); $this->set('aco', $aco); $acoParent = $this->Acl->Aco->findById($aco['Aco']['parent_id']); $this->set('acoParent', $acoParent); //debug($aco); if ($aco['Aco']['parent_id'] == 1) { $parentAlias = $aco['Aco']['alias']; } else { $parentAlias = $acoParent['Aco']['alias']; } if ($this->request->is('post')) { $this->Page->create(); if ($this->Page->save($this->request->data)) { //Edita o Model e o foreign_key do aco corresponente ao seu Page. $aco = new Aco(); $aco->create(); $aco_options = array('id' => $acoId, 'parent_alias' => $parentAlias, 'model' => 'Page', 'foreign_key' => $this->Page->id); $aco->save($aco_options); $this->Session->setFlash('Acesso controlado salvo com sucesso!', 'alert_success'); return $this->redirect(array('action' => 'index')); } else { $this->Session->setFlash('O Acesso controlado não pode ser salvo. Tente novamente!', 'alert_error'); } } }
function actionAcl() { $aro = new Aro(); $aco = new Aco(); /*$groups = array ( 0=> array ( 'alias'=>'SuperAdministrador', 'parent_id'=>null, 'model'=>'Group', 'foreign_key'=>'1'), 1=> array ( 'alias'=>'Administradores', 'parent_id'=>null, 'model'=>'Group', 'foreign_key'=>'2') ); foreach ($groups as $data) { $aro->create(); $aro->save($data); } $users = array ( 0=> array ( 'alias'=>'admin1', 'parent_id'=>1, 'model'=>'User', 'foreign_key'=>'1' ), 1=> array ( 'alias'=>'a1', 'parent_id'=>2, 'model'=>'User', 'foreign_key'=>'2' ) ); //Iterar y crear los AROs (como hijos) foreach ($users as $data) { ///Recuerda llamar a create() cuando estés guardando información dentro de bucles... $aro->create(); //Guardar datos $aro->save($data); }*/ $groups = array(0 => array('alias' => 'add', 'parent_id' => '39'), 1 => array('alias' => 'index', 'parent_id' => '39'), 2 => array('alias' => 'cPanelConnect', 'parent_id' => '39'), 3 => array('alias' => 'downloadBackup', 'parent_id' => '39')); foreach ($groups as $data) { $aco->create(); $aco->save($data); } /* $this->Acl->allow('SuperAdministrador', 'controllers'); $this->Acl->deny('Administradores', 'controllers'); $this->Acl->allow('Administradores', 'controllers/Domains'); $this->Acl->allow('Administradores', 'controllers/Emailaccounts'); $this->Acl->allow('Administradores', 'controllers/Ftpaccounts');*/ }
/** * metodo simple para actualizacion de acos * no incluye plugins ni pages ni herencia de metodos del app_controller */ private function update_acos() { $aco = new Aco(); // consulta los controladores en archivos reales $controladores = $this->ControllerList->get(); ksort($controladores); foreach ($controladores as $i => $l) { $controladores[ucfirst($i)] = $controladores[$i]; unset($controladores[$i]); sort($controladores[ucfirst($i)]); } // consultando lista de acos en bd $acos = $aco->find('threaded', array('recursive' => 0, 'order' => 'parent_id, alias')); $lista_bd = array(); foreach ($acos as $a) { $lista_bd[$a['Aco']['alias']]['option'] = 0; $lista_bd[$a['Aco']['alias']]['id'] = $a['Aco']['id']; foreach ($a['children'] as $b) { $lista_bd[$a['Aco']['alias']]['children'][$b['Aco']['alias']]['option'] = 0; $lista_bd[$a['Aco']['alias']]['children'][$b['Aco']['alias']]['id'] = $b['Aco']['id']; foreach ($b['children'] as $c) { $lista_bd[$a['Aco']['alias']]['children'][$b['Aco']['alias']]['children'][$c['Aco']['alias']]['option'] = 0; $lista_bd[$a['Aco']['alias']]['children'][$b['Aco']['alias']]['children'][$c['Aco']['alias']]['id'] = $c['Aco']['id']; } } } // insertando elementos a la lista $lista_bd['controllers']['option'] = !isset($lista_bd['controllers']) ? 1 : 2; // insertar : no hacer nada foreach ($controladores as $i => $l) { $lista_bd['controllers']['children'][$i]['option'] = !isset($lista_bd['controllers']['children'][$i]) ? 1 : 2; // insertar : no hacer nada if ($lista_bd['controllers']['children'][$i]['option'] == 1) { $aco->create(); $aco->save(array('Aco' => array('parent_id' => $lista_bd['controllers']['id'], 'alias' => $i))); $lista_bd['controllers']['children'][$i]['id'] = $aco->getLastInsertId(); } foreach ($controladores[$i] as $k) { $lista_bd['controllers']['children'][$i]['children'][$k]['option'] = !isset($lista_bd['controllers']['children'][$i]['children'][$k]) ? 1 : 2; // insertar : no hacer nada if ($lista_bd['controllers']['children'][$i]['children'][$k]['option'] == 1) { $aco->create(); $aco->save(array('Aco' => array('parent_id' => $lista_bd['controllers']['children'][$i]['id'], 'alias' => $k))); $lista_bd['controllers']['children'][$i]['children'][$k]['id'] = $aco->getLastInsertId(); } } } // borrando elementos foreach ($lista_bd['controllers']['children'] as $i => $l) { if ($lista_bd['controllers']['children'][$i]['option'] == 0) { $aco->id = $lista_bd['controllers']['children'][$i]['id']; $aco->delete(); } foreach ($lista_bd['controllers']['children'][$i]['children'] as $k => $m) { if ($lista_bd['controllers']['children'][$i]['children'][$k]['option'] == 0) { $aco->id = $lista_bd['controllers']['children'][$i]['children'][$k]['id']; $aco->delete(); } } } }
function initAcl() { $aro = new Aro(); $groupsAll = array(0 => array('alias' => 'all')); //Iterate and create ARO groups foreach ($groupsAll as $data) { //Remember to call create() when saving in loops... $aro->create(); //Save data $aro->save($data); } $aro = new Aro(); // $groups=$this->Group->find('all', array('conditions' => array('Group.id' != 1))); // debug($groups); $aroList = array(0 => array('alias' => 'admin', 'parent_id' => 1), 1 => array('alias' => 'user', 'parent_id' => 1), 2 => array('alias' => 'anonymous', 'parent_id' => 1)); // $i=0; // foreach($groups as $group){ // $aroList[$i++]= // array( // 'alias' => $group['Group']['name'], // 'parent_id' => 1, // ); // } //iterate through groups adding to aro table // $groups = array( // 0 => array( // 'alias' => 'users' // ), // 1 => array( // 'alias' => 'administrators' // ), // ); //Iterate and create ARO groups foreach ($aroList as $data) { //Remember to call create() when saving in loops... $aro->create(); //Save data $aro->save($data); } /* * next we add our existing add users to users group * ! adds all users to user group, you may add some logic to * ! detemrine admins based on role, or edit manually later * * the **whos** */ $aro = new Aro(); //pull users form existing user table $users = $this->User->find('all'); debug($users); $i = 0; foreach ($users as $user) { $id = $user['User']['id']; $groupId = $user['User']['group_id']; $aroList2[$i++] = array('alias' => $id, 'parent_id' => $groupId, 'model' => 'User', 'foreign_key' => $id); } //print to screen to verify layout debug($aroList2); //now save! foreach ($aroList2 as $data) { //Remember to call create() when saving in loops... $aro->create(); //Save data $aro->save($data); } /* * now on to *whats* can they access * * for my layout I have the entire site as a parent, two sub groups that contain all models. * */ $aco = new Aco(); //admin can access whole site $controllers = array(0 => array('alias' => 'vsetko')); //Iterate and create ARO groups foreach ($controllers as $data) { //Remember to call create() when saving in loops... $aco->create(); //Save data $aco->save($data); } $aco = new Aco(); //Here's all of our sub-ACO info in an array we can iterate through $controllers = array(0 => array('alias' => 'uploads', 'parent_id' => 1), 1 => array('alias' => 'posts', 'parent_id' => 1), 2 => array('alias' => 'galleries', 'parent_id' => 1), 3 => array('alias' => 'aclpreps', 'parent_id' => 1), 4 => array('alias' => 'p28n', 'parent_id' => 1), 5 => array('alias' => 'welcome', 'parent_id' => 1), 6 => array('alias' => 'about', 'parent_id' => 1), 7 => array('alias' => 'contact', 'parent_id' => 1), 8 => array('alias' => 'products', 'parent_id' => 1), 9 => array('alias' => 'products_form', 'parent_id' => 1)); //Iterate and create ACO nodes foreach ($controllers as $data) { //Remember to call create() when saving in loops... $aco->create(); //Save data $aco->save($data); } die; exit; $this->redirect(array('controller' => 'aclpreps', 'action' => 'index')); }