Commit 187b3423 authored by rlgy's avatar rlgy

update

parent 3a6a6435
...@@ -63,7 +63,7 @@ class AdminController extends BaseController ...@@ -63,7 +63,7 @@ class AdminController extends BaseController
if ($model->save()) { if ($model->save()) {
$auth = Yii::$app->authManager; $auth = Yii::$app->authManager;
$role = $auth->getRole($role); $role = $auth->getRole($role);
$auth->assign($role,$model->uid); $auth->assign($role, $model->uid);
$this->success('操作成功', $this->getForward()); $this->success('操作成功', $this->getForward());
} else { } else {
$this->error('操作错误'); $this->error('操作错误');
...@@ -116,4 +116,43 @@ class AdminController extends BaseController ...@@ -116,4 +116,43 @@ class AdminController extends BaseController
]); ]);
} }
public function actionEdit()
{
$model = new Admin();
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字符');
}
$model->setAttributes($data);
$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('操作错误');
}
}
return $this->render('add', [
'model' => $model,
'role' => Yii::$app->request->get('role', 'administrator')
]);
}
} }
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