Commit 577be8df authored by rlgy's avatar rlgy

update

......@@ -23,10 +23,10 @@ class AdminController extends BaseController
/* 添加当前位置到cookie供后续操作调用 */
$this->setForward();
$searchModel = new AdminSearch();
$searchModel = new AdminSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
......@@ -43,12 +43,12 @@ class AdminController extends BaseController
if (Yii::$app->request->isPost) {
/* 表单验证 */
$data = Yii::$app->request->post('Admin');
$data['reg_time'] = time();
$data['reg_ip'] = ip2long(Yii::$app->request->getUserIP());
$data = Yii::$app->request->post('Admin');
$data['reg_time'] = time();
$data['reg_ip'] = ip2long(Yii::$app->request->getUserIP());
$data['last_login_time'] = 0;
$data['last_login_ip'] = ip2long('127.0.0.1');
$data['update_time'] = 0;
$data['last_login_ip'] = ip2long('127.0.0.1');
$data['update_time'] = 0;
/* 表单数据加载和验证,具体验证规则在模型rule中配置 */
/* 密码单独验证,否则setPassword后密码肯定符合rule */
if (empty($data['password']) || strlen($data['password']) < 6) {
......@@ -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,
]);
}
}
......@@ -22,40 +22,25 @@ 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">
后台角色<label style="color: #0d8580">【查看】</label>
<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':''; ?> />
<span></span>
<?=$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':''; ?> />
<input type="radio" name="param" value="<?= $role->name ?>" <?php echo in_array($role->name, $group) ? 'checked' : ''; ?> />
<span></span>
<?=$k?> (<?=$v?>)
<?= $role->name ?> (<?= $role->description ?>)
</label>
<?php endforeach ?>
<?php endforeach ?>
</div>
</div>
<div class="form-actions">
<?= Html::submitButton('确定', ['class' => 'btn blue ajax-post','target-form'=>'form-aaa']) ?>&nbsp;&nbsp;&nbsp;
<?= Html::button('返回', ['class' => 'btn ','onclick'=>"javascript:history.go(-1);"]) ?>
</div>
<div class="form-actions">
<?= Html::submitButton('确定', ['class' => 'btn blue ajax-post', 'target-form' => 'form-aaa']) ?>&nbsp;&nbsp;&nbsp;
<?= Html::button('返回', ['class' => 'btn ', 'onclick' => "javascript:history.go(-1);"]) ?>
</div>
</form>
<!-- END FORM-->
</div>
......
<?php
namespace common\core\rbac;
use yii\rbac\Item;
......@@ -12,18 +13,19 @@ class DbManager extends \yii\rbac\DbManager
* ---------------------------------------
* 当Rule不存在时添加
* 同时将auth_item添加或更新
* @param string $name rule名称
* @param object $rule 规则对象
* @param string $name rule名称
* @param object $rule 规则对象
* ---------------------------------------
*/
public function saveRule($name) {
public function saveRule($name)
{
/* 判断auth_rule表是否存在 */
if ($rule = $this->getRule($name)) {
/* 更新 */
} else {
/* 添加 */
$rule = new Rule();
$rule = new Rule();
$rule->name = $name;
$this->add($rule);
}
......@@ -34,9 +36,9 @@ class DbManager extends \yii\rbac\DbManager
} else {
/* 添加 */
$item = new Item();
$item->name = $name;
$item->type = 2;
$item = new Item();
$item->name = $name;
$item->type = 2;
$item->ruleName = $name;
$this->add($item);
}
......@@ -45,11 +47,12 @@ class DbManager extends \yii\rbac\DbManager
/**
* ---------------------------------------
* 保存角色的权限分配
* @param string $parent 角色name
* @param string $child 权限name
* @param string $parent 角色name
* @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,30 +65,26 @@ 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, [
'rule_name' => $rule->name,
'name' => $rule->name,
], [
'rule_name' => $name
])->execute();
$this->db->createCommand()->update($this->itemTable, [
'rule_name' => $rule->name,
'name' => $rule->name,
], ['rule_name' => $name])->execute();
}
$rule->updatedAt = time();
$this->db->createCommand()
->update($this->ruleTable, [
'name' => $rule->name,
'data' => serialize($rule),
'name' => $rule->name,
'data' => serialize($rule),
'updated_at' => $rule->updatedAt,
], [
'name' => $name,
])->execute();
], ['name' => $name,])->execute();
$this->invalidateCache();
......
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