Exemple #1
0
 function afterSave($created)
 {
     if ($created) {
         // its a creation
         $id = $this->getLastInsertID();
         $aro = new Aro();
         $aro->updateAll(array('alias' => '\'User:'******'\''), array('Aro.model' => 'User', 'Aro.foreign_key' => $id));
     } else {
         // its an edit, we have to update the tree
         $data = $this->read();
         $parent_id = $data['User']['group_id'];
         $aro = new Aro();
         $aro_record = $aro->findByAlias($this->name . ':' . $this->id);
         $parent_record = $aro->findByAlias('Group:' . $parent_id);
         if (!empty($aro_record)) {
             $parent_id = '0';
             if (!empty($parent_record)) {
                 $parent_id = $parent_record['Aro']['id'];
             }
             // just changing parents
             $this->Aro->save(array('parent_id' => $parent_id, 'id' => $aro_record['Aro']['id']));
         }
     }
     return true;
 }
 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);
 }
Exemple #3
0
 function admin_create_basic_acl()
 {
     Configure::write('debug', '2');
     //turn debugging off; debugging breaks ajax
     die('not now!');
     $aco = new Aco();
     $aro = new Aro();
     /*
     $aro->create();
     $aro->save(array('alias' => 'users'));
     $aro->create();
     $aro->save(array('alias' => 'admins', 'parent_id' => 1));
     
     $aco->create();
     $aco->save(array('alias' => 'admin'));
     $aco->create();
     $aco->save(array('alias' => 'site', 'parent_id' => 1));
     */
     //$this->Acl->grant(array('alias' => 'users'), array('alias' => 'site'));
     $rr = $aro->findByAlias('users');
     $rc = $aco->findByAlias('site');
     print_r($rr);
     $this->Acl->grant(array('Aro' => array('alias' => 'users')), array('Aco' => array('alias' => 'site')), '*');
     //$this->Acl->grant(2, 1);
     //$this->Acl->grant(array('alias' => 'admins'), array('alias' => 'admin'));
     $this->set('json', 'a');
 }