Commit 3a6a6435 authored by rlgy's avatar rlgy

update

parent 577be8df
...@@ -49,6 +49,7 @@ class AdminController extends BaseController ...@@ -49,6 +49,7 @@ class AdminController extends BaseController
$data['last_login_time'] = 0; $data['last_login_time'] = 0;
$data['last_login_ip'] = ip2long('127.0.0.1'); $data['last_login_ip'] = ip2long('127.0.0.1');
$data['update_time'] = 0; $data['update_time'] = 0;
$role = Yii::$app->request->post('role', 'administrator');
/* 表单数据加载和验证,具体验证规则在模型rule中配置 */ /* 表单数据加载和验证,具体验证规则在模型rule中配置 */
/* 密码单独验证,否则setPassword后密码肯定符合rule */ /* 密码单独验证,否则setPassword后密码肯定符合rule */
if (empty($data['password']) || strlen($data['password']) < 6) { if (empty($data['password']) || strlen($data['password']) < 6) {
...@@ -60,6 +61,9 @@ class AdminController extends BaseController ...@@ -60,6 +61,9 @@ class AdminController extends BaseController
$model->setPassword($data['password']); $model->setPassword($data['password']);
/* 保存用户数据到数据库 */ /* 保存用户数据到数据库 */
if ($model->save()) { if ($model->save()) {
$auth = Yii::$app->authManager;
$role = $auth->getRole($role);
$auth->assign($role,$model->uid);
$this->success('操作成功', $this->getForward()); $this->success('操作成功', $this->getForward());
} else { } else {
$this->error('操作错误'); $this->error('操作错误');
...@@ -68,6 +72,7 @@ class AdminController extends BaseController ...@@ -68,6 +72,7 @@ class AdminController extends BaseController
return $this->render('add', [ return $this->render('add', [
'model' => $model, 'model' => $model,
'role' => Yii::$app->request->get('role', 'administrator')
]); ]);
} }
...@@ -105,9 +110,9 @@ class AdminController extends BaseController ...@@ -105,9 +110,9 @@ class AdminController extends BaseController
$group = array_keys($auth->getAssignments($uid)); $group = array_keys($auth->getAssignments($uid));
return $this->render('auth', [ return $this->render('auth', [
'model' => $model, 'model' => $model,
'roles' => $roles, 'roles' => $roles,
'group' => $group, 'group' => $group,
]); ]);
} }
......
...@@ -61,23 +61,25 @@ class AuthController extends BaseController ...@@ -61,23 +61,25 @@ class AuthController extends BaseController
public function actionAdd() public function actionAdd()
{ {
if (Yii::$app->request->isPost) { if (Yii::$app->request->isPost) {
$data = Yii::$app->request->post('param'); $data = Yii::$app->request->post('param');
$data['name'] = trim($data['name']); $data['name'] = trim($data['name']);
if (!$data['name']) { if (!$data['name']) {
$this->error('请输入要添加的角色名!'); $this->error('请输入要添加的角色名!');
} else if (Yii::$app->authManager->getRole($data['name']) != null) { } else {
$this->error('该角色名已存在!'); if (Yii::$app->authManager->getRole($data['name']) != null) {
} else { $this->error('该角色名已存在!');
} else {
/* 创建角色 */
$role = Yii::$app->authManager->createRole($data['name']); /* 创建角色 */
$role->type = 1; $role = Yii::$app->authManager->createRole($data['name']);
$role->description = $data['description']; $role->type = 1;
if (Yii::$app->authManager->add($role)) { $role->description = $data['description'];
$this->success('添加成功!', $this->getForward()); if (Yii::$app->authManager->add($role)) {
} $this->success('添加成功!', $this->getForward());
$this->error('添加失败!'); }
} $this->error('添加失败!');
}
}
} }
return $this->render('add'); return $this->render('add');
} }
...@@ -91,30 +93,32 @@ class AuthController extends BaseController ...@@ -91,30 +93,32 @@ class AuthController extends BaseController
*/ */
public function actionEdit() public function actionEdit()
{ {
/* 获取角色信息 */ /* 获取角色信息 */
$item_name = trim(Yii::$app->request->get('role')); $item_name = trim(Yii::$app->request->get('role'));
$role = Yii::$app->authManager->getRole($item_name); $role = Yii::$app->authManager->getRole($item_name);
if (Yii::$app->request->isPost) { if (Yii::$app->request->isPost) {
$data = Yii::$app->request->post('param'); $data = Yii::$app->request->post('param');
$data['name'] = trim($data['name']); $data['name'] = trim($data['name']);
if (!$data['name']) { if (!$data['name']) {
$this->success('请输入要更新的角色名!'); $this->success('请输入要更新的角色名!');
} else if (Yii::$app->authManager->getRole($data['name']) != null) { } else {
$this->error('该角色名已存在!'); if (Yii::$app->authManager->getRole($data['name']) != null) {
} else { $this->error('该角色名已存在!');
} else {
$role->name = $data['name'];
$role->description = $data['description']; $role->name = $data['name'];
if (Yii::$app->authManager->update($item_name, $role)) { $role->description = $data['description'];
$this->success('更新成功!', $this->getForward()); if (Yii::$app->authManager->update($item_name, $role)) {
} $this->success('更新成功!', $this->getForward());
$this->error('更新失败!'); }
} $this->error('更新失败!');
}
}
} }
return $this->render('edit', [ return $this->render('edit', [
'role' => $role, 'role' => $role,
...@@ -167,14 +171,14 @@ class AuthController extends BaseController ...@@ -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 = Yii::$app->authManager->getChildren($role);
$auth_rules = array_keys($auth_rules);//var_dump($auth_rules);exit; $auth_rules = array_keys($auth_rules);//var_dump($auth_rules);exit;
return $this->render('auth', [ return $this->render('auth', [
'node_list' => $node_list, 'node_list' => $node_list,
'auth_rules' => $auth_rules, 'auth_rules' => $auth_rules,
'role' => $role, 'role' => $role,
]); ]);
} }
...@@ -200,6 +204,7 @@ class AuthController extends BaseController ...@@ -200,6 +204,7 @@ class AuthController extends BaseController
return $this->render('user', [ return $this->render('user', [
'dataProvider' => $this->lists1(new Admin(), $_where), 'dataProvider' => $this->lists1(new Admin(), $_where),
'role' => Yii::$app->request->get('role', 'administrator'),
]); ]);
} }
......
...@@ -38,6 +38,7 @@ use common\core\ActiveForm; ...@@ -38,6 +38,7 @@ use common\core\ActiveForm;
'placeholder' => '修改时,密码不变可不填' 'placeholder' => '修改时,密码不变可不填'
])->label(false) ?> ])->label(false) ?>
<input type="hidden" value="<?= $role ?>" name="role">
<?= $form->field($model, 'status')->radioList(['1'=>'正常', '0'=>'禁用'])->label('使用状态') ?> <?= $form->field($model, 'status')->radioList(['1'=>'正常', '0'=>'禁用'])->label('使用状态') ?>
......
...@@ -21,6 +21,7 @@ use common\core\ActiveForm; ...@@ -21,6 +21,7 @@ use common\core\ActiveForm;
<!-- BEGIN FORM--> <!-- BEGIN FORM-->
<?= $this->render('_form', [ <?= $this->render('_form', [
'model' => $model, 'model' => $model,
'role' => $role,
]) ?> ]) ?>
<!-- END FORM--> <!-- END FORM-->
</div> </div>
......
<?php <?php
use common\core\ActiveForm; use common\core\ActiveForm;
?> ?>
<div class="portlet light bordered"> <div class="portlet light bordered">
...@@ -8,6 +9,7 @@ use common\core\ActiveForm; ...@@ -8,6 +9,7 @@ use common\core\ActiveForm;
<!-- BEGIN FORM--> <!-- BEGIN FORM-->
<?= $this->render('_form', [ <?= $this->render('_form', [
'model' => $model, 'model' => $model,
'role' => $role,
]) ?> ]) ?>
<!-- END FORM--> <!-- END FORM-->
</div> </div>
......
...@@ -6,10 +6,10 @@ use common\helpers\ArrayHelper; ...@@ -6,10 +6,10 @@ use common\helpers\ArrayHelper;
?> ?>
<div class="portlet light bordered" > <div class="portlet light bordered">
<div class="portlet-body form"> <div class="portlet-body form">
<!-- BEGIN 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 class="form-group">
<div> <div>
...@@ -28,10 +28,9 @@ use common\helpers\ArrayHelper; ...@@ -28,10 +28,9 @@ use common\helpers\ArrayHelper;
<textarea class="form-control c-md-4" name="param[description]" rows="3"></textarea> <textarea class="form-control c-md-4" name="param[description]" rows="3"></textarea>
<span class="help-block"></span> <span class="help-block"></span>
</div> </div>
<div class="form-actions"> <div class="form-actions">
<?= Html::submitButton('确定', ['class' => 'btn blue ajax-post','target-form'=>'form-aaa']) ?> <?= Html::submitButton('确定', ['class' => 'btn blue ajax-post', 'target-form' => 'form-aaa']) ?>
<?= Html::button('返回', ['class' => 'btn ','onclick'=>"javascript:history.go(-1);"]) ?> <?= Html::button('返回', ['class' => 'btn ', 'onclick' => "javascript:history.go(-1);"]) ?>
</div> </div>
</form> </form>
<!-- END FORM--> <!-- END FORM-->
......
...@@ -7,75 +7,75 @@ use yii\grid\GridView; ...@@ -7,75 +7,75 @@ use yii\grid\GridView;
$columns = [ $columns = [
[ [
'class' => \common\core\CheckboxColumn::className(), 'class' => \common\core\CheckboxColumn::className(),
'name' => 'id', 'name' => 'id',
'options' => ['width' => '20px;'], 'options' => ['width' => '20px;'],
'checkboxOptions' => function ($model, $key, $index, $column) { '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', 'attribute' => 'uid',
'options' => ['width' => '50px;'] 'options' => ['width' => '50px;']
], ],
[ [
'header' => '用户名', 'header' => '用户名',
'attribute' => 'username', 'attribute' => 'username',
'options' => ['width' => '100px;'] 'options' => ['width' => '100px;']
], ],
[ [
'header' => '邮箱', 'header' => '邮箱',
'attribute' => 'email', 'attribute' => 'email',
'options' => ['width' => '150px;'] 'options' => ['width' => '150px;']
], ],
[ [
'header' => '手机', 'header' => '手机',
'attribute' => 'mobile', 'attribute' => 'mobile',
'options' => ['width' => '150px;'] 'options' => ['width' => '150px;']
], ],
[ [
'header' => '最后登录时间', 'header' => '最后登录时间',
'attribute' => 'last_login_time', 'attribute' => 'last_login_time',
'options' => ['width' => '150px;'], 'options' => ['width' => '150px;'],
'format' => ['date', 'php:Y-m-d H:i:s'] 'format' => ['date', 'php:Y-m-d H:i:s']
], ],
[ [
'header' => '最后登录IP', 'header' => '最后登录IP',
'attribute' => 'last_login_ip', 'attribute' => 'last_login_ip',
'options' => ['width' => '150px;'], 'options' => ['width' => '150px;'],
'content' => function($model){ 'content' => function ($model) {
return long2ip($model['last_login_ip']); return long2ip($model['last_login_ip']);
} }
], ],
[ [
'header' => '状态', 'header' => '状态',
'attribute' => 'status', 'attribute' => 'status',
'options' => ['width' => '60px;'], 'options' => ['width' => '60px;'],
'content' => function($model){ 'content' => function ($model) {
return $model['status'] ? '正常': '<span style="color: red">删除</span>'; return $model['status'] ? '正常' : '<span style="color: red">删除</span>';
} }
], ],
[ [
'class' => 'yii\grid\ActionColumn', 'class' => 'yii\grid\ActionColumn',
'header' => '操作', 'header' => '操作',
'template' => '{edit} {auth}', 'template' => '{edit} {auth}',
'options' => ['width' => '200px;'], 'options' => ['width' => '200px;'],
'buttons' => [ 'buttons' => [
'edit' => function ($url, $model, $key) { 'edit' => function ($url, $model, $key) {
return Html::a('<i class="fa fa-edit"></i> 编辑', ['admin/edit','uid'=>$key], [ return Html::a('<i class="fa fa-edit"></i> 编辑', ['admin/edit', 'uid' => $key], [
'title' => Yii::t('app', '编辑'), 'title' => Yii::t('app', '编辑'),
'class' => 'btn btn-xs blue' 'class' => 'btn btn-xs blue'
]); ]);
}, },
'auth' => function ($url, $model, $key) { 'auth' => function ($url, $model, $key) {
return Html::a('<i class="fa fa-user"></i> 授权', ['admin/auth','uid'=>$key], [ return Html::a('<i class="fa fa-user"></i> 授权', ['admin/auth', 'uid' => $key], [
'title' => Yii::t('app', '授权'), 'title' => Yii::t('app', '授权'),
'class' => 'btn btn-xs blue' 'class' => 'btn btn-xs blue'
]); ]);
}, },
'delete' => function ($url, $model, $key) { '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', '删除'), 'title' => Yii::t('app', '删除'),
'class' => 'btn btn-xs red ajax-get confirm' 'class' => 'btn btn-xs red ajax-get confirm'
]); ]);
...@@ -87,25 +87,27 @@ $columns = [ ...@@ -87,25 +87,27 @@ $columns = [
?> ?>
<div class="row admin-auth-user"> <div class="row admin-auth-user">
<div class="col-md-12"> <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"> <div class="table-container">
<form class="ids"> <form class="ids">
<?= GridView::widget([ <?= GridView::widget([
'dataProvider' => $dataProvider, // 列表数据 'dataProvider' => $dataProvider, // 列表数据
//'filterModel' => $searchModel, // 搜索模型 //'filterModel' => $searchModel, // 搜索模型
'emptyText' => Html::a('<i class="fa fa-mail-reply"></i> 无数据', Yii::getAlias('@web').'/auth/index'), 'emptyText' => Html::a('<i class="fa fa-mail-reply"></i> 无数据', Yii::getAlias('@web') . '/auth/index'),
'options' => ['class' => 'grid-view'], 'options' => ['class' => 'grid-view'],
/* 表格配置 */ /* 表格配置 */
'tableOptions' => ['class' => 'table table-striped table-bordered table-hover table-checkable order-column dataTable no-footer'], '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>', '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'], 'summaryOptions' => ['class' => 'pagination'],
/* 配置分页样式 */ /* 配置分页样式 */
'pager' => Yii::$app->params['pager'], 'pager' => Yii::$app->params['pager'],
/* 定义列表格式 */ /* 定义列表格式 */
'columns' => $columns, 'columns' => $columns,
]); ?> ]); ?>
</form> </form>
</div> </div>
</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