Showing
1 changed file
with
40 additions
and
1 deletions
@@ -12,7 +12,7 @@ class InitController extends Controller | @@ -12,7 +12,7 @@ class InitController extends Controller | ||
12 | { | 12 | { |
13 | 13 | ||
14 | /** | 14 | /** |
15 | - * Create init user | 15 | + * 创建/修改后台用户 |
16 | */ | 16 | */ |
17 | public function actionAdmin() | 17 | public function actionAdmin() |
18 | { | 18 | { |
@@ -80,4 +80,43 @@ class InitController extends Controller | @@ -80,4 +80,43 @@ class InitController extends Controller | ||
80 | public function actionTest(){ | 80 | public function actionTest(){ |
81 | echo "init/test"; | 81 | echo "init/test"; |
82 | } | 82 | } |
83 | + | ||
84 | + /** | ||
85 | + * 创建/移除后台权限标签(controller/action) | ||
86 | + */ | ||
87 | + public function actionRbac(){ | ||
88 | + | ||
89 | + $this->stdout("1: Create rbac permission\n2: Delete rbac permission\n"); | ||
90 | + $action = $this->prompt('Which:'); | ||
91 | + | ||
92 | + $auth = Yii::$app->authManager; | ||
93 | + if ($action == 1){ | ||
94 | + echo "创建一个新权限标签 ...\n"; // 提示当前操作 | ||
95 | + $name = $this->prompt('Permission Name:'); // 权限名称 | ||
96 | + $description = $this->prompt('Description(default is as name):'); // 描述 | ||
97 | + | ||
98 | + if ($name){ | ||
99 | + $permission = $auth->createPermission($name); | ||
100 | + $permission->description = $description ? : ucwords(strtr($name,array('/'=>' '))); | ||
101 | + $r = $auth->add($permission); | ||
102 | + } | ||
103 | + }elseif ($action == 2){ | ||
104 | + echo "移除一个权限标签 ...\n"; // 提示当前操作 | ||
105 | + $name = $this->prompt('Permission Name:'); // 权限名称 | ||
106 | + | ||
107 | + if ($name){ | ||
108 | + if (!$permission = $auth->getPermission($name)){ | ||
109 | + $this->stderr('Not a predefined permission'); | ||
110 | + return 1; | ||
111 | + } | ||
112 | + $r = $auth->remove($permission); | ||
113 | + } | ||
114 | + }else{ | ||
115 | + $this->stderr('Not a predefined option'); | ||
116 | + return 1; | ||
117 | + } | ||
118 | + | ||
119 | + var_dump($r); | ||
120 | + return 0; | ||
121 | + } | ||
83 | } | 122 | } |
-
Please register or login to post a comment