Commit 3a6a6435 authored by rlgy's avatar rlgy

update

parent 577be8df
......@@ -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,
]);
}
......
......@@ -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'),
]);
}
......
......@@ -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('使用状态') ?>
......
......@@ -21,6 +21,7 @@ use common\core\ActiveForm;
<!-- BEGIN FORM-->
<?= $this->render('_form', [
'model' => $model,
'role' => $role,
]) ?>
<!-- END FORM-->
</div>
......
<?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>
......
......@@ -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-->
......
......@@ -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>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment