Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
token
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wallet
token
Commits
577be8df
Commit
577be8df
authored
Aug 07, 2018
by
rlgy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
30517063
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
87 deletions
+48
-87
AdminController.php
backend/controllers/AdminController.php
+34
-57
auth.php
backend/views/admin/auth.php
+5
-20
DbManager.php
common/core/rbac/DbManager.php
+9
-10
No files found.
backend/controllers/AdminController.php
View file @
577be8df
...
...
@@ -76,62 +76,39 @@ class AdminController extends BaseController
* 用户授权
* ---------------------------------------
*/
// public function actionAuth()
// {
// /* 获取用户信息 */
// $uid = Yii::$app->request->get('uid');
// if (!is_numeric($uid) || !($model = Admin::findOne($uid)) ) {
// $this->error('操作对象不合法');
// }
//
// $auth = Yii::$app->authManager;
// if (Yii::$app->request->isPost) {
// $data = Yii::$app->request->post();
//
// //更新Fxee权限
// try {
// $ret = FxeeBusiness::updateMemberGroup($uid,isset($data['param_fxee']) ? $data['param_fxee'] : null);
// } catch (Exception $e) {
// $ret = $e->getMessage();
// }
//
// /* 用户权限组 */
// $item_name = $data['param'];
//
// /* 先删除 用户组-用户 记录 */
// $auth->revokeAll($uid);
// /* 再添加记录 */
// $role = $auth->getRole($item_name);
// $auth->assign($role, $uid);
//
// //fxee用户权限操作
//
// if ($ret == true) {
// $this->success('授权成功!', $this->getForward());
// } else if (is_string($ret)) {
// $this->error($ret);
// }
// exit;
// }
//
// $roles = $auth->getRoles();
// $group = array_keys($auth->getAssignments($uid));
//
// $one = Admin::findOne(['uid' => $uid]);
// if (isset($one['bind_uid']) && is_numeric($one['bind_uid'])) {
// $fxeeRoles = Member::getRoles();
// $fxeeGroup = Member::find()->select('group')->where(['id' => $one['bind_uid']])->scalar();
// } else {
// $fxeeRoles = $fxeeGroup = null;
// }
//
// return $this->render('auth', [
// 'model' => $model,
// 'roles' => $roles,
// 'group' => $group,
// 'fxee_roles' => $fxeeRoles,
// 'fxee_group' => $fxeeGroup,
// ]);
// }
public
function
actionAuth
()
{
/* 获取用户信息 */
$uid
=
Yii
::
$app
->
request
->
get
(
'uid'
);
if
(
!
is_numeric
(
$uid
)
||
!
(
$model
=
Admin
::
findOne
(
$uid
)))
{
$this
->
error
(
'操作对象不合法'
);
}
$auth
=
Yii
::
$app
->
authManager
;
if
(
Yii
::
$app
->
request
->
isPost
)
{
$data
=
Yii
::
$app
->
request
->
post
();
/* 用户权限组 */
$item_name
=
$data
[
'param'
];
/* 先删除 用户组-用户 记录 */
$auth
->
revokeAll
(
$uid
);
/* 再添加记录 */
$role
=
$auth
->
getRole
(
$item_name
);
$auth
->
assign
(
$role
,
$uid
);
$this
->
success
(
'授权成功!'
,
$this
->
getForward
());
}
$roles
=
$auth
->
getRoles
();
$group
=
array_keys
(
$auth
->
getAssignments
(
$uid
));
return
$this
->
render
(
'auth'
,
[
'model'
=>
$model
,
'roles'
=>
$roles
,
'group'
=>
$group
,
]);
}
}
backend/views/admin/auth.php
View file @
577be8df
...
...
@@ -22,7 +22,7 @@ use common\core\ActiveForm;
<div
class=
"portlet light bordered"
>
<div
class=
"portlet-body form"
>
<!-- BEGIN FORM-->
<form
action=
"
<?=
\yii\helpers\Url
::
toRoute
([
'auth'
,
'uid'
=>
$model
->
uid
])
?>
"
method=
"post"
class=
"form-aaa "
>
<form
action=
"
<?=
\yii\helpers\Url
::
toRoute
([
'auth'
,
'uid'
=>
$model
->
uid
])
?>
"
method=
"post"
class=
"form-aaa "
>
<input
name=
"_csrf"
type=
"hidden"
id=
"_csrf"
value=
"
<?=
Yii
::
$app
->
request
->
csrfToken
?>
"
>
<div
class=
"form-group"
>
...
...
@@ -30,31 +30,16 @@ use common\core\ActiveForm;
<div
class=
"mt-radio-list"
>
<?php
if
(
$roles
)
foreach
(
$roles
as
$role
)
:
?>
<label
class=
"mt-radio mt-radio-outline"
>
<input
type=
"radio"
name=
"param"
value=
"
<?=
$role
->
name
?>
"
<?php
echo
in_array
(
$role
->
name
,
$group
)
?
'checked'
:
''
;
?>
/>
<input
type=
"radio"
name=
"param"
value=
"
<?=
$role
->
name
?>
"
<?php
echo
in_array
(
$role
->
name
,
$group
)
?
'checked'
:
''
;
?>
/>
<span></span>
<?=
$role
->
name
?>
(
<?=
$role
->
description
?>
)
<?=
$role
->
name
?>
(
<?=
$role
->
description
?>
)
</label>
<?php
endforeach
?>
</div>
<?=
$fxee_roles
?
'<hr>fxee角色<label style="color: #858423">【操作】</label>'
:
''
?>
<div
class=
"mt-radio-list"
>
<?php
if
(
$fxee_roles
)
foreach
(
$fxee_roles
as
$k
=>
$v
)
:
?>
<label
class=
"mt-radio mt-radio-outline"
>
<input
type=
"radio"
name=
"param_fxee"
value=
"
<?=
$k
?>
"
<?php
echo
$k
==
$fxee_group
?
'checked'
:
''
;
?>
/>
<span></span>
<?=
$k
?>
(
<?=
$v
?>
)
</label>
<?php
endforeach
?>
</div>
</div>
<div
class=
"form-actions"
>
<?=
Html
::
submitButton
(
'确定'
,
[
'class'
=>
'btn blue ajax-post'
,
'target-form'
=>
'form-aaa'
])
?>
<?=
Html
::
button
(
'返回'
,
[
'class'
=>
'btn '
,
'onclick'
=>
"javascript:history.go(-1);"
])
?>
<?=
Html
::
submitButton
(
'确定'
,
[
'class'
=>
'btn blue ajax-post'
,
'target-form'
=>
'form-aaa'
])
?>
<?=
Html
::
button
(
'返回'
,
[
'class'
=>
'btn '
,
'onclick'
=>
"javascript:history.go(-1);"
])
?>
</div>
</form>
<!-- END FORM-->
...
...
common/core/rbac/DbManager.php
View file @
577be8df
<?php
namespace
common\core\rbac
;
use
yii\rbac\Item
;
...
...
@@ -16,7 +17,8 @@ class DbManager extends \yii\rbac\DbManager
* @param object $rule 规则对象
* ---------------------------------------
*/
public
function
saveRule
(
$name
)
{
public
function
saveRule
(
$name
)
{
/* 判断auth_rule表是否存在 */
if
(
$rule
=
$this
->
getRule
(
$name
))
{
/* 更新 */
...
...
@@ -49,7 +51,8 @@ class DbManager extends \yii\rbac\DbManager
* @param string $child 权限name
* ---------------------------------------
*/
public
function
saveChild
(
$parent
,
$child
){
public
function
saveChild
(
$parent
,
$child
)
{
/* 判断auth_item_child表是否存在 */
$parent
=
$this
->
getRole
(
$parent
);
$child
=
$this
->
getItem
(
$child
);
...
...
@@ -62,18 +65,16 @@ class DbManager extends \yii\rbac\DbManager
/**
* ---------------------------------------
* 更新auth_item
* @throws \Exception
* ---------------------------------------
*/
protected
function
updateRule
(
$name
,
$rule
)
{
if
(
$rule
->
name
!==
$name
&&
!
$this
->
supportsCascadeUpdate
())
{
$this
->
db
->
createCommand
()
->
update
(
$this
->
itemTable
,
[
$this
->
db
->
createCommand
()
->
update
(
$this
->
itemTable
,
[
'rule_name'
=>
$rule
->
name
,
'name'
=>
$rule
->
name
,
],
[
'rule_name'
=>
$name
])
->
execute
();
],
[
'rule_name'
=>
$name
])
->
execute
();
}
$rule
->
updatedAt
=
time
();
...
...
@@ -83,9 +84,7 @@ class DbManager extends \yii\rbac\DbManager
'name'
=>
$rule
->
name
,
'data'
=>
serialize
(
$rule
),
'updated_at'
=>
$rule
->
updatedAt
,
],
[
'name'
=>
$name
,
])
->
execute
();
],
[
'name'
=>
$name
,])
->
execute
();
$this
->
invalidateCache
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment