request->filter('trim,strip_tags,htmlspecialchars'); } /** * 后台首页 */ public function index() { $cookieArr = ['adminskin' => "/^skin\-([a-z\-]+)\$/i", 'multiplenav' => "/^(0|1)\$/", 'multipletab' => "/^(0|1)\$/", 'show_submenu' => "/^(0|1)\$/"]; foreach ($cookieArr as $key => $regex) { $cookieValue = $this->request->cookie($key); if (!is_null($cookieValue) && preg_match($regex, $cookieValue)) { config('fastadmin.' . $key, $cookieValue); } } $userRule = ["*","general","category","addon","auth","general/config","general/attachment","general/profile","auth/admin","auth/adminlog","auth/group","auth/rule", "dashboard/index","dashboard/add","dashboard/del","dashboard/edit","dashboard/multi","general/config/index","general/config/add","general/config/edit","general/config/del","general/config/multi", "general/attachment/index","general/attachment/select","general/attachment/add","general/attachment/edit","general/attachment/del","general/attachment/multi", "general/profile/index","general/profile/update","general/profile/add","general/profile/edit","general/profile/del","general/profile/multi", "category/index","category/add","category/edit","category/del","category/multi","auth/admin/index","auth/admin/add","auth/admin/edit","auth/admin/del", "auth/adminlog/index","auth/adminlog/detail","auth/adminlog/del","auth/group/index","auth/group/add","auth/group/edit","auth/group/del","auth/rule/index", "auth/rule/add","auth/rule/edit","auth/rule/del","addon/index","addon/add","addon/edit","addon/del","addon/downloaded","addon/state","addon/config", "addon/refresh","addon/multi","user","user/user","user/user/index","user/user/edit","user/user/add","user/user/del","user/user/multi", "user/group","user/group/add","user/group/edit","user/group/index","user/group/del","user/group/multi","user/rule","user/rule/index","user/rule/del","user/rule/add","user/rule/edit","user/rule/multi", "command","command/index","command/add","command/detail","command/command","command/execute","command/del","command/multi","firm","firm/index","firm/add","firm/edit","firm/del","firm/multi", "firmbigcategory","firmbigcategory/index","firmbigcategory/add","firmbigcategory/edit","firmbigcategory/del","firmbigcategory/multi","kefuguanli", "firm","firm/index","firm/add","firm/edit","firm/del","firm/multi","aicustomerservice","aicustomerservice/index","aicustomerservice/add","aicustomerservice/edit","aicustomerservice/del","aicustomerservice/multi", "mattertemplate","mattertemplate/index","mattertemplate/add","mattertemplate/edit","mattertemplate/del","mattertemplate/multi","jichuguanli","firmcustomerorigin","firmcustomerorigin/index","firmduty","firmduty/index", "firmstoreprojectsone","firmstoreprojectsone/index","firmtags","firmtags/index","aicustomerservicefirmstorelist","aicustomerservicefirmstorelist/index","mattertemplatecategorization","mattertemplatecategorization/index"]; //左侧菜单 list($menulist, $navlist, $fixedmenu, $referermenu) = $this->auth->getSidebar([ 'dashboard' => 'hot', 'addon' => ['new', 'red', 'badge'], 'auth/rule' => __('Menu'), ], $this->view->site['fixedpage'],$userRule); $action = $this->request->request('action'); if ($this->request->isPost()) { if ($action == 'refreshmenu') { $this->success('', null, ['menulist' => $menulist, 'navlist' => $navlist]); } } $this->assignconfig('cookie', ['prefix' => config('cookie.prefix')]); $this->view->assign('menulist', $menulist); $this->view->assign('navlist', $navlist); $this->view->assign('fixedmenu', $fixedmenu); $this->view->assign('referermenu', $referermenu); $this->view->assign('title', __('Home')); return $this->view->fetch(); } /** * 管理员登录 */ public function login() { $url = $this->request->get('url', '', 'url_clean'); $url = $url ?: 'index/index'; if ($this->auth->isLogin()) { $this->success(__("You've logged in, do not login again"), $url); } //保持会话有效时长,单位:小时 $keeyloginhours = 24; if ($this->request->isPost()) { $username = $this->request->post('username'); $password = $this->request->post('password', '', null); $keeplogin = $this->request->post('keeplogin'); $token = $this->request->post('__token__'); $rule = [ 'username' => 'require|length:3,30', 'password' => 'require|length:3,30', '__token__' => 'require|token', ]; $data = [ 'username' => $username, 'password' => $password, '__token__' => $token, ]; if (Config::get('fastadmin.login_captcha')) { $rule['captcha'] = 'require|captcha'; $data['captcha'] = $this->request->post('captcha'); } $validate = new Validate($rule, [], ['username' => __('Username'), 'password' => __('Password'), 'captcha' => __('Captcha')]); $result = $validate->check($data); if (!$result) { $this->error($validate->getError(), $url, ['token' => $this->request->token()]); } AdminLog::setTitle(__('Login')); $result = $this->auth->login($username, $password, $keeplogin ? $keeyloginhours * 3600 : 0); if ($result === true) { Hook::listen("admin_login_after", $this->request); $this->success(__('Login successful'), $url, ['url' => $url, 'id' => $this->auth->id, 'username' => $username, 'avatar' => $this->auth->avatar]); } else { $msg = $this->auth->getError(); $msg = $msg ? $msg : __('Username or password is incorrect'); $this->error($msg, $url, ['token' => $this->request->token()]); } } // 根据客户端的cookie,判断是否可以自动登录 if ($this->auth->autologin()) { Session::delete("referer"); $this->redirect($url); } $background = Config::get('fastadmin.login_background'); $background = $background ? (stripos($background, 'http') === 0 ? $background : config('site.cdnurl') . $background) : ''; $this->view->assign('keeyloginhours', $keeyloginhours); $this->view->assign('background', $background); $this->view->assign('title', __('Login')); Hook::listen("admin_login_init", $this->request); return $this->view->fetch(); } /** * 退出登录 */ public function logout() { if ($this->request->isPost()) { $this->auth->logout(); Hook::listen("admin_logout_after", $this->request); $this->success(__('Logout successful'), 'index/login'); } $html = "
" . token() . "
"; $html .= ""; return $html; } }