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
3a6a6435
Commit
3a6a6435
authored
Aug 07, 2018
by
rlgy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
577be8df
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
107 additions
and
92 deletions
+107
-92
AdminController.php
backend/controllers/AdminController.php
+8
-3
AuthController.php
backend/controllers/AuthController.php
+41
-36
_form.php
backend/views/admin/_form.php
+1
-0
add.php
backend/views/admin/add.php
+1
-0
edit.php
backend/views/admin/edit.php
+2
-0
add.php
backend/views/auth/add.php
+4
-5
user.php
backend/views/auth/user.php
+50
-48
No files found.
backend/controllers/AdminController.php
View file @
3a6a6435
...
...
@@ -49,6 +49,7 @@ class AdminController extends BaseController
$data
[
'last_login_time'
]
=
0
;
$data
[
'last_login_ip'
]
=
ip2long
(
'127.0.0.1'
);
$data
[
'update_time'
]
=
0
;
$role
=
Yii
::
$app
->
request
->
post
(
'role'
,
'administrator'
);
/* 表单数据加载和验证,具体验证规则在模型rule中配置 */
/* 密码单独验证,否则setPassword后密码肯定符合rule */
if
(
empty
(
$data
[
'password'
])
||
strlen
(
$data
[
'password'
])
<
6
)
{
...
...
@@ -60,6 +61,9 @@ class AdminController extends BaseController
$model
->
setPassword
(
$data
[
'password'
]);
/* 保存用户数据到数据库 */
if
(
$model
->
save
())
{
$auth
=
Yii
::
$app
->
authManager
;
$role
=
$auth
->
getRole
(
$role
);
$auth
->
assign
(
$role
,
$model
->
uid
);
$this
->
success
(
'操作成功'
,
$this
->
getForward
());
}
else
{
$this
->
error
(
'操作错误'
);
...
...
@@ -68,6 +72,7 @@ class AdminController extends BaseController
return
$this
->
render
(
'add'
,
[
'model'
=>
$model
,
'role'
=>
Yii
::
$app
->
request
->
get
(
'role'
,
'administrator'
)
]);
}
...
...
@@ -105,9 +110,9 @@ class AdminController extends BaseController
$group
=
array_keys
(
$auth
->
getAssignments
(
$uid
));
return
$this
->
render
(
'auth'
,
[
'model'
=>
$model
,
'roles'
=>
$roles
,
'group'
=>
$group
,
'model'
=>
$model
,
'roles'
=>
$roles
,
'group'
=>
$group
,
]);
}
...
...
backend/controllers/AuthController.php
View file @
3a6a6435
...
...
@@ -61,23 +61,25 @@ class AuthController extends BaseController
public
function
actionAdd
()
{
if
(
Yii
::
$app
->
request
->
isPost
)
{
$data
=
Yii
::
$app
->
request
->
post
(
'param'
);
$data
[
'name'
]
=
trim
(
$data
[
'name'
]);
$data
=
Yii
::
$app
->
request
->
post
(
'param'
);
$data
[
'name'
]
=
trim
(
$data
[
'name'
]);
if
(
!
$data
[
'name'
])
{
$this
->
error
(
'请输入要添加的角色名!'
);
}
else
if
(
Yii
::
$app
->
authManager
->
getRole
(
$data
[
'name'
])
!=
null
)
{
$this
->
error
(
'该角色名已存在!'
);
}
else
{
/* 创建角色 */
$role
=
Yii
::
$app
->
authManager
->
createRole
(
$data
[
'name'
]);
$role
->
type
=
1
;
$role
->
description
=
$data
[
'description'
];
if
(
Yii
::
$app
->
authManager
->
add
(
$role
))
{
$this
->
success
(
'添加成功!'
,
$this
->
getForward
());
}
$this
->
error
(
'添加失败!'
);
}
$this
->
error
(
'请输入要添加的角色名!'
);
}
else
{
if
(
Yii
::
$app
->
authManager
->
getRole
(
$data
[
'name'
])
!=
null
)
{
$this
->
error
(
'该角色名已存在!'
);
}
else
{
/* 创建角色 */
$role
=
Yii
::
$app
->
authManager
->
createRole
(
$data
[
'name'
]);
$role
->
type
=
1
;
$role
->
description
=
$data
[
'description'
];
if
(
Yii
::
$app
->
authManager
->
add
(
$role
))
{
$this
->
success
(
'添加成功!'
,
$this
->
getForward
());
}
$this
->
error
(
'添加失败!'
);
}
}
}
return
$this
->
render
(
'add'
);
}
...
...
@@ -91,30 +93,32 @@ class AuthController extends BaseController
*/
public
function
actionEdit
()
{
/* 获取角色信息 */
/* 获取角色信息 */
$item_name
=
trim
(
Yii
::
$app
->
request
->
get
(
'role'
));
$role
=
Yii
::
$app
->
authManager
->
getRole
(
$item_name
);
if
(
Yii
::
$app
->
request
->
isPost
)
{
$data
=
Yii
::
$app
->
request
->
post
(
'param'
);
$data
[
'name'
]
=
trim
(
$data
[
'name'
]);
$data
=
Yii
::
$app
->
request
->
post
(
'param'
);
$data
[
'name'
]
=
trim
(
$data
[
'name'
]);
if
(
!
$data
[
'name'
])
{
$this
->
success
(
'请输入要更新的角色名!'
);
}
else
if
(
Yii
::
$app
->
authManager
->
getRole
(
$data
[
'name'
])
!=
null
)
{
$this
->
error
(
'该角色名已存在!'
);
}
else
{
$role
->
name
=
$data
[
'name'
];
$role
->
description
=
$data
[
'description'
];
if
(
Yii
::
$app
->
authManager
->
update
(
$item_name
,
$role
))
{
$this
->
success
(
'更新成功!'
,
$this
->
getForward
());
}
$this
->
error
(
'更新失败!'
);
}
if
(
!
$data
[
'name'
])
{
$this
->
success
(
'请输入要更新的角色名!'
);
}
else
{
if
(
Yii
::
$app
->
authManager
->
getRole
(
$data
[
'name'
])
!=
null
)
{
$this
->
error
(
'该角色名已存在!'
);
}
else
{
$role
->
name
=
$data
[
'name'
];
$role
->
description
=
$data
[
'description'
];
if
(
Yii
::
$app
->
authManager
->
update
(
$item_name
,
$role
))
{
$this
->
success
(
'更新成功!'
,
$this
->
getForward
());
}
$this
->
error
(
'更新失败!'
);
}
}
}
}
return
$this
->
render
(
'edit'
,
[
'role'
=>
$role
,
...
...
@@ -167,14 +171,14 @@ class AuthController extends BaseController
}
/* 获取栏目节点 */
$node_list
=
Menu
::
returnNodes
();
$node_list
=
Menu
::
returnNodes
();
$auth_rules
=
Yii
::
$app
->
authManager
->
getChildren
(
$role
);
$auth_rules
=
array_keys
(
$auth_rules
);
//var_dump($auth_rules);exit;
return
$this
->
render
(
'auth'
,
[
'node_list'
=>
$node_list
,
'node_list'
=>
$node_list
,
'auth_rules'
=>
$auth_rules
,
'role'
=>
$role
,
'role'
=>
$role
,
]);
}
...
...
@@ -200,6 +204,7 @@ class AuthController extends BaseController
return
$this
->
render
(
'user'
,
[
'dataProvider'
=>
$this
->
lists1
(
new
Admin
(),
$_where
),
'role'
=>
Yii
::
$app
->
request
->
get
(
'role'
,
'administrator'
),
]);
}
...
...
backend/views/admin/_form.php
View file @
3a6a6435
...
...
@@ -38,6 +38,7 @@ use common\core\ActiveForm;
'placeholder'
=>
'修改时,密码不变可不填'
])
->
label
(
false
)
?>
<input
type=
"hidden"
value=
"
<?=
$role
?>
"
name=
"role"
>
<?=
$form
->
field
(
$model
,
'status'
)
->
radioList
([
'1'
=>
'正常'
,
'0'
=>
'禁用'
])
->
label
(
'使用状态'
)
?>
...
...
backend/views/admin/add.php
View file @
3a6a6435
...
...
@@ -21,6 +21,7 @@ use common\core\ActiveForm;
<!-- BEGIN FORM-->
<?=
$this
->
render
(
'_form'
,
[
'model'
=>
$model
,
'role'
=>
$role
,
])
?>
<!-- END FORM-->
</div>
...
...
backend/views/admin/edit.php
View file @
3a6a6435
<?php
use
common\core\ActiveForm
;
?>
<div
class=
"portlet light bordered"
>
...
...
@@ -8,6 +9,7 @@ use common\core\ActiveForm;
<!-- BEGIN FORM-->
<?=
$this
->
render
(
'_form'
,
[
'model'
=>
$model
,
'role'
=>
$role
,
])
?>
<!-- END FORM-->
</div>
...
...
backend/views/auth/add.php
View file @
3a6a6435
...
...
@@ -6,10 +6,10 @@ use common\helpers\ArrayHelper;
?>
<div
class=
"portlet light bordered"
>
<div
class=
"portlet light bordered"
>
<div
class=
"portlet-body form"
>
<!-- BEGIN FORM-->
<form
action=
"
<?=
\yii\helpers\Url
::
toRoute
([
'add'
])
?>
"
method=
"post"
class=
"form-aaa "
>
<form
action=
"
<?=
\yii\helpers\Url
::
toRoute
([
'add'
])
?>
"
method=
"post"
class=
"form-aaa "
>
<div
class=
"form-group"
>
<div>
...
...
@@ -28,10 +28,9 @@ use common\helpers\ArrayHelper;
<textarea
class=
"form-control c-md-4"
name=
"param[description]"
rows=
"3"
></textarea>
<span
class=
"help-block"
></span>
</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-->
...
...
backend/views/auth/user.php
View file @
3a6a6435
...
...
@@ -7,75 +7,75 @@ use yii\grid\GridView;
$columns
=
[
[
'class'
=>
\common\core\CheckboxColumn
::
className
(),
'name'
=>
'id'
,
'options'
=>
[
'width'
=>
'20px;'
],
'class'
=>
\common\core\CheckboxColumn
::
className
(),
'name'
=>
'id'
,
'options'
=>
[
'width'
=>
'20px;'
],
'checkboxOptions'
=>
function
(
$model
,
$key
,
$index
,
$column
)
{
return
[
'value'
=>
$key
,
'label'
=>
'<span></span>'
,
'labelOptions'
=>
[
'class'
=>
'mt-checkbox mt-checkbox-outline'
,
'style'
=>
'padding-left:19px;'
]];
return
[
'value'
=>
$key
,
'label'
=>
'<span></span>'
,
'labelOptions'
=>
[
'class'
=>
'mt-checkbox mt-checkbox-outline'
,
'style'
=>
'padding-left:19px;'
]];
}
],
[
'header'
=>
'UID'
,
'header'
=>
'UID'
,
'attribute'
=>
'uid'
,
'options'
=>
[
'width'
=>
'50px;'
]
'options'
=>
[
'width'
=>
'50px;'
]
],
[
'header'
=>
'用户名'
,
'header'
=>
'用户名'
,
'attribute'
=>
'username'
,
'options'
=>
[
'width'
=>
'100px;'
]
'options'
=>
[
'width'
=>
'100px;'
]
],
[
'header'
=>
'邮箱'
,
'header'
=>
'邮箱'
,
'attribute'
=>
'email'
,
'options'
=>
[
'width'
=>
'150px;'
]
'options'
=>
[
'width'
=>
'150px;'
]
],
[
'header'
=>
'手机'
,
'header'
=>
'手机'
,
'attribute'
=>
'mobile'
,
'options'
=>
[
'width'
=>
'150px;'
]
'options'
=>
[
'width'
=>
'150px;'
]
],
[
'header'
=>
'最后登录时间'
,
'header'
=>
'最后登录时间'
,
'attribute'
=>
'last_login_time'
,
'options'
=>
[
'width'
=>
'150px;'
],
'format'
=>
[
'date'
,
'php:Y-m-d H:i:s'
]
'options'
=>
[
'width'
=>
'150px;'
],
'format'
=>
[
'date'
,
'php:Y-m-d H:i:s'
]
],
[
'header'
=>
'最后登录IP'
,
'header'
=>
'最后登录IP'
,
'attribute'
=>
'last_login_ip'
,
'options'
=>
[
'width'
=>
'150px;'
],
'content'
=>
function
(
$model
)
{
'options'
=>
[
'width'
=>
'150px;'
],
'content'
=>
function
(
$model
)
{
return
long2ip
(
$model
[
'last_login_ip'
]);
}
],
[
'header'
=>
'状态'
,
'header'
=>
'状态'
,
'attribute'
=>
'status'
,
'options'
=>
[
'width'
=>
'60px;'
],
'content'
=>
function
(
$model
)
{
return
$model
[
'status'
]
?
'正常'
:
'<span style="color: red">删除</span>'
;
'options'
=>
[
'width'
=>
'60px;'
],
'content'
=>
function
(
$model
)
{
return
$model
[
'status'
]
?
'正常'
:
'<span style="color: red">删除</span>'
;
}
],
[
'class'
=>
'yii\grid\ActionColumn'
,
'header'
=>
'操作'
,
'class'
=>
'yii\grid\ActionColumn'
,
'header'
=>
'操作'
,
'template'
=>
'{edit} {auth}'
,
'options'
=>
[
'width'
=>
'200px;'
],
'buttons'
=>
[
'edit'
=>
function
(
$url
,
$model
,
$key
)
{
return
Html
::
a
(
'<i class="fa fa-edit"></i> 编辑'
,
[
'admin/edit'
,
'uid'
=>
$key
],
[
'options'
=>
[
'width'
=>
'200px;'
],
'buttons'
=>
[
'edit'
=>
function
(
$url
,
$model
,
$key
)
{
return
Html
::
a
(
'<i class="fa fa-edit"></i> 编辑'
,
[
'admin/edit'
,
'uid'
=>
$key
],
[
'title'
=>
Yii
::
t
(
'app'
,
'编辑'
),
'class'
=>
'btn btn-xs blue'
]);
},
'auth'
=>
function
(
$url
,
$model
,
$key
)
{
return
Html
::
a
(
'<i class="fa fa-user"></i> 授权'
,
[
'admin/auth'
,
'uid'
=>
$key
],
[
'auth'
=>
function
(
$url
,
$model
,
$key
)
{
return
Html
::
a
(
'<i class="fa fa-user"></i> 授权'
,
[
'admin/auth'
,
'uid'
=>
$key
],
[
'title'
=>
Yii
::
t
(
'app'
,
'授权'
),
'class'
=>
'btn btn-xs blue'
]);
},
'delete'
=>
function
(
$url
,
$model
,
$key
)
{
return
Html
::
a
(
'<i class="fa fa-times"></i>'
,
[
'admin/delete'
,
'id'
=>
$key
],
[
return
Html
::
a
(
'<i class="fa fa-times"></i>'
,
[
'admin/delete'
,
'id'
=>
$key
],
[
'title'
=>
Yii
::
t
(
'app'
,
'删除'
),
'class'
=>
'btn btn-xs red ajax-get confirm'
]);
...
...
@@ -87,25 +87,27 @@ $columns = [
?>
<div
class=
"row admin-auth-user"
>
<div
class=
"col-md-12"
>
<a
href=
"/admin/admin/add?role=
<?=
$role
?>
"
>
<button
class=
"btn btn-primary"
><i
class=
"fa fa-plus"
></i>
添加
</button>
</a>
<div
class=
"table-container"
>
<form
class=
"ids"
>
<?=
GridView
::
widget
([
'dataProvider'
=>
$dataProvider
,
// 列表数据
//'filterModel' => $searchModel, // 搜索模型
'emptyText'
=>
Html
::
a
(
'<i class="fa fa-mail-reply"></i> 无数据'
,
Yii
::
getAlias
(
'@web'
)
.
'/auth/index'
),
'options'
=>
[
'class'
=>
'grid-view'
],
/* 表格配置 */
'tableOptions'
=>
[
'class'
=>
'table table-striped table-bordered table-hover table-checkable order-column dataTable no-footer'
],
/* 重新排版 摘要、表格、分页 */
'layout'
=>
'{items}<div class=""><div class="col-md-5 col-sm-5">{summary}</div><div class="col-md-7 col-sm-7"><div class="dataTables_paginate paging_bootstrap_full_number" style="text-align:right;">{pager}</div></div></div>'
,
/* 配置摘要 */
'summaryOptions'
=>
[
'class'
=>
'pagination'
],
/* 配置分页样式 */
'pager'
=>
Yii
::
$app
->
params
[
'pager'
],
/* 定义列表格式 */
'columns'
=>
$columns
,
]);
?>
<?=
GridView
::
widget
([
'dataProvider'
=>
$dataProvider
,
// 列表数据
//'filterModel' => $searchModel, // 搜索模型
'emptyText'
=>
Html
::
a
(
'<i class="fa fa-mail-reply"></i> 无数据'
,
Yii
::
getAlias
(
'@web'
)
.
'/auth/index'
),
'options'
=>
[
'class'
=>
'grid-view'
],
/* 表格配置 */
'tableOptions'
=>
[
'class'
=>
'table table-striped table-bordered table-hover table-checkable order-column dataTable no-footer'
],
/* 重新排版 摘要、表格、分页 */
'layout'
=>
'{items}<div class=""><div class="col-md-5 col-sm-5">{summary}</div><div class="col-md-7 col-sm-7"><div class="dataTables_paginate paging_bootstrap_full_number" style="text-align:right;">{pager}</div></div></div>'
,
/* 配置摘要 */
'summaryOptions'
=>
[
'class'
=>
'pagination'
],
/* 配置分页样式 */
'pager'
=>
Yii
::
$app
->
params
[
'pager'
],
/* 定义列表格式 */
'columns'
=>
$columns
,
]);
?>
</form>
</div>
</div>
...
...
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