Last active
August 29, 2015 14:00
-
-
Save gimox/11042750 to your computer and use it in GitHub Desktop.
this is my console auth file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace console\controllers; | |
use frontend\rbac\UserGroupRule; | |
class AuthController extends \yii\console\Controller | |
{ | |
public function actionCreateauth() { | |
$rule = new UserGroupRule; | |
$auth = \Yii::$app->authManager; | |
$auth->add($rule); | |
$viewAgenziaOwn = $auth->createPermission('viewAgenziaOwn'); | |
$auth->add($viewAgenziaOwn); | |
$manageOperators = $auth->createPermission('manageOperators'); | |
$auth->add($manageOperators); | |
//------------------------ AUTH CODE -------------------------- | |
echo "Start Creating Authorization structure\n"; | |
echo "\n"; | |
//------------- OPERATORS ------------------------/ | |
echo "\nOPERATORS AUTH\n"; | |
echo " - creating Role: operators\n"; | |
$operators = $auth->createRole('operators'); | |
$operators->ruleName = $rule->name; | |
$auth->add($operators); | |
$auth->addChild($operators, $manageOperators); | |
echo " - creating Role: agencyManager\n"; | |
$agencyManager = $auth->createRole('agencyManager'); | |
$agencyManager->ruleName = $rule->name; | |
$auth->add($agencyManager); | |
$auth->addChild($agencyManager, $viewAgenziaOwn); | |
$auth->addChild($agencyManager, $operators); | |
echo "\nAuthorization Rule completed\n"; | |
} | |
public function actionRemoveall() { | |
echo "Start Removing ALL authorization"; | |
echo "\n"; | |
$auth = \Yii::$app->authManager; | |
$auth->removeAll(); | |
echo "done\n"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment