Skip to content

Instantly share code, notes, and snippets.

@gimox
Last active August 29, 2015 14:00
Show Gist options
  • Save gimox/11042750 to your computer and use it in GitHub Desktop.
Save gimox/11042750 to your computer and use it in GitHub Desktop.
this is my console auth file
<?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