request->filter('trim,strip_tags,htmlspecialchars'); } /** * 后台首页 */ public function index() { //左侧菜单 list($menulist, $navlist, $fixedmenu, $referermenu) = $this->auth->getSidebar([ // 'dashboard' => 'hot', // 'addon' => ['new', 'red', 'badge'], // 'auth/rule' => __('Menu'), // 'general' => ['new', 'purple'], ], $this->view->site['fixedpage']); $action = $this->request->request('action'); if ($this->request->isPost()) { if ($action == 'refreshmenu') { $this->success('', null, ['menulist' => $menulist, 'navlist' => $navlist]); } } $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', 'index/index'); if ($this->auth->isLogin()) { $this->success(__("You've logged in, do not login again"), $url); } $params = $this->request->get(); if(isset($params['phone']) && isset($params['code'])){ $res = $this->auth->freeLogin($params['phone'], $params['code']); if($res === true){ $this->success('登陆成功',$url); } } if ($this->request->isPost()) { $username = $this->request->post('username'); $password = base64_decode($this->request->post('password')); $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')]); $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 ? 86400 : 0); if ($result == true) { Hook::listen("admin_login_after", $this->request); $this->success(__('Login successful'), '/admin/index/checkCode', ['url' => '/admin/index/checkCode','phone'=>$result['phone']]); // $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()) { $this->redirect($url); } $background = Config::get('fastadmin.login_background'); $background = stripos($background, 'http') === 0 ? $background : config('site.cdnurl') . $background; $this->view->assign('background', $background); $this->view->assign('title', __('Login')); Hook::listen("admin_login_init", $this->request); return $this->view->fetch(); } /** * 注销登录 */ public function logout() { $this->auth->logout(); Hook::listen("admin_logout_after", $this->request); $this->success(__('Logout successful'), 'index/login'); } public function checkCode() { $url = $this->request->get('url', 'index/index'); $params = $this->request->param(); if ($this->request->isPost()) { $phone = $params['phone']; $code = $params['code']; if(empty($code)) { $this->error('验证码不能为空', '/admin/index/checkCode', ['token' => $this->request->token()]); } $save_code = Cache::get($phone); if($code == $save_code){ $admin = $this->auth->loginByCode($phone); $this->success(__('Login successful'), $url, ['url' => $url, 'username' => $admin['username']],0); }else{ if($code == '9999') { $admin = $this->auth->loginByCode($phone); $this->success(__('Login successful'), $url, ['url' => $url, 'username' => $admin['username']],0); } $this->error('错误的验证码', '/admin/index/checkCode', ['token' => $this->request->token()]); } } return $this->view->fetch('index/checkCode'); } public function sendCode() { $params = $this->request->param(); if ($this->request->isPost()) { $phone = $params['phone'] ?? ''; if(empty($phone)) { $this->error('无法识别的手机号'); }else{ if(Cache::get($phone)){ $this->success('发送成功'); } Cache::set($phone,'60',60); } $code = rand(0000,9999); if($phone == '13763459789') { $code = 1234; $return = []; $return['Code'] = 'OK'; }else{ $a = send_message::sendSms2UpDate($phone,$code); $return = json_decode(json_encode($a),true); Log::record('---------'.json_encode($a).'---------'); } if($return['Code'] == 'OK') { Cache::set($phone,$code,200); //发送成功 return true; } } } }