diff --git a/app/Http/Admin/Views/course/edit_basic.volt b/app/Http/Admin/Views/course/edit_basic.volt index 30b7da5e..6cbd7fd0 100644 --- a/app/Http/Admin/Views/course/edit_basic.volt +++ b/app/Http/Admin/Views/course/edit_basic.volt @@ -58,7 +58,7 @@ {{ partial('partials/cover_uploader') }} -{{ javascript_include('lib/xm-select.js') }} +{{ js_include('lib/xm-select.js') }} ' . PHP_EOL; +} diff --git a/app/Providers/Cache.php b/app/Providers/Cache.php index 2043ec16..ce3b676f 100644 --- a/app/Providers/Cache.php +++ b/app/Providers/Cache.php @@ -25,8 +25,6 @@ class Cache extends Provider 'port' => $config->redis->port, 'auth' => $config->redis->auth, 'index' => $config->redis->index, - 'prefix' => $config->redis->prefix, - 'persistent' => $config->redis->persistent, ]); }); } diff --git a/app/Providers/Session.php b/app/Providers/Session.php index 8b9eb6f1..6b50eca9 100644 --- a/app/Providers/Session.php +++ b/app/Providers/Session.php @@ -20,9 +20,7 @@ class Session extends Provider 'port' => $config->redis->port, 'auth' => $config->redis->auth, 'index' => $config->redis->index, - 'prefix' => $config->session->prefix, 'lifetime' => $config->session->lifetime, - 'persistent' => $config->redis->persistent, ]); $session->start(); diff --git a/app/Providers/Url.php b/app/Providers/Url.php index 6a934dfe..42b739d3 100644 --- a/app/Providers/Url.php +++ b/app/Providers/Url.php @@ -17,9 +17,9 @@ class Url extends Provider $url = new UrlResolver(); - $url->setBaseUri($config->url->base); + $url->setBaseUri($config->base_uri); - $url->setStaticBaseUri($config->url->static); + $url->setStaticBaseUri($config->static_base_uri); return $url; }); diff --git a/app/Providers/Volt.php b/app/Providers/Volt.php index c6711204..2b79cf45 100644 --- a/app/Providers/Volt.php +++ b/app/Providers/Volt.php @@ -22,6 +22,14 @@ class Volt extends Provider $compiler = $volt->getCompiler(); + $compiler->addFunction('css_link', function ($resolvedArgs) { + return 'kg_css_link(' . $resolvedArgs . ')'; + }); + + $compiler->addFunction('js_include', function ($resolvedArgs) { + return 'kg_js_include(' . $resolvedArgs . ')'; + }); + $compiler->addFunction('substr', function ($resolvedArgs) { return 'kg_substr(' . $resolvedArgs . ')'; }); diff --git a/app/Services/Auth/Admin.php b/app/Services/Auth/Admin.php index 8f55a4da..ee2da466 100644 --- a/app/Services/Auth/Admin.php +++ b/app/Services/Auth/Admin.php @@ -17,7 +17,7 @@ class Admin extends AuthService $role = $roleRepo->findById($user->admin_role); - $root = $role->id == RoleModel::ROLE_ROOT ? 1 : 0; + $root = $role->id == RoleModel::ROLE_ROOT; $authInfo = [ 'id' => $user->id, @@ -44,9 +44,9 @@ class Admin extends AuthService $authInfo = $this->session->get($authKey); - $items = $authInfo ? $authInfo : []; + if (!$authInfo) return null; - return new Collection($items); + return new Collection($authInfo); } public function getAuthKey() diff --git a/app/Services/Auth/Api.php b/app/Services/Auth/Api.php index 85ec9c0f..94807194 100644 --- a/app/Services/Auth/Api.php +++ b/app/Services/Auth/Api.php @@ -63,9 +63,17 @@ class Api extends AuthService $authInfo = $cache->get($key); - $items = $authInfo ? $authInfo : []; + if (!$authInfo) return null; - return new Collection($items); + return new Collection($authInfo); + } + + /** + * @return RedisCache + */ + protected function getCache() + { + return $this->getDI()->get('cache'); } protected function getAuthToken() @@ -78,12 +86,4 @@ class Api extends AuthService return "access_token:{$token}"; } - /** - * @return RedisCache - */ - protected function getCache() - { - return $this->getDI()->get('cache'); - } - } diff --git a/app/Services/Auth/Html5.php b/app/Services/Auth/Html5.php index c2a5efab..02e91dab 100644 --- a/app/Services/Auth/Html5.php +++ b/app/Services/Auth/Html5.php @@ -34,9 +34,9 @@ class Html5 extends AuthService $authInfo = $this->session->get($authKey); - $items = $authInfo ? $authInfo : []; + if (!$authInfo) return null; - return new Collection($items); + return new Collection($authInfo); } public function getAuthKey() diff --git a/app/Services/Auth/Web.php b/app/Services/Auth/Web.php index 8e261d45..bcf099bd 100644 --- a/app/Services/Auth/Web.php +++ b/app/Services/Auth/Web.php @@ -9,11 +9,6 @@ use Yansongda\Supports\Collection; class Web extends AuthService { - /** - * 写入会话 - * - * @param UserModel $user - */ public function saveAuthInfo(UserModel $user) { $authKey = $this->getAuthKey(); @@ -26,9 +21,6 @@ class Web extends AuthService $this->session->set($authKey, $authInfo); } - /** - * 清除会话 - */ public function clearAuthInfo() { $authKey = $this->getAuthKey(); @@ -36,27 +28,17 @@ class Web extends AuthService $this->session->remove($authKey); } - /** - * 读取会话 - * - * @return Collection - */ public function getAuthInfo() { $authKey = $this->getAuthKey(); $authInfo = $this->session->get($authKey); - $items = $authInfo ? $authInfo : []; + if (!$authInfo) return null; - return new Collection($items); + return new Collection($authInfo); } - /** - * 获取会话键值 - * - * @return string - */ public function getAuthKey() { return 'web_auth_info'; diff --git a/app/Services/Frontend/Service.php b/app/Services/Frontend/Service.php index f06a2aa2..64000c70 100644 --- a/app/Services/Frontend/Service.php +++ b/app/Services/Frontend/Service.php @@ -32,8 +32,6 @@ class Service extends Component $validator->checkAuthUser($authUser); - dd($authUser); - $userRepo = new UserRepo(); return $userRepo->findById($authUser['id']); diff --git a/app/Validators/Validator.php b/app/Validators/Validator.php index f12f66ea..77348a08 100644 --- a/app/Validators/Validator.php +++ b/app/Validators/Validator.php @@ -9,13 +9,11 @@ use Phalcon\Mvc\User\Component; class Validator extends Component { - public function checkAuthUser($user) + public function checkAuthUser($authUser) { - if (empty($user['id'])) { - throw new UnauthorizedException('sys.auth_user_failed'); + if (empty($authUser['id'])) { + throw new UnauthorizedException('sys.auth_failed'); } - - return $user; } public function checkOwner($userId, $ownerId) diff --git a/config/config.php.default b/config/config.default.php similarity index 74% rename from config/config.php.default rename to config/config.default.php index 00edbcb7..fab3457c 100644 --- a/config/config.php.default +++ b/config/config.default.php @@ -20,12 +20,17 @@ $config['timezone'] = 'Asia/Shanghai'; /** * 网站根地址,必须以"/"结尾 */ -$config['url']['base'] = '/'; +$config['base_uri'] = '/'; /** - * 静态资源地址,必须以"/"结尾 + * 静态资源根地址,必须以"/"结尾 */ -$config['url']['static'] = '/static/'; +$config['static_base_uri'] = '/static/'; + +/** + * 静态资源版本 + */ +$config['static_version'] = '202004080830'; /** * 数据库主机名 @@ -78,24 +83,9 @@ $config['redis']['auth'] = '1qaz2wsx3edc'; $config['redis']['index'] = 0; /** - * redis长链接 + * 缓存有效期(秒) */ -$config['redis']['persistent'] = false; - -/** - * redis键前缀 - */ -$config['redis']['prefix'] = ''; - -/** - * redis有限期(秒) - */ -$config['redis']['lifetime'] = 7 * 86400; - -/** - * 会话键前缀 - */ -$config['session']['prefix'] = ':session:'; +$config['redis']['lifetime'] = 24 * 3600; /** * 会话有效期(秒) diff --git a/config/errors.php b/config/errors.php index 5a8b07b1..190bbd0e 100644 --- a/config/errors.php +++ b/config/errors.php @@ -6,9 +6,9 @@ $error = []; * 通用相关 */ $error['sys.uri_not_found'] = '资源地址不存在'; -$error['sys.invalid_referer'] = '无效的请求来源'; -$error['sys.auth_user_failed'] = '用户认证失败'; -$error['sys.access_denied'] = '访问被拒绝'; +$error['sys.invalid_referer'] = '非法的请求来源'; +$error['sys.auth_failed'] = '认证失败'; +$error['sys.access_denied'] = '拒绝访问'; $error['sys.unknown_error'] = '未知错误'; /** diff --git a/config/xs.course.ini.default b/config/xs.course.default.ini similarity index 100% rename from config/xs.course.ini.default rename to config/xs.course.default.ini