Exemplo n.º 1
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;
     } else {
         $new_aro['parent_id'] = NULL;
     }
     $aro->save($new_aro);
     $user['id'] = $uid;
     $user['active'] = $active;
     $this->User->save($user);
 }
 function activateAccount()
 {
     $this->autoLayout = false;
     $this->autoRender = false;
     if (empty($this->params['url']['key'])) {
         $this->redirect(array('controller' => 'home', 'action' => 'index'), null, true);
     }
     $key = $this->params['url']['key'];
     $data = $this->Pending->findByKey($key);
     if ($data) {
         $uid = $data['Pending']['user_id'];
         $user = $this->User->findById($uid);
         if ($user) {
             $user['User']['pending'] = 'no';
             $user['User']['secret'] = $this->User->mksecret();
             $user['User']['passkey'] = sha1($user['User']['username'] . mktime() . $user['User']['username']);
             $user['User']['group_id'] = 3;
             $this->User->save($user);
             $this->Pending->remove($data['Pending']['id']);
             $aro = new Aro();
             $arodata = $aro->findByForeign_key($uid);
             $newgroup = $aro->find('model LIKE "Group" AND foreign_key = 3');
             $arodata['Aro']['parent_id'] = $newgroup['Aro']['id'];
             $aro->save($arodata);
             $this->ZTAuth->fields = array('username' => 'username', 'password' => 'sha_hash');
             if ($this->ZTAuth->login($user['User'])) {
                 $this->redirect(array('controller' => 'home', 'action' => 'index'), null, true);
             }
         }
     }
 }
 function edit($id = null)
 {
     $this->set("modul", "page");
     $back['title'] = 'Back to Group List';
     $back['url'] = '/groups/index';
     $this->set("back", $back);
     if (!$id && empty($this->data)) {
         $this->Session->setFlash(__('Invalid Group', true));
         $this->redirect(array('action' => 'index'));
     }
     if (!empty($this->data)) {
         if ($this->Group->save($this->data)) {
             $aro = new Aro();
             $group = $aro->find(array("model" => "Group", "foreign_key" => $this->data['Group']['id']));
             $group['Aro']['alias'] = $this->data['Group']['name'];
             $aro->save($group);
             $this->Session->setFlash(__('The Group has been saved', true));
             $this->redirect(array('action' => 'index'));
         } else {
             $this->Session->setFlash(__('The Group could not be saved. Please, try again.', true));
         }
     }
     if (empty($this->data)) {
         $this->data = $this->Group->read(null, $id);
     }
 }
Exemplo n.º 4
0
 function permissions($id)
 {
     // primero actualiza los permisos
     $this->update_acos();
     // importando las clases
     App::import('Model', 'UserGroup');
     App::import('Model', 'Aro');
     App::import('Model', 'ArosAco');
     // consulta todos los acos
     $aco = new Aco();
     $this->set('acos', $aco->find('threaded', array('recursive' => 0)));
     // consulta el id del aro
     $aro = new Aro();
     $aro_row = $aro->find('first', array('conditions' => array('model' => 'UserGroup', 'foreign_key' => $id)));
     $this->UserGroup = new UserGroup();
     $this->set('userGroup', $this->UserGroup->read(null, $id));
     $this->set('aro_foreignkey', $id);
     if (!empty($this->data)) {
         // guarda los permisos
         $group =& $this->UserGroup;
         $group->id = $id;
         $aro_aco_del = new ArosAco();
         foreach ($this->data['Acos'] as $aco_id => $mode) {
             switch ($mode['option']) {
                 case 1:
                     // allow
                     $this->Acl->allow($group, $mode['url']);
                     break;
                 case 2:
                     // deny
                     $this->Acl->deny($group, $mode['url']);
                     break;
                 default:
                     // lo borra
                     $aro_aco_del->deleteAll(array('aro_id' => $aro_row['Aro']['id'], 'aco_id' => $aco_id));
                     break;
             }
         }
         $this->Session->setFlash(__('UserGroup permissions changed successfully', true));
         $this->redirect(array('action' => 'index'));
     }
     // consulta la relacion de aros_acos
     $aros_aco = new ArosAco();
     $this->set('aros_acos', $aros_aco->find('all', array('conditions' => array('aro_id' => $aro_row['Aro']['id']))));
 }
 /**
  * Test After Delete
  *
  * @return void
  * @access public
  */
 function testAfterDelete()
 {
     $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);
     $id = $Person->id;
     $node = $Person->node();
     $this->assertEqual(count($node), 2);
     $this->assertEqual($node[0]['Aro']['parent_id'], 5);
     $this->assertEqual($node[1]['Aro']['parent_id'], null);
     $Person->delete($id);
     $result = $this->Aro->find('first', array('conditions' => array('Aro.model' => 'AclPerson', 'Aro.foreign_key' => $id)));
     $this->assertTrue(empty($result));
     $result = $this->Aro->find('first', array('conditions' => array('Aro.model' => 'AclPerson', 'Aro.foreign_key' => 2)));
     $this->assertFalse(empty($result));
     $data = array('AclPerson' => array('name' => 'Trent', 'mother_id' => 2, 'father_id' => 3));
     $Person->save($data);
     $id = $Person->id;
     $Person->delete(2);
     $result = $this->Aro->find('first', array('conditions' => array('Aro.model' => 'AclPerson', 'Aro.foreign_key' => $id)));
     $this->assertTrue(empty($result));
     $result = $this->Aro->find('first', array('conditions' => array('Aro.model' => 'AclPerson', 'Aro.foreign_key' => 2)));
     $this->assertTrue(empty($result));
 }
 /**
  * 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"}');
     }
 }
Exemplo n.º 7
0
 /**
  * Get an array of access-control links between the given Aro and Aco
  *
  * @param mixed $aro
  * @param mixed $aco
  * @return array
  * @access public
  */
 function getAclLink($aro, $aco)
 {
     $Aro = new Aro();
     $Aco = new Aco();
     $Link = new ArosAco();
     $obj = array();
     $obj['Aro'] = $Aro->find($Aro->_resolveID($aro));
     $obj['Aco'] = $Aco->find($Aco->_resolveID($aco));
     $obj['Aro'] = $obj['Aro']['Aro'];
     $obj['Aco'] = $obj['Aco']['Aco'];
     if ($obj['Aro'] == null || count($obj['Aro']) == 0 || $obj['Aco'] == null || count($obj['Aco']) == 0) {
         return false;
     }
     return array('aro' => $obj['Aro']['id'], 'aco' => $obj['Aco']['id'], 'link' => $Link->findAll(array('ArosAco.aro_id' => $obj['Aro']['id'], 'ArosAco.aco_id' => $obj['Aco']['id'])));
 }
Exemplo n.º 8
0
 function beforeFilter()
 {
     $this->Auth->loginRedirect = '/';
     // for the authorizations
     $this->Auth->authorize = 'actions';
     $this->Auth->actionPath = 'controllers/';
     // if the user is not logged and it requests the root '/' url
     // redirects to '/login'
     if (!$this->Session->read('Auth.User.id')) {
         if ($this->params['url']['url'] == '/') {
             $this->redirect('/login');
         }
     }
     App::import('Model', 'User');
     if ($this->Session->read('Auth.User.id')) {
         if ($this->params['url']['url'] == '/') {
             $user = new User();
             $user = $user->read(null, $this->Session->read('Auth.User.id'));
             $this->redirect($user['UserGroup']['home_url']);
         }
     }
     if ($this->layout == 'default' && $this->Session->read('Auth.User.id')) {
         // creating an array with all the permissions for this user
         // and in the view we check if it has permissions to show the link
         // getting all the acos with permissions
         App::import('Model', 'Aco');
         App::import('Model', 'Aro');
         App::import('Model', 'ArosAco');
         $aco = new Aco();
         $aro = new Aro();
         $aros_aco = new ArosAco();
         $acos = $aco->find('threaded', array('recursive' => 0));
         // consulta el id del aro
         $aro_row = $aro->find('first', array('conditions' => array('model' => 'UserGroup', 'foreign_key' => $this->Session->read('Auth.User.user_group_id'))));
         // consulta la relacion de aros_acos
         $aros_acos = $aros_aco->find('all', array('conditions' => array('aro_id' => $aro_row['Aro']['id'])));
         $this->set('acl_lists', $this->AclGetList->get($this->Session->read('Auth.User.user_group_id'), $acos, $aros_acos));
     }
     // rendering the menu for "default" layout
     // checking if there is a logged user
     if ($this->layout == 'default' && $this->Session->read('Auth.User.id')) {
         // renders the menu according the user group
         App::import('Model', 'Menu');
         $menu = new Menu();
         $this->set('layout_menus', $menu->find_for_show($this->Session->read('Auth.User.user_group_id')));
         // selecting the current menu
         $this->set('layout_current', $this->params['url']['url']);
         //$route = Router::parse('/'.$this->params['url']['url']);
         //$aco_alias = 'controllers/'.$route['controller'].'/'.$route['action'];
         //$this->set('layout_acos', $this->Acl->Aco->node('controllers/'.$route['controller'].'/'.$route['action']));
         // asks the controller for selecting the correct link in the menu
         $cont = split('_', $this->params['controller']);
         $newcont = '';
         foreach ($cont as $c) {
             $newcont .= ucfirst($c);
         }
         $current_aco = $this->Acl->Aco->node('controllers/' . $newcont . '/' . $this->params['action']);
         $this->set('layout_aco_id', $current_aco[0]['Aco']['id']);
         //$route = Router::parse('/profile');
         //$this->set('menu_url', '/'.$this->params['controller'].'/'.$this->params['action']);
         if ($this->Session->read('Auth.User.type') == 'web') {
             $user = new User();
             $user->id = $this->Session->read('Auth.User.id');
             $user->updatecredit_expiration();
             $this->set('user_balance', $user->getBalance());
             $this->set('user_expirationdate', $user->getExpirationDate());
         }
     }
 }
Exemplo n.º 9
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);
     }
 }