Commit 8d008f67 authored by rlgy's avatar rlgy

update

parent 465ce1ff
......@@ -4,7 +4,6 @@ namespace backend\controllers;
use common\models\Admin;
use common\models\search\AdminSearch;
use common\core\Exception;
use Yii;
/**
......@@ -62,7 +61,8 @@ class AdminController extends BaseController
$model->generateAuthKey();
$model->setPassword($data['password']);
$model->group = $role;
$model->group = $role;
$model->platform_id = Yii::$app->user->identity->platform_id;
/* 保存用户数据到数据库 */
if ($model->save()) {
$auth = Yii::$app->authManager;
......@@ -76,7 +76,7 @@ class AdminController extends BaseController
return $this->render('add', [
'model' => $model,
'role' => Yii::$app->request->get('role', 'administrator')
'role' => Yii::$app->request->get('role', 'administrator'),
]);
}
......@@ -123,41 +123,29 @@ class AdminController extends BaseController
public function actionEdit()
{
$model = new Admin();
$model = Admin::findOne(Yii::$app->request->get('uid'));
if (Yii::$app->request->isPost) {
/* 表单验证 */
$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;
$role = Yii::$app->request->post('role', 'administrator');
/* 表单数据加载和验证,具体验证规则在模型rule中配置 */
/* 密码单独验证,否则setPassword后密码肯定符合rule */
if (empty($data['password']) || strlen($data['password']) < 6) {
$this->error('密码为空或小于6字符');
}
$data = Yii::$app->request->post('Admin');
$model->setAttributes($data);
$model->generateAuthKey();
$model->setPassword($data['password']);
$model->group = $role;
if (!empty($data['password'])) {
$model->generateAuthKey();
$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('操作错误');
}
}
$model->password = '';
return $this->render('add', [
'model' => $model,
'role' => Yii::$app->request->get('role', 'administrator')
'role' => Yii::$app->request->get('role', 'administrator'),
]);
}
}
......@@ -34,7 +34,7 @@ class Admin extends \common\core\BaseActiveRecord
public function rules()
{
return [
[['username', 'password', 'salt'], 'required'],
[['username', 'salt'], 'required'],
[
['username', 'password'],
'filter',
......
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