function admin_activate($uid, $active = 1)
 {
     Configure::write('debug', '0');
     //turn debugging off; debugging breaks ajax
     $aro = new Aro();
     //find the id of this user's aco
     $aro->create();
     $user_aro = $aro->find('first', array('conditions' => array('model' => 'User', 'foreign_key' => $uid), 'fields' => array('id')));
     $new_aro = array('model' => 'User', 'foreign_key' => $uid);
     if ($user_aro) {
         $new_aro['id'] = $user_aro['Aro']['id'];
     }
     if ($active) {
         // add this user to the users Aro group
         // find the id of the users group
         $aro->create();
         $users_aro = $aro->findByAlias('users');
         $users_aro_id = $users_aro['Aro']['id'];
         $new_aro['parent_id'] = $users_aro_id;
     } else {
         $new_aro['parent_id'] = NULL;
     }
     $aro->save($new_aro);
     $user['id'] = $uid;
     $user['active'] = $active;
     $this->User->save($user);
 }
 function enable($id = null)
 {
     if (empty($this->data)) {
         $this->data = $this->User->read(null, $id);
     } else {
         if ($this->User->save($this->data)) {
             $user = $this->User->read(null, $this->data['User']['id']);
             $aro_user = $user['User']['USERNAME'];
             $aro_group = null;
             $parent_id = 0;
             if ($user['User']['TYPE'] === 'MAHASISWA') {
                 $aro_group = 'Mahasiswa';
                 $parent_id = 1;
             } else {
                 if ($user['User']['TYPE'] === 'DOSEN') {
                     $aro_group = 'Dosen';
                     $parent_id = 2;
                 } else {
                     $aro_group = 'Pegawai';
                     $parent_id = 3;
                 }
             }
             $aro = new Aro();
             $aro->create();
             if (!$aro->node("{$aro_group}/{$aro_user}")) {
                 $aro->save(array('alias' => $aro_user, 'parent_id' => $parent_id, 'model' => 'User', 'foreign_key' => $user['User']['id']));
             }
             $this->Session->setFlash(__('The User has been Actived', true));
             $this->redirect(array('action' => 'index'));
         }
     }
 }
 function create_users()
 {
     $aro = new Aro();
     //Here are our user records, ready to be linked up to new ARO records
     //This data could come from a model and modified, but we're using static
     //arrays here for demonstration purposes.
     $users = array(0 => array('parent_id' => 1, 'model' => 'User', 'foreign_key' => 1), 1 => array('parent_id' => 1, 'model' => 'User', 'foreign_key' => 2), 2 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 3), 3 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 4), 4 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 5), 5 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 6), 6 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 7), 7 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 8), 8 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 9), 9 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 10), 10 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 11), 11 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 12), 12 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 13), 13 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 14), 14 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 15), 15 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 16), 16 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 17), 17 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 18), 18 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 19), 19 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 20), 20 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 21), 21 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 22), 22 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 23), 23 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 24), 24 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 25), 25 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 26), 26 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 27), 27 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 28), 28 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 29), 29 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 30), 30 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 31), 31 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 32), 32 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 33), 33 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 34), 34 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 35), 35 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 36), 36 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 37), 37 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 38), 38 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 39), 39 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 40), 40 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 41), 41 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 42), 42 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 43), 43 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 44), 44 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 45), 45 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 46), 46 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 47), 47 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 48), 48 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 49), 49 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 50), 50 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 51), 51 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 52), 52 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 53), 53 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 54), 54 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 55), 55 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 56), 56 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 57), 57 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 58), 58 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 59), 59 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 60), 60 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 61), 61 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 62), 62 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 63), 63 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 64), 64 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 65), 65 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 66), 66 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 67), 67 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 68), 68 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 69), 69 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 70), 70 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 71), 71 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 72), 72 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 73), 73 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 74), 74 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 75), 75 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 76), 76 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 77), 77 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 78), 78 => array('parent_id' => 2, 'model' => 'User', 'foreign_key' => 79), 79 => array('parent_id' => 3, 'model' => 'User', 'foreign_key' => 80));
     //Iterate and create AROs (as children)
     foreach ($users as $data) {
         //Remember to call create() when saving in loops...
         $aro->create();
         //Save data
         $aro->save($data);
     }
     //Other action logic goes here...
 }
Exemple #4
0
 function afterSave($created)
 {
     $aro = new Aro();
     if ($created) {
         // on insert
         $aro_data = array('alias' => $this->data['User']['username'], 'parent_id' => $this->data['User']['group_id'], 'model' => 'User', 'foreign_key' => $this->getLastInsertId());
         $aro->create();
         $aro->save($aro_data);
     } else {
         // on update
         $aro_data = $aro->findByForeignKeyAndModel($this->id, 'User');
         $aro_data['Aro']['parent_id'] = $this->data['User']['group_id'];
         $aro->id = $aro_data['Aro']['id'];
         $aro->save($aro_data);
     }
 }
 /**
  * test After Save
  *
  * @return void
  * @access 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->assertEqual($result['Aco']['model'], 'Post');
     $this->assertEqual($result['Aco']['foreign_key'], $Post->id);
     $aroData = array('Aro' => array('model' => 'AclPerson', 'foreign_key' => 2, 'parent_id' => null));
     $this->Aro->save($aroData);
     $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->assertEqual($result['Aro']['parent_id'], 5);
     $node = $Person->node(array('model' => 'AclPerson', 'foreign_key' => 8));
     $this->assertEqual(count($node), 2);
     $this->assertEqual($node[0]['Aro']['parent_id'], 5);
     $this->assertEqual($node[1]['Aro']['parent_id'], null);
     $aroData = array('Aro' => array('model' => 'AclPerson', 'foreign_key' => 1, 'parent_id' => null));
     $this->Aro->create();
     $this->Aro->save($aroData);
     $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->assertEqual($result['Aro']['parent_id'], 7);
     $node = $Person->node(array('model' => 'AclPerson', 'foreign_key' => 8));
     $this->assertEqual(sizeof($node), 2);
     $this->assertEqual($node[0]['Aro']['parent_id'], 7);
     $this->assertEqual($node[1]['Aro']['parent_id'], null);
 }
 /**
  * modify 
  * 
  * @access public
  * @return void
  */
 function modify()
 {
     Configure::write('debug', '0');
     $this->layout = 'ajax';
     if ($this->Acl->check($this->ZTAuth->user('username'), "Users::edit", '*')) {
         if ($this->User->save($this->data['User'])) {
             $aro = new Aro();
             $arodata = $aro->findByForeign_Key($this->data['User']['id']);
             // try to find group ARO
             $newgroup = $aro->find('model LIKE "Group" AND foreign_key =' . $this->data['User']['group_id']);
             if (empty($newgroup)) {
                 $this->set('result', '{success:false, msg:"Group ARO not found"}');
                 return;
             }
             // update ARO fields
             $arodata['Aro']['model'] = 'User';
             $arodata['Aro']['alias'] = $this->data['User']['username'];
             $arodata['Aro']['foreign_key'] = $this->data['User']['id'];
             $arodata['Aro']['parent_id'] = $newgroup['Aro']['id'];
             // create new ARO for user if it's not already exists
             if (empty($arodata['Aro']['id'])) {
                 $aro->create();
             }
             $aro->save($arodata);
             $this->set('result', '{success:true}');
         } else {
             $this->set('result', '{success:false}');
         }
     } else {
         $this->set('result', '{success:false, msg:"You can not do that"}');
     }
 }
Exemple #7
0
 function install()
 {
     $aro = new Aro();
     //创建组
     $aro->create(0, null, 'Admins');
     $aro->create(0, null, 'Finances');
     $aro->create(0, null, 'Members');
     $aro->create(0, null, 'Workstations');
     $aro->create(0, null, 'Merchants');
     //创建ARO(admin)
     $aro->create(1, null, 'admin');
     //把admin授权到Admins组
     $aro->setParent('Admins', 'admin');
     $this->Session->setFlash('系统授权成功!');
 }
Exemple #8
0
 /**
  * Members_delete method
  * Freitas - 2014-11-16
  */
 public function members_delete($id = null)
 {
     if ($this->request->is('post')) {
         //Exclusão do aro.
         $aro = new Aro();
         $aro->create();
         $aro_options = array('id' => $this->request->data['Group']['aro_id']);
         if ($aro->delete($aro_options)) {
             $this->Session->setFlash(__('Membro excluido com sucesso!'), 'alert_success');
             return $this->redirect(array('action' => 'view', $id));
         } else {
             $this->Session->setFlash(__('Membro não pode ser excluido, tente novamete!'), 'alert_error');
         }
     }
 }
 function register()
 {
     if ($this->data) {
         if ($this->data['User']['password'] == $this->Auth->password($this->data['User']['confirm_password'])) {
             $this->User->create();
             $this->User->save($this->data);
             // Insert user into the AROS
             $aro = new Aro();
             //Here are our user records, ready to be linked up to new ARO records
             //This data could come from a model and modified, but we're using static
             //arrays here for demonstration purposes.
             $users = array(0 => array('parent_id' => 3, 'model' => 'User', 'foreign_key' => $this->User->id));
             //Iterate and create AROs (as children)
             foreach ($users as $data) {
                 //Remember to call create() when saving in loops...
                 $aro->create();
                 //Save data
                 $aro->save($data);
             }
             //Other action logic goes here...
         }
     }
 }
 function assignPermissions1Dot7Dot1()
 {
     App::import('Component', 'Acl');
     $this->Acl = new AclComponent();
     // Usuarios
     $this->Acl->allow('usuarios', 'Planes/ajax_similars');
     // crear rol Ministros
     $aro = new Aro();
     $aro->create();
     $aro->save(array('alias' => 'ministros', 'parent_id' => '1'));
     $this->Acl->allow('ministros', 'Fondos/index_x_instit');
     $this->Acl->allow('ministros', 'Fondos/index_x_jurisdiccion');
     echo 'done 1.7.1';
 }
 function admin_addgroup($parentid = 0)
 {
     $aro = new Aro();
     if (empty($this->data)) {
         // allow addition of new group
     } else {
         $aro->create();
         if ($aro->save($this->data)) {
             $this->Session->setFlash(__('The new group has been saved.', true));
             $this->redirect(array('controller' => 'users', 'action' => 'groups'));
         } else {
             $this->Session->setFlash(__('There was an error creating the new group.', true));
         }
     }
     $this->set(compact('parentid'));
 }
Exemple #12
0
 function admin_activate($uid, $active = 1)
 {
     Configure::write('debug', '0');
     //turn debugging off; debugging breaks ajax
     $aro = new Aro();
     //find the id of this user's aco
     $aro->create();
     $user_aro = $aro->find('first', array('conditions' => array('model' => 'User', 'foreign_key' => $uid), 'fields' => array('id')));
     $new_aro = array('model' => 'User', 'foreign_key' => $uid);
     if ($user_aro) {
         $new_aro['id'] = $user_aro['Aro']['id'];
     }
     if ($active) {
         // add this user to the users Aro group
         // find the id of the users group
         $aro->create();
         $users_aro = $aro->findByAlias('users');
         $users_aro_id = $users_aro['Aro']['id'];
         $new_aro['parent_id'] = $users_aro_id;
         $this->User->addtotimeline(null, null, 'users-admin_activate', $uid);
     } else {
         $new_aro['parent_id'] = NULL;
     }
     $aro->save($new_aro);
     $user['id'] = $uid;
     $user['active'] = $active;
     $this->User->save($user);
     $referer = $this->params['url']['r'];
     if ($referer) {
         $this->Session->setFlash('User activation status changed.', 'admin_flash_message_success');
         $this->redirect($referer);
     }
 }
 /**
  * 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']);
 }
 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'));
 }
 /**
  * Groups_delete method
  * Freitas - 2014-11-20
  */
 public function groups_delete($userId = null, $aroId = null)
 {
     if ($this->request->is('post')) {
         //Exclusão do aro.
         $aro = new Aro();
         $aro->create();
         $aro_options = array('id' => $aroId);
         if ($aro->delete($aro_options)) {
             $this->Session->setFlash(__('Grupo excluido com sucesso!'), 'alert_success');
             return $this->redirect(array('action' => 'edit', $userId));
         } else {
             $this->Session->setFlash(__('Grupo não pode ser excluido, tente novamete!'), 'alert_error');
         }
     }
 }