Authored by wuxiao

用户编辑、用户组编辑、权限编辑

... ... @@ -27,8 +27,8 @@ return [
'admin'=>array(
'后台管理',array(
'admin/list'=>array('用户','admin/list'),
'admin/permission'=>array('菜单权限','admin/permission'),
'admin/role'=>array('用户组','admin/role'),
'admin/permission'=>array('权限','admin/permission'),
)
),
),
... ...
... ... @@ -25,10 +25,11 @@ class AdminController extends BaseController
public function actionList()
{
if (Yii::$app->request->isPost){
$posts = Yii::$app->request->post();
$model = new Admin;
$model->username = Yii::$app->request->post('username');
$model->email = Yii::$app->request->post('email');
$model->setPassword(Yii::$app->request->post('password'));
$model->username = $posts['username'];
$model->email = $posts['email'];
$model->setPassword($posts['password']);
$model->generateAuthKey();
$model->generatePasswordResetToken();
... ... @@ -98,7 +99,7 @@ class AdminController extends BaseController
$list = $this->authManager->getPermissions();
return $this->render('permissions',[
return $this->render('permission',[
'list'=>$list,
]);
}
... ... @@ -119,10 +120,12 @@ class AdminController extends BaseController
$authManager = $this->authManager;
switch (true){
case $target == 'user' && $type == 'disable':
$r = true;
$model = Admin::findOne(Yii::$app->getRequest()->getQueryParam('id'));
$r = $model->load(['status'=>Admin::STATUS_DELETED],'') && $model->save();
break;
case $target == 'user' && $type == 'enable':
$r = true;
$model = Admin::findOne(Yii::$app->getRequest()->getQueryParam('id'));
$r = $model->load(['status'=>Admin::STATUS_ACTIVE],'') && $model->save();
break;
case $target == 'user' && $type == 'del':
$r = Admin::findOne(Yii::$app->getRequest()->getQueryParam('id'))->delete();
... ... @@ -146,10 +149,48 @@ class AdminController extends BaseController
}
/**
* 用户组配置
* @return type
*/
public function actionAssignrole()
{
if (!$user_id = Yii::$app->getRequest()->getQueryParam('id')){
return $this->redirect($this->_refer);
}
if (!$user = Admin::findOne($user_id)){
return $this->redirect($this->_refer);
}
$auth = $this->authManager;
$allRoles = $auth->getRoles();
if (Yii::$app->request->isPost){
$roles = Yii::$app->request->post('roles',[]);
$auth->revokeAll($user_id);
foreach ($roles as $roleName){
if (empty($allRoles[$roleName])){
continue;
}
$role = $allRoles[$roleName];
$auth->assign($role,$user_id);
}
}
$userRoles = $auth->getRolesByUser($user->getId());
//var_dump($allRoles,$userRoles);
return $this->render('assignrole',[
'user'=>$user,
'allRoles'=>$allRoles,
'userRoles'=>$userRoles,
]);
}
/**
* 权限配置
* @return type
*/
public function actionAssignment()
public function actionAssignpermission()
{
if (!$name = Yii::$app->getRequest()->get('name')){
return $this->redirect($this->_refer);
... ... @@ -158,14 +199,11 @@ class AdminController extends BaseController
$auth = $this->authManager;
$role = $auth->getRole($name);
$allPermissions = $auth->getPermissions();
$rolePermissions = $auth->getPermissionsByRole($name);
if (Yii::$app->request->isPost){
$permissions = Yii::$app->request->post('permissions');
$permissions = Yii::$app->request->post('permissions',[]);
$auth->removeChildren($role);
foreach ($permissions as $permissionName){
if (!empty($rolePermissions[$permissionName])){
continue;
}
if (empty($allPermissions[$permissionName])){
continue;
}
... ... @@ -177,10 +215,120 @@ class AdminController extends BaseController
$rolePermissions = $auth->getPermissionsByRole($name);
//var_dump($allPermissions,$rolePermissions);
return $this->render('assignment',[
return $this->render('assignpermission',[
'role'=>$role,
'allPermissions'=>$allPermissions,
'rolePermissions'=>$rolePermissions,
]);
}
/**
* 编辑用户
* @return type
*/
public function actionAdminedit()
{
if (!$id = Yii::$app->getRequest()->getQueryParam('id')){
return $this->redirect($this->_refer);
}
$model = Admin::findOne($id);
if (!$model){
Yii::$app->session->setFlash('error', '找不到该用户');
return $this->redirect($this->_refer);
}
if(Yii::$app->request->isPost){
$posts = Yii::$app->request->post();
$model->username = $posts['username'];
$model->email = $posts['email'];
if (!empty($posts['password'])){
$model->setPassword($posts['password']);
$model->generateAuthKey();
$model->generatePasswordResetToken();
}
if($model->save()){
if (!empty($posts['password'])){
Yii::$app->session->setFlash('success', '密码修改成功。');
}
Yii::$app->session->setFlash('success', '编辑成功。');
}else{
Yii::$app->session->setFlash('warning', current($model->getFirstErrors()));
}
return $this->refresh();
}
return $this->render('adminedit',[
'model'=>$model,
]);
}
/**
* 编辑用户组
* @return type
*/
public function actionRoleedit()
{
if (!$name = Yii::$app->getRequest()->get('name')){
return $this->redirect($this->_refer);
}
$model = $this->authManager->getRole($name);
if (!$model){
Yii::$app->session->setFlash('error', '找不到该用户组');
return $this->redirect($this->_refer);
}
if(Yii::$app->request->isPost){
$posts = Yii::$app->request->post();
$model->name = $posts['name'];
$model->description = $posts['description'];
if($this->authManager->update($name,$model)){
Yii::$app->session->setFlash('success', '编辑成功。');
}else{
Yii::$app->session->setFlash('warning', current($model->getFirstErrors()));
}
return $this->refresh();
}
return $this->render('roleedit',[
'model'=>$model,
]);
}
/**
* 编辑菜单权限
* @return type
*/
public function actionPermissionedit()
{
if (!$name = Yii::$app->getRequest()->get('name')){
return $this->redirect($this->_refer);
}
$model = $this->authManager->getPermission($name);
if (!$model){
Yii::$app->session->setFlash('error', '找不到该用户组');
return $this->redirect($this->_refer);
}
if(Yii::$app->request->isPost){
$posts = Yii::$app->request->post();
$model->name = $posts['name'];
$model->description = $posts['description'];
if($this->authManager->update($name,$model)){
Yii::$app->session->setFlash('success', '编辑成功。');
}else{
Yii::$app->session->setFlash('warning', current($model->getFirstErrors()));
}
return $this->refresh();
}
return $this->render('permissionedit',[
'model'=>$model,
]);
}
}
... ...
<?php
use yii\web\View;
use yii\helpers\Html;
use backend\widgets\YHGImage\Common\Images as CommonImages;
$this->title = $this->params['main_title'].'-'.$this->params['sub_title'];
?>
<?php
$this->registerCssFile('/css/select2.css',array('postion'=>View::POS_END));
$this->registerJsFile('/js/select2.min.js',array('postion'=>View::POS_END));
?>
<script type="text/javascript">
<?php $this->beginBlock('javascript');?>
jQuery(document).ready(function() {
// Select2
jQuery(".select-basic").select2();
});
<?php
$this->endBlock();
$this->registerJs($this->blocks['javascript'],View::POS_END)
?>
</script>
<div class="col-md-6">
<form id="form" method="POST" action="">
<div class="panel panel-default">
<div class="panel-body">
<div class="row">
<div class="form-group">
<label class="col-sm-3 control-label">用户名: <span class="asterisk">*</span></label>
<div class="col-sm-5">
<input type="text" name="username" class="form-control" required="required" value="<?=$model->username?>">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">邮箱: </label>
<div class="col-sm-5">
<input type="text" name="email" class="form-control" required="required" value="<?=$model->email?>">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">修改密码: <span class="asterisk">*</span></label>
<div class="col-sm-5">
<input type="password" name="password" class="form-control">
</div>
</div>
</div><!-- row -->
</div><!-- panel-body -->
<div class="panel-footer">
<div class="row">
<div class="col-sm-9 col-sm-offset-3">
<button class="btn btn-primary mr5" id="upload_button">保存</button>
<a href="<?=$_refer?>" class="btn btn-dark">取消</a>
</div>
</div>
</div><!-- panel-footer -->
</div><!-- panel -->
</form>
</div>
... ...
<?php
use yii\web\View;
use yii\helpers\Html;
use yii\helpers\ArrayHelper;
$this->title = $this->params['main_title'] . '-' . $this->params['sub_title'];
?>
<div class="col-md-12">
<form class="form-bordered" method="POST" action="">
<div class="panel panel-default">
<div class="panel-heading">
<h5 class="panel-title"><?=$user->username?></h5>
<p><?=$user->email?></p>
</div><!-- panel-heading -->
<div class="panel-body">
<ul class="row icon-list">
<?php foreach ($allRoles as $roleName=>$role):?>
<li class="col-xs-6 col-sm-4 col-md-3">
<div class="ckbox ckbox-default">
<?php echo Html::checkbox('roles[]', array_key_exists($roleName, $userRoles), ['id'=>$roleName,'value'=>$roleName])?>
<label for="<?=$roleName?>"><?=$role->description?></label>
</div>
</li>
<?php endforeach;?>
</ul>
</div>
<div class="panel-footer">
<div class="row">
<div class="col-sm-9 col-sm-offset-3">
<button class="btn btn-primary mr5" id="upload_button">保存</button>
<a href="<?=$_refer?>" class="btn btn-dark">取消</a>
</div>
</div>
</div><!-- panel-footer -->
</div><!-- panel -->
</form>
</div>
\ No newline at end of file
... ...
... ... @@ -31,17 +31,12 @@ $this->registerJs($this->blocks['javascript'],View::POS_END)
<div class="col-sm-4">
<input type="text" name="username" class="form-control" required="required" placeholder="用户名">
</div>
<div class="col-sm-5">
<div class="col-sm-4">
<input type="text" name="email" class="form-control" required="required" placeholder="邮箱">
</div>
</div>
<div class="form-group">
<div class="col-sm-4">
<input type="password" name="password" class="form-control" required="required" placeholder="密码">
</div>
<div class="col-sm-5">
<?php echo Html::dropDownList('role', null,$roles, ['class' => 'width300 select-basic']);?>
</div>
</div>
<div class="form-group">
<div class="col-sm-3">
... ... @@ -63,7 +58,6 @@ $this->registerJs($this->blocks['javascript'],View::POS_END)
<th><input type="checkbox" onclick="checkall(this)">选择</th>
<th>用户名</th>
<th>邮箱</th>
<th>权限</th>
<th>状态</th>
<th>加入时间</th>
<th>操作</th>
... ... @@ -75,22 +69,22 @@ $this->registerJs($this->blocks['javascript'],View::POS_END)
<td><input type="checkbox" value="<?=$model->id?>" name="room[]"></td>
<td><?=$model->username?></td>
<td><?=$model->email?></td>
<td><?=$model->role?></td>
<td><?=$model->status?></td>
<td><?=$model->status ? '启用' : '禁用'?></td>
<td style="white-space:nowrap"><?=date('Y-m-d H:i:s',$model->create_time)?></td>
<td>
<?php if (!in_array($model->username,['admin','super_admin'])):?>
<a href="/live/roomedit/<?=$model->id?>" class="btn btn-default btn-white">编辑</a>
<a href="/admin/adminedit/<?=$model->id?>" class="btn btn-default btn-white">编辑</a>
<a href="/admin/assignrole/<?=$model->id?>" class="btn btn-default btn-white">用户组配置</a>
<?php if ($model->status == 0)://未开始?>
<a onclick="return confirm('启用用户?')" href="/admin/operate/<?=$model->id?>?type=enable" class="btn btn-success btn-metro">启用</a>
<?php if ($model->status == 0)://禁用状态?>
<a onclick="return confirm('启用用户?')" href="/admin/operate/<?=$model->id?>?target=user&type=enable" class="btn btn-success btn-metro">启用</a>
<?php else:?>
<a onclick="return confirm('禁用用户?')" href="/admin/operate/<?=$model->id?>?type=disable" class="btn btn-danger btn-metro">禁用</a>
<a onclick="return confirm('禁用用户?')" href="/admin/operate/<?=$model->id?>?target=user&type=disable" class="btn btn-danger btn-metro">禁用</a>
<?php endif;?>
<a onclick="return confirm('删除用户?')" href="/admin/operate/<?=$model->id?>?type=del" class="btn btn-danger btn-metro">删除</a>
<a onclick="return confirm('删除用户?')" href="/admin/operate/<?=$model->id?>?target=user&type=del" class="btn btn-danger btn-metro">删除</a>
<?php endif;?>
</td>
... ...
... ... @@ -36,7 +36,7 @@ $this->title = $this->params['main_title'].'-'.$this->params['sub_title'];
<thead>
<tr style="white-space:nowrap">
<th><input type="checkbox" onclick="checkall(this)">选择</th>
<th>权限</th>
<th>权限标签</th>
<th>描述</th>
<th>添加时间</th>
<th>操作</th>
... ... @@ -51,7 +51,7 @@ $this->title = $this->params['main_title'].'-'.$this->params['sub_title'];
<td style="white-space:nowrap"><?=date('Y-m-d H:i:s',$model->createdAt)?></td>
<td>
<?php if ($model->name != 'index/index'):?>
<a href="/admin/roledit/?name=<?=$model->name?>" class="btn btn-default btn-white">编辑</a>
<a href="/admin/permissionedit/?name=<?=$model->name?>" class="btn btn-default btn-white">编辑</a>
<a onclick="return confirm('删除用户组?')" href="/admin/operate/?target=permission&type=del&name=<?=$model->name?>" class="btn btn-danger btn-metro">删除</a>
<?php endif;?>
</td>
... ...
<?php
use yii\web\View;
use yii\helpers\Html;
use backend\widgets\YHGImage\Common\Images as CommonImages;
$this->title = $this->params['main_title'].'-'.$this->params['sub_title'];
?>
<div class="col-md-6">
<form id="form" method="POST" action="">
<div class="panel panel-default">
<div class="panel-body">
<div class="row">
<div class="form-group">
<label class="col-sm-3 control-label">权限标签: <span class="asterisk">*</span></label>
<div class="col-sm-5">
<input type="text" name="name" class="form-control" required="required" value="<?=$model->name?>">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">描述: </label>
<div class="col-sm-5">
<input type="text" name="description" class="form-control" required="required" value="<?=$model->description?>">
</div>
</div>
</div><!-- row -->
</div><!-- panel-body -->
<div class="panel-footer">
<div class="row">
<div class="col-sm-9 col-sm-offset-3">
<button class="btn btn-primary mr5" id="upload_button">保存</button>
<a href="<?=$_refer?>" class="btn btn-dark">取消</a>
</div>
</div>
</div><!-- panel-footer -->
</div><!-- panel -->
</form>
</div>
... ...
... ... @@ -51,8 +51,8 @@ $this->title = $this->params['main_title'].'-'.$this->params['sub_title'];
<td style="white-space:nowrap"><?=date('Y-m-d H:i:s',$model->createdAt)?></td>
<td>
<?php if ($model->name != 'admin'):?>
<a href="/admin/roledit/?name=<?=$model->name?>" class="btn btn-default btn-white">编辑</a>
<a href="/admin/assignment/?name=<?=$model->name?>" class="btn btn-default btn-white">权限配置</a>
<a href="/admin/roleedit/?name=<?=$model->name?>" class="btn btn-default btn-white">编辑</a>
<a href="/admin/assignpermission/?name=<?=$model->name?>" class="btn btn-default btn-white">权限配置</a>
<a onclick="return confirm('删除用户组?')" href="/admin/operate/?target=role&type=del&name=<?=$model->name?>" class="btn btn-danger btn-metro">删除</a>
<?php endif;?>
</td>
... ...
<?php
use yii\web\View;
use yii\helpers\Html;
use backend\widgets\YHGImage\Common\Images as CommonImages;
$this->title = $this->params['main_title'].'-'.$this->params['sub_title'];
?>
<div class="col-md-6">
<form id="form" method="POST" action="">
<div class="panel panel-default">
<div class="panel-body">
<div class="row">
<div class="form-group">
<label class="col-sm-3 control-label">用户组: <span class="asterisk">*</span></label>
<div class="col-sm-5">
<input type="text" name="name" class="form-control" required="required" value="<?=$model->name?>">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">描述: </label>
<div class="col-sm-5">
<input type="text" name="description" class="form-control" required="required" value="<?=$model->description?>">
</div>
</div>
</div><!-- row -->
</div><!-- panel-body -->
<div class="panel-footer">
<div class="row">
<div class="col-sm-9 col-sm-offset-3">
<button class="btn btn-primary mr5" id="upload_button">保存</button>
<a href="<?=$_refer?>" class="btn btn-dark">取消</a>
</div>
</div>
</div><!-- panel-footer -->
</div><!-- panel -->
</form>
</div>
... ...