/** * * @param array $POST[] 表单提交管理员信息 * 添加管理员 */ public function actionCreateAdmin() { //菜单权限检测 Yii::$app->util->adminAuth() ? '' : $this->redirect('/admin/login'); if ($params = Yii::$app->request->post()) { //密码复杂度判断 $pattern = '/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{8,16}$/'; $re = preg_match($pattern, $params['password']); if (!$re) { Yii::$app->util->msg('密码8-16,必须包含字母'); } //验证 if (empty($params['user_name']) || empty($params['password']) || empty($params['repassword'])) { Yii::$app->util->msg('参数错误'); } else { if ($params['password'] != $params['repassword']) { Yii::$app->util->msg('两次密码不一致'); } } //验证用户是否存在 if (Admin::userExists($params['user_name'])) { Yii::$app->util->msg('该用户已经存在'); } $str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; $salt = substr(str_shuffle($str), 0, 8); $options = ['user_name' => $params['user_name'], 'salt' => $salt, 'password' => Yii::$app->util->passwordEncode($params['password'], $salt), 'auth' => isset($params['auth']) ? json_encode($params['auth']) : '']; $mAdmin = new Admin(); if ($mAdmin->store($options)) { return $this->redirect('admin-list'); } else { Yii::$app->util->msg('入库错误'); } } else { // $session = Yii::$app->session; // $session->isActive ? '' : $session->open(); // $ids = $session->get('admin'); // $session->close(); // $ids = json_decode($ids['auth']); $mMenu = new Menu(); $data = $mMenu->menu(); return $this->render('create', ['data' => $data]); } }