Exemple #1
0
 protected function controllerRules($controller, $module = null)
 {
     $accessArray = array();
     $controller_model = Controllers::model()->find("controller_name like '{$controller}' and module_name like '{$module}'");
     //var_dump($controller_model);
     if (!$controller_model) {
         echo 'denied';
         return array(array('deny'));
     }
     //user roles
     //        $actions_user = ActionsUsers::model()->findAll(array('condition' => "controller_id = $controller_model->id  and can_access like 'allow'",
     //                                                     'order' => 'controller_id desc'));
     // ANH DUNG CLOSE JAN 29, 2015
     // ANH DUNG ADD JAN 29, 2015
     $criteria = new CDbCriteria();
     $criteria->compare("t.controller_id", $controller_model->id);
     $criteria->compare("t.user_id", Yii::app()->user->id);
     $criteria->compare("t.can_access", "allow", true);
     $criteria->order = "t.controller_id desc";
     $actions_user = ActionsUsers::model()->findAll($criteria);
     // ANH DUNG ADD JAN 29, 2015
     //        if($actions_user)
     //        {
     foreach ($actions_user as $key => $user_action) {
         if ($user_action->user) {
             $array_action = array_map('trim', explode(",", trim($user_action->actions)));
             $accessArray[] = array($user_action->can_access, 'actions' => $array_action, 'users' => array($user_action->user->username));
         } else {
             $user_action->delete();
         }
         // delete data not valid
     }
     //        }
     //menu roles ANH DUNG FIX Oct 07, 2014
     $criteria = new CDbCriteria();
     $criteria->compare('controller_id', $controller_model->id);
     $criteria->compare('can_access', 'allow');
     $criteria->compare('roles_id', Yii::app()->user->role_id);
     $actions_role = ActionsRoles::model()->findAll($criteria);
     //        $actions_role = ActionsRoles::model()->findAll(array('condition' => "controller_id = $controller_model->id  and can_access LIKE 'allow'",
     //                                                                                                                'order' => 'controller_id desc'));
     //      //menu roles ANH DUNG FIX Oct 07, 2014
     if ($actions_role) {
         foreach ($actions_role as $key => $action_role) {
             $array_action = array_map('trim', explode(",", trim($action_role->actions)));
             $accessArray[] = array('allow', 'actions' => $array_action, 'users' => array('@'));
         }
     }
     //        $accessArray[] = array('deny'); // ANH DUNG CLOSE JAN 29, 2015
     $accessArray[] = array('deny', 'users' => array('*'));
     // ANH DUNG ADD JAN 29, 2015
     return $accessArray;
 }
Exemple #2
0
 public function showMenu()
 {
     if (Yii::app()->session['LOGGED_USER'] != null) {
         $userObj = new Users();
         $userObj = Yii::app()->session['LOGGED_USER'];
         $value = '';
         $userRoleId = $userObj->role_id;
         $appicationId = Roles::getAppicationIdByRoleId($userRoleId);
         if ($appicationId != BE) {
             Yii::app()->user->logout();
             Yii::app()->controller->redirect(Yii::app()->createAbsoluteUrl('admin/site/login'));
         }
         $userRoleMenu = RolesMenus::model()->findAll(array('condition' => 'role_id=' . $userRoleId));
         $userRoleMenuId = array();
         if ($userRoleMenu) {
             foreach ($userRoleMenu as $u) {
                 $userRoleMenuId[] = $u->menu_id;
             }
         }
         $menusTemp = Menus::model()->findAll(array('condition' => 'show_in_menu="1"', 'order' => 'display_order asc'));
         // MAY 12, 2014 ANH DUNG ADD
         $menus = array();
         foreach ($menusTemp as $menuTemp) {
             if ($menuTemp->menu_link == '') {
                 $menus[] = $menuTemp;
                 continue;
             }
             $aLinks = explode('/', $menuTemp->menu_link);
             $c = '';
             // controller name
             $a = '';
             // action name
             if (count($aLinks) == 2) {
                 $c = $aLinks[1];
                 $a = 'Index';
             } elseif (count($aLinks) == 3) {
                 $c = $aLinks[1];
                 $a = ucfirst($aLinks[2]);
             }
             $aActionAllowed = ActionsUsers::getActionArrayAllowForCurrentUserByControllerName($c);
             $aActionAllowed = array_map('strtolower', $aActionAllowed);
             $aActionAllowed = array_map('trim', $aActionAllowed);
             // Now 14, 2014 ANH DUNG ADD
             if (in_array(strtolower($a), $aActionAllowed)) {
                 $menus[] = $menuTemp;
             }
         }
         // MAY 12, 2014 ANH DUNG ADD
         $this->str = "<ul class='nav'>";
         $this->str .= "<li class='nav_li'><a href='" . Yii::app()->createAbsoluteUrl('/admin') . "'>Home</a></li>";
         if ($menus != NULL) {
             $this->findchild(0, $menus, $value, $userRoleMenuId);
         }
         $this->str .= "</ul>";
         if (Yii::app()->user->id) {
             if (isset(Yii::app()->user->application_id) && Yii::app()->user->application_id == BE) {
                 return $this->str;
             } else {
                 return '';
             }
         } else {
             return '';
         }
     }
     return '';
 }
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = ActionsUsers::model()->findByPk($id);
     if ($model === null) {
         Yii::log("The requested page does not exist.");
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Exemple #4
0
     if ($d1 > $d2) {
         return true;
     }
     return false;
 }
 /**  ANH DUNG Apr 24, 2014
 *  @to do: format number
 /**
  * @Author: ANH DUNG Dec 19, 2014
  * @Todo: reset all custom role of one user
  */
 public function actionResetRoleCustomOfUser($id)
 {
     $criteria = new CDbCriteria();
     $criteria->compare('user_id', $id);
     ActionsUsers::model()->deleteAll($criteria);
     $this->redirect(array('user', 'id' => $id));
 }
Exemple #6
0
</div>
<div id="accordion">
    <?php 
foreach ($this->aControllers as $keyController => $aController) {
    ?>
    
    <div class="block_privilege">
        <h3><a class="l_margin_20 item_b" href="#"><?php 
    echo $aController['alias'];
    ?>
</a></h3>
        <?php 
    $mController = Controllers::getByName($keyController);
    $aActionsAllowGroup = ActionsRoles::getActionArrayByRoleIdAndControllerId($mUser->role_id, $mController->id);
    $aActionsAllowUser = ActionsUsers::getActionArrayByUserIdAndControllerId($id, $mController->id);
    $mActionsUsers = ActionsUsers::model()->findAll('user_id=' . $id . ' AND controller_id=' . $mController->id);
    ?>
        <div class="wrap_privilege">
            <!--<h2><?php 
    echo $aController['alias'];
    ?>
</h2>-->
            <a href="javascript:void(0)" class="checkAll item_b">Select All</a> | <a href="javascript:void(0)" class="clearAll item_b">Deselect All</a><br><br>
            <ul class="permission-list">
                <?php 
    foreach ($aController['actions'] as $keyAction => $aAction) {
        ?>
                <?php 
        $classCheck = '';
        ?>
                <li><input type="checkbox" name="<?php 
Exemple #7
0
 public static function canAccess($action, $controller_id, $class)
 {
     try {
         $roles = Yii::app()->session['roles'];
         $obj = new $class();
         if ($class == 'ActionsRoles') {
             $actions = ActionsRoles::model()->findAll('controller_id = ' . $controller_id . ' and roles_id = ' . $roles);
         } else {
             $user_id = Users::model()->find("username like '{$roles}'")->id;
             $actions = ActionsUsers::model()->findAll('controller_id = ' . $controller_id . ' and user_id = ' . $user_id);
         }
         foreach ($actions as $key => $model) {
             $array_action = array_map('trim', explode(",", trim($model->actions)));
             foreach ($array_action as $key2 => $value) {
                 if (strtolower($value) == strtolower($action)) {
                     return $model->can_access;
                 }
             }
         }
         return 'allow';
     } catch (Exception $e) {
         Yii::log("Exception " . print_r($e, true), 'error');
         throw new CHttpException("Exception " . print_r($e, true));
     }
 }
Exemple #8
0
 public static function isAllowAccess($controllerName, $actionName)
 {
     $aActionAllowed = ActionsUsers::getActionArrayAllowForCurrentUserByControllerName($controllerName);
     if (in_array(ucfirst($actionName), $aActionAllowed)) {
         return true;
     }
     return false;
 }