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)) { // 皮肤由系统风格强制,忽略 cookie 覆盖 if ($key === 'adminskin') { continue; } config('fastadmin.' . $key, $cookieValue); } } // 按登录系统再次套用风格(覆盖 cookie) $theme = SystemLogin::applyTheme($this->auth); $this->view->assign($theme); //左侧菜单(不显示 hot/new 等角标) list($menulist, $navlist, $fixedmenu, $referermenu) = $this->auth->getSidebar([ ], $this->view->site['fixedpage']); $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(); } /** * 登录页 login.html:按 mproc.login_page_system 锁定可登录账号与风格 */ public function login() { SystemLogin::loadConfig(); $systemKey = SystemLogin::normalizeKey((string)Config::get('mproc.login_page_system')); return $this->doSystemLogin($systemKey); } /** * 兼容旧链接 */ public function cockpitlogin() { $this->redirect('index/login', $this->request->get(), 302); } /** * @param string $systemKey collab|cockpit */ protected function doSystemLogin(string $systemKey) { SystemLogin::loadConfig(); $systemKey = SystemLogin::normalizeKey($systemKey); $url = $this->request->get('url', '', 'url_clean'); $url = $url ?: 'index/index'; $sysName = (string)SystemLogin::option($systemKey, 'name', ''); if ($sysName === '') { $sysName = $systemKey === 'cockpit' ? '生产经营驾驶舱系统' : '生产协同系统'; } if ($this->auth->isLogin()) { if (!SystemLogin::belongsTo($this->auth, (int)$this->auth->id, $systemKey)) { $this->auth->logout(); Session::delete('login_system'); } else { Session::set('login_system', $systemKey); $this->success(__("You've logged in, do not login again"), $url); } } //保持会话有效时长,单位:小时(与 config fastadmin.keeplogin_hours 一致) $keeyloginhours = (int)Config::get('fastadmin.keeplogin_hours'); if ($keeyloginhours <= 0) { $keeyloginhours = 72; } if ($this->request->isPost()) { $username = $this->request->post('username'); $password = $this->request->post('password', '', null); $token = $this->request->post('__token__'); $rule = [ 'username' => 'require|length:3,30', 'password' => 'require|length:4,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') . '-' . $sysName); // 默认保持登录 72 小时(登录页无「记住我」勾选时也生效,避免频繁掉线) $keeptime = $keeyloginhours * 3600; $result = $this->auth->login($username, $password, $keeptime); if ($result === true) { if (!SystemLogin::belongsTo($this->auth, (int)$this->auth->id, $systemKey)) { $this->auth->logout(); Session::delete('login_system'); $this->error('登录账号不存在', $url, ['token' => $this->request->token()]); } Session::set('login_system', $systemKey); Hook::listen("admin_login_after", $this->request); $this->success(__('Login successful'), $url, ['url' => $url, 'id' => $this->auth->id, 'username' => $username, 'avatar' => resolve_admin_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()) { if (!SystemLogin::belongsTo($this->auth, (int)$this->auth->id, $systemKey)) { $this->auth->logout(); Session::delete('login_system'); } else { Session::set('login_system', $systemKey); 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('login_system', $systemKey); $this->view->assign('title', $sysName . ' - ' . __('Login')); Hook::listen("admin_login_init", $this->request); return $this->view->fetch('login'); } /** * 退出登录 */ public function logout() { if ($this->request->isPost()) { $this->auth->logout(); Session::delete('login_system'); Hook::listen("admin_logout_after", $this->request); $this->redirect('index/login'); } $html = "
"; $html .= ""; return $html; } }