first commit

This commit is contained in:
yanwenwu 2019-12-22 09:37:52 +08:00
parent cf1dedabd4
commit b27ef2570a
359 changed files with 34726 additions and 758 deletions

27
.gitignore vendored
View File

@ -2,5 +2,30 @@
/.vscode /.vscode
/vendor /vendor
/database /database
*.log *.log
.env .env
# view
/view/catch-admin/.DS_Store
/view/catch-admin/node_modules
/view/catch-admin/dist
# local env files
/view/catch-admin/.env.local
/view/catch-admin/.env.*.local
# Log files
/view/catch-admin/npm-debug.log*
/view/catch-admin/yarn-debug.log*
/view/catch-admin/yarn-error.log*
# Editor directories and files
/view/catch-admin/.idea
/view/catch-admin/.vscode
/view/catch-admin/*.suo
/view/catch-admin/*.ntvs*
/view/catch-admin/*.njsproj
/view/catch-admin/*.sln
/view/catch-admin/*.sw*

View File

@ -1,7 +1,6 @@
## CatchAdmin ## CatchAdmin
## 5.1 版本的请使用 tag1.0 版本 ## 这是 vue 分支 开发中
## 新版后台在开发中 请不要使用
### 环境要求 ### 环境要求
- php7.1+ (需以下扩展) - php7.1+ (需以下扩展)
- mbstring - mbstring

View File

@ -56,10 +56,7 @@ class ExceptionHandle extends Handle
*/ */
public function render($request, Throwable $e): Response public function render($request, Throwable $e): Response
{ {
// if ($e instanceof CatchException){
return CatchResponse::fail($e->getMessage(), $e->getCode());
// }
// 其他错误交给系统处理 // 其他错误交给系统处理
//return parent::render($request, $e); return parent::render($request, $e);
} }
} }

View File

@ -6,5 +6,6 @@ return [
// 多语言加载 // 多语言加载
// \think\middleware\LoadLangPack::class, // \think\middleware\LoadLangPack::class,
// Session初始化 // Session初始化
\think\middleware\SessionInit::class // \think\middleware\SessionInit::class
\think\middleware\AllowCrossDomain::class,
]; ];

View File

@ -1,5 +1,4 @@
<?php <?php
return [ return [
\jaguarjack\think\module\ThinkModuleService::class,
\catchAdmin\CatchAdminService::class, \catchAdmin\CatchAdminService::class,
]; ];

View File

@ -35,12 +35,14 @@ class Index extends CatchController
public function login(LoginRequest $request) public function login(LoginRequest $request)
{ {
$params = $request->param(); $params = $request->param();
$isSucceed = Auth::login($params); $token = Auth::login($params);
// 登录事件 // 登录事件
$params['success'] = $isSucceed; $params['success'] = $token;
event('loginLog', $params); event('loginLog', $params);
return $isSucceed ? CatchResponse::success('', '登录成功') : return $token ? CatchResponse::success([
'token' => $token,
], '登录成功') :
CatchResponse::success('', '登录失败'); CatchResponse::success('', '登录失败');
} }

View File

@ -11,7 +11,7 @@ class LoginRequest extends CatchRequest
return [ return [
'email|用户名' => 'email', 'email|用户名' => 'email',
'password|密码' => 'require', 'password|密码' => 'require',
'captcha|验证码' => 'require|captcha' // 'captcha|验证码' => 'require|captcha'
]; ];
} }

View File

@ -56,11 +56,20 @@ class Roles extends CatchModel
/** /**
* *
* @time 2019年12月08日 * @time 2019年12月08日
* @param array $condition
* @param array $field
* @return mixed * @return mixed
*/ */
public function getPermissions() public function getPermissions($condition = [], $field = [])
{ {
return $this->permissions()->select(); return $this->permissions()
->when(!empty($field), function ($query) use ($field){
$query->field($field);
})
->when(!empty($condition), function ($query) use ($condition){
$query->where($condition);
})
->select();
} }
/** /**

View File

@ -2,14 +2,16 @@
namespace catchAdmin\user; namespace catchAdmin\user;
use catchAdmin\permissions\model\Permissions; use catchAdmin\permissions\model\Permissions;
use catchAdmin\permissions\model\Roles;
use catchAdmin\user\model\Users; use catchAdmin\user\model\Users;
use catcher\exceptions\LoginFailedException; use catcher\exceptions\LoginFailedException;
use catcher\Tree;
use thans\jwt\facade\JWTAuth;
use think\facade\Session; use think\facade\Session;
class Auth class Auth
{ {
protected const USER_KEY = 'admin_user'; protected const USER_ID = 'catch_uid';
/** /**
* 登陆 * 登陆
* *
@ -42,9 +44,9 @@ class Auth
$user->last_login_time = time(); $user->last_login_time = time();
$user->save(); $user->save();
Session::set(self::getLoginUserKey(), $user); // Session::set(self::getLoginUserKey(), $user);
return true; return JWTAuth::builder([self::USER_ID => $user->id]);
} }
/** /**
@ -67,7 +69,27 @@ class Auth
*/ */
public static function user() public static function user()
{ {
return Session::get(self::getLoginUserKey(), null); $user = Users::where('id', JWTAuth::auth()[self::USER_ID])
->field(['id', 'username', 'status'])->find();
return $user;
}
public static function getUserInfo()
{
$user = self::user();
$roles = $user->getRoles();
foreach ($roles as &$role) {
$role['permissions'] = Roles::where('id', $role['id'])->find()->getPermissions([
'type' => Permissions::MENU_TYPE
], ['permission_name', 'route']);
}
$user->roles = $roles;
return $user;
} }
/** /**
@ -77,7 +99,7 @@ class Auth
*/ */
protected static function getLoginUserKey(): string protected static function getLoginUserKey(): string
{ {
return md5(self::USER_KEY); // return md5(self::USER_KEY);
} }
/** /**

View File

@ -0,0 +1,34 @@
<?php
namespace catchAdmin\user;
use catcher\Code;
use catcher\exceptions\FailedException;
use thans\jwt\exception\TokenBlacklistException;
use thans\jwt\exception\TokenExpiredException;
use thans\jwt\exception\TokenInvalidException;
use thans\jwt\facade\JWTAuth;
use think\Middleware;
class AuthTokenMiddleware extends Middleware
{
public function handle($request, \Closure $next)
{
try {
JWTAuth::auth();
} catch (\Exception $e) {
if ($e instanceof TokenExpiredException) {
throw new FailedException('token 过期', Code::LOST_LOGIN);
}
if ($e instanceof TokenBlacklistException) {
throw new FailedException('token 被加入黑名单', Code::LOST_LOGIN);
}
if ($e instanceof TokenInvalidException) {
throw new FailedException('token 不合法', Code::LOST_LOGIN);
}
throw new FailedException('登录用户不合法', Code::LOST_LOGIN);
}
return $next($request);
}
}

View File

@ -3,6 +3,7 @@ namespace catchAdmin\user\controller;
use app\Request; use app\Request;
use catchAdmin\permissions\model\Roles; use catchAdmin\permissions\model\Roles;
use catchAdmin\user\Auth;
use catchAdmin\user\model\Users; use catchAdmin\user\model\Users;
use catchAdmin\user\request\CreateRequest; use catchAdmin\user\request\CreateRequest;
use catchAdmin\user\request\UpdateRequest; use catchAdmin\user\request\UpdateRequest;
@ -23,19 +24,20 @@ class User extends CatchController
/** /**
* *
* @time 2019年12月04日 * @time 2019年12月04日
* @throws \Exception * @param Request $request
* @return string * @return string
* @throws \think\db\exception\DbException
*/ */
public function index() public function index(Request $request)
{
return $this->fetch();
}
public function list(Request $request)
{ {
return CatchResponse::paginate($this->user->getList($request->param())); return CatchResponse::paginate($this->user->getList($request->param()));
} }
public function info()
{
return CatchResponse::success(Auth::getUserInfo());
}
/** /**
* *
* @time 2019年12月06日 * @time 2019年12月06日

View File

@ -13,6 +13,7 @@ class CreateRequest extends CatchRequest
return [ return [
'username|用户名' => 'require|max:20', 'username|用户名' => 'require|max:20',
'password|密码' => 'require|min:5|max:12', 'password|密码' => 'require|min:5|max:12',
'passwordConfirm|密码' => 'confirm:password',
'email|邮箱' => 'require|email|unique:'.Users::class, 'email|邮箱' => 'require|email|unique:'.Users::class,
]; ];
} }

View File

@ -1,8 +1,6 @@
<?php <?php
$router->resource('user', '\catchAdmin\user\controller\User'); $router->resource('user', '\catchAdmin\user\controller\User');
// 用户列表
$router->get('users', '\catchAdmin\user\controller\User@list');
// 切换状态 // 切换状态
$router->put('user/switch/status/<id>', '\catchAdmin\user\controller\User@switchStatus'); $router->put('user/switch/status/<id>', '\catchAdmin\user\controller\User@switchStatus');
$router->put('user/recover/<id>', '\catchAdmin\user\controller\User@recover'); $router->put('user/recover/<id>', '\catchAdmin\user\controller\User@recover');

View File

@ -21,7 +21,8 @@
"topthink/think-orm": "^2.0", "topthink/think-orm": "^2.0",
"topthink/think-view": "^1.0", "topthink/think-view": "^1.0",
"topthink/think-migration": "^3.0", "topthink/think-migration": "^3.0",
"topthink/think-captcha": "^3.0" "topthink/think-captcha": "^3.0",
"thans/tp-jwt-auth": "^1.0"
}, },
"require-dev": { "require-dev": {
"symfony/var-dumper": "^4.2", "symfony/var-dumper": "^4.2",
@ -29,11 +30,11 @@
}, },
"autoload": { "autoload": {
"files": [ "files": [
"catchAdmin/helper.php" "catch/helper.php"
], ],
"psr-4": { "psr-4": {
"app\\": "app", "app\\": "app",
"catchAdmin\\": "catchAdmin", "catchAdmin\\": "catch",
"jaguarjack\\think\\module\\": "extend/think-module/src" "jaguarjack\\think\\module\\": "extend/think-module/src"
}, },
"psr-0": { "psr-0": {

168
composer.lock generated
View File

@ -1,11 +1,72 @@
{ {
"_readme": [ "_readme": [
"This file locks the dependencies of your project to a known state", "This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "b877160c14919bce0ee4bc7ed00317a2", "content-hash": "867a29731eb9f56d75d75bd32e8a9f37",
"packages": [ "packages": [
{
"name": "lcobucci/jwt",
"version": "3.3.1",
"source": {
"type": "git",
"url": "https://github.com/lcobucci/jwt.git",
"reference": "a11ec5f4b4d75d1fcd04e133dede4c317aac9e18"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/lcobucci/jwt/zipball/a11ec5f4b4d75d1fcd04e133dede4c317aac9e18",
"reference": "a11ec5f4b4d75d1fcd04e133dede4c317aac9e18",
"shasum": "",
"mirrors": [
{
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
"preferred": true
}
]
},
"require": {
"ext-mbstring": "*",
"ext-openssl": "*",
"php": "^5.6 || ^7.0"
},
"require-dev": {
"mikey179/vfsstream": "~1.5",
"phpmd/phpmd": "~2.2",
"phpunit/php-invoker": "~1.1",
"phpunit/phpunit": "^5.7 || ^7.3",
"squizlabs/php_codesniffer": "~2.3"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.1-dev"
}
},
"autoload": {
"psr-4": {
"Lcobucci\\JWT\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Luís Otávio Cobucci Oblonczyk",
"email": "lcobucci@gmail.com",
"role": "Developer"
}
],
"description": "A simple library to work with JSON Web Token and JSON Web Signature",
"keywords": [
"JWS",
"jwt"
],
"time": "2019-05-24T18:30:49+00:00"
},
{ {
"name": "league/flysystem", "name": "league/flysystem",
"version": "1.0.57", "version": "1.0.57",
@ -151,16 +212,16 @@
}, },
{ {
"name": "opis/closure", "name": "opis/closure",
"version": "3.4.1", "version": "3.5.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/opis/closure.git", "url": "https://github.com/opis/closure.git",
"reference": "e79f851749c3caa836d7ccc01ede5828feb762c7" "reference": "93ebc5712cdad8d5f489b500c59d122df2e53969"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/opis/closure/zipball/e79f851749c3caa836d7ccc01ede5828feb762c7", "url": "https://api.github.com/repos/opis/closure/zipball/93ebc5712cdad8d5f489b500c59d122df2e53969",
"reference": "e79f851749c3caa836d7ccc01ede5828feb762c7", "reference": "93ebc5712cdad8d5f489b500c59d122df2e53969",
"shasum": "", "shasum": "",
"mirrors": [ "mirrors": [
{ {
@ -179,7 +240,7 @@
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-master": "3.3.x-dev" "dev-master": "3.5.x-dev"
} }
}, },
"autoload": { "autoload": {
@ -214,7 +275,7 @@
"serialization", "serialization",
"serialize" "serialize"
], ],
"time": "2019-10-19T18:38:51+00:00" "time": "2019-11-29T22:36:02+00:00"
}, },
{ {
"name": "psr/cache", "name": "psr/cache",
@ -430,6 +491,63 @@
], ],
"time": "2017-10-23T01:57:42+00:00" "time": "2017-10-23T01:57:42+00:00"
}, },
{
"name": "thans/tp-jwt-auth",
"version": "v1.0.6",
"source": {
"type": "git",
"url": "https://github.com/QThans/jwt-auth.git",
"reference": "34941e26acfff81f5d5392f76632b57ff3508a56"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/QThans/jwt-auth/zipball/34941e26acfff81f5d5392f76632b57ff3508a56",
"reference": "34941e26acfff81f5d5392f76632b57ff3508a56",
"shasum": "",
"mirrors": [
{
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
"preferred": true
}
]
},
"require": {
"lcobucci/jwt": "^3.3",
"php": "^7.0",
"topthink/framework": "^5.1.10 || ^6.0.0"
},
"type": "library",
"extra": {
"think": {
"services": [
"thans\\jwt\\Service"
],
"config": {
"jwt": "config/config.php"
}
}
},
"autoload": {
"psr-4": {
"thans\\jwt\\": "src"
},
"files": [
"src/helper.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Thans",
"email": "360641274@qq.com"
}
],
"description": "thinkphp jwt auth composer",
"time": "2019-12-03T14:28:46+00:00"
},
{ {
"name": "topthink/framework", "name": "topthink/framework",
"version": "v6.0.0", "version": "v6.0.0",
@ -795,16 +913,16 @@
"packages-dev": [ "packages-dev": [
{ {
"name": "symfony/polyfill-mbstring", "name": "symfony/polyfill-mbstring",
"version": "v1.12.0", "version": "v1.13.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/polyfill-mbstring.git", "url": "https://github.com/symfony/polyfill-mbstring.git",
"reference": "b42a2f66e8f1b15ccf25652c3424265923eb4f17" "reference": "7b4aab9743c30be783b73de055d24a39cf4b954f"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/b42a2f66e8f1b15ccf25652c3424265923eb4f17", "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/7b4aab9743c30be783b73de055d24a39cf4b954f",
"reference": "b42a2f66e8f1b15ccf25652c3424265923eb4f17", "reference": "7b4aab9743c30be783b73de055d24a39cf4b954f",
"shasum": "", "shasum": "",
"mirrors": [ "mirrors": [
{ {
@ -822,7 +940,7 @@
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-master": "1.12-dev" "dev-master": "1.13-dev"
} }
}, },
"autoload": { "autoload": {
@ -856,20 +974,20 @@
"portable", "portable",
"shim" "shim"
], ],
"time": "2019-08-06T08:03:45+00:00" "time": "2019-11-27T14:18:11+00:00"
}, },
{ {
"name": "symfony/polyfill-php72", "name": "symfony/polyfill-php72",
"version": "v1.12.0", "version": "v1.13.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/polyfill-php72.git", "url": "https://github.com/symfony/polyfill-php72.git",
"reference": "04ce3335667451138df4307d6a9b61565560199e" "reference": "66fea50f6cb37a35eea048d75a7d99a45b586038"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-php72/zipball/04ce3335667451138df4307d6a9b61565560199e", "url": "https://api.github.com/repos/symfony/polyfill-php72/zipball/66fea50f6cb37a35eea048d75a7d99a45b586038",
"reference": "04ce3335667451138df4307d6a9b61565560199e", "reference": "66fea50f6cb37a35eea048d75a7d99a45b586038",
"shasum": "", "shasum": "",
"mirrors": [ "mirrors": [
{ {
@ -884,7 +1002,7 @@
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-master": "1.12-dev" "dev-master": "1.13-dev"
} }
}, },
"autoload": { "autoload": {
@ -917,20 +1035,20 @@
"portable", "portable",
"shim" "shim"
], ],
"time": "2019-08-06T08:03:45+00:00" "time": "2019-11-27T13:56:44+00:00"
}, },
{ {
"name": "symfony/var-dumper", "name": "symfony/var-dumper",
"version": "v4.4.0", "version": "v4.4.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/var-dumper.git", "url": "https://github.com/symfony/var-dumper.git",
"reference": "eade2890f8b0eeb279b6cf41b50a10007294490f" "reference": "0a89a1dbbedd9fb2cfb2336556dec8305273c19a"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/var-dumper/zipball/eade2890f8b0eeb279b6cf41b50a10007294490f", "url": "https://api.github.com/repos/symfony/var-dumper/zipball/0a89a1dbbedd9fb2cfb2336556dec8305273c19a",
"reference": "eade2890f8b0eeb279b6cf41b50a10007294490f", "reference": "0a89a1dbbedd9fb2cfb2336556dec8305273c19a",
"shasum": "", "shasum": "",
"mirrors": [ "mirrors": [
{ {
@ -999,7 +1117,7 @@
"debug", "debug",
"dump" "dump"
], ],
"time": "2019-11-12T14:51:11+00:00" "time": "2019-11-28T13:33:56+00:00"
}, },
{ {
"name": "topthink/think-trace", "name": "topthink/think-trace",

View File

@ -9,5 +9,5 @@ return [
/** /**
* set error page * set error page
*/ */
'error' => root_path('catchAdmin/index/view/') . 'error.html', 'error' => root_path('catch/index/view/') . 'error.html',
]; ];

18
config/jwt.php Normal file
View File

@ -0,0 +1,18 @@
<?php
return [
'secret' => env('JWT_SECRET'),
//Asymmetric key
'public_key' => env('JWT_PUBLIC_KEY'),
'private_key' => env('JWT_PRIVATE_KEY'),
'password' => env('JWT_PASSWORD'),
//JWT time to live
'ttl' => env('JWT_TTL', 30 * 36000 * 24),
//Refresh time to live
'refresh_ttl' => env('JWT_REFRESH_TTL', 20160),
//JWT hashing algorithm
'algo' => env('JWT_ALGO', 'HS256'),
'blacklist_storage' => thans\jwt\provider\storage\Tp5::class,
];

View File

@ -5,7 +5,7 @@ use think\helper\Arr;
class CatchAdmin class CatchAdmin
{ {
public const NAME = 'catchAdmin'; public const NAME = 'catch';
/** /**
* *

View File

@ -16,7 +16,7 @@ class CatchResponse
* @param int $code * @param int $code
* @return \think\response\Json * @return \think\response\Json
*/ */
public static function success($data = [], $msg = 'success', $code = 10000): \think\response\Json public static function success($data = [], $msg = 'success', $code = Code::SUCCESS): \think\response\Json
{ {
return json([ return json([
'code' => $code, 'code' => $code,
@ -39,6 +39,7 @@ class CatchResponse
'msg' => 'success', 'msg' => 'success',
'count' => $list->total(), 'count' => $list->total(),
'current' => $list->currentPage(), 'current' => $list->currentPage(),
'limit' => $list->listRows(),
'data' => $list->getCollection(), 'data' => $list->getCollection(),
]); ]);
} }

13
extend/catcher/Code.php Normal file
View File

@ -0,0 +1,13 @@
<?php
namespace catcher;
class Code
{
public const SUCCESS = 10000; // 成功
public const LOST_LOGIN = 10001; // 登录失效
public const VALIDATE_FAILED = 10002; // 验证错误
public const PERMISSION_FORBIDDEN = 10003; // 权限禁止
public const LOGIN_FAILED = 10004; // 登录失败
public const FAILED = 10005; // 操作失败
}

View File

@ -49,7 +49,7 @@ class CompressPackageCommand extends Command
protected function zip($package): void protected function zip($package): void
{ {
if (!is_dir(CatchAdmin::directory() . $package)) { if (!is_dir(CatchAdmin::directory() . $package)) {
$package = $this->output->ask($this->input, sprintf('Can not find [%s] in catchAdmin directory, you should input package again', $package)); $package = $this->output->ask($this->input, sprintf('Can not find [%s] in catch directory, you should input package again', $package));
} }
if (!is_dir(CatchAdmin::directory() . $package)) { if (!is_dir(CatchAdmin::directory() . $package)) {

View File

@ -78,7 +78,7 @@ class ModelGeneratorCommand extends Command
{ {
return <<<EOT return <<<EOT
<?php <?php
namespace catchAdmin\{Module}\model; namespace catch\{Module}\model;
use cather\base\BaseModel; use cather\base\BaseModel;

View File

@ -3,6 +3,7 @@ declare (strict_types = 1);
namespace catcher\event; namespace catcher\event;
use catchAdmin\user\AuthTokenMiddleware;
use catcher\CatchAdmin; use catcher\CatchAdmin;
use think\Route; use think\Route;
@ -27,14 +28,17 @@ class LoadModuleRoutes
foreach ($routes as $route) { foreach ($routes as $route) {
include $route; include $route;
} }
}); })->middleware([AuthTokenMiddleware::class]);
} else { } else {
$router->group(function () use ($router, $routes) { $router->group(function () use ($router, $routes) {
foreach ($routes as $route) { foreach ($routes as $route) {
include $route; include $route;
} }
}); })->middleware([AuthTokenMiddleware::class]);
} }
// 单独加载登录
include CatchAdmin::moduleDirectory('login') . 'route.php';
} }
/** /**
@ -45,7 +49,7 @@ class LoadModuleRoutes
protected function getRoutes(): array protected function getRoutes(): array
{ {
$routes = CatchAdmin::getRoutes(); $routes = CatchAdmin::getRoutes();
array_push($routes, CatchAdmin::directory() . 'login' . DIRECTORY_SEPARATOR . 'route.php');
return $routes; return $routes;
} }
} }

View File

@ -1,5 +1,20 @@
<?php <?php
namespace catcher\exceptions; namespace catcher\exceptions;
abstract class CatchException extends \Exception use Exception;
{} use think\exception\HttpException;
abstract class CatchException extends HttpException
{
protected const HTTP_SUCCESS = 200;
public function __construct(string $message = '', int $code = 0, Exception $previous = null, array $headers = [], $statusCode = 0)
{
parent::__construct($statusCode, $message, $previous, $headers, $code);
}
public function getStatusCode()
{
return self::HTTP_SUCCESS;
}
}

View File

@ -1,7 +1,9 @@
<?php <?php
namespace catcher\exceptions; namespace catcher\exceptions;
use catcher\Code;
class FailedException extends CatchException class FailedException extends CatchException
{ {
protected $code = 10010; protected $code = Code::FAILED;
} }

View File

@ -1,7 +1,9 @@
<?php <?php
namespace catcher\exceptions; namespace catcher\exceptions;
use catcher\Code;
class LoginFailedException extends CatchException class LoginFailedException extends CatchException
{ {
protected $code = 10010; protected $code = Code::LOGIN_FAILED;
} }

View File

@ -1,9 +1,11 @@
<?php <?php
namespace catcher\exceptions; namespace catcher\exceptions;
use catcher\Code;
class PermissionForbiddenException extends CatchException class PermissionForbiddenException extends CatchException
{ {
protected $code = 10005; protected $code = Code::PERMISSION_FORBIDDEN;
protected $message = 'permission forbidden'; protected $message = 'permission forbidden';
} }

View File

@ -1,7 +1,9 @@
<?php <?php
namespace catcher\exceptions; namespace catcher\exceptions;
use catcher\Code;
class ValidateFailedException extends CatchException class ValidateFailedException extends CatchException
{ {
protected $code = 10001; protected $code = Code::VALIDATE_FAILED;
} }

View File

@ -1,19 +0,0 @@
{
"name": "jaguarjack/think-module",
"description": "thinkphp module",
"type": "library",
"license": "MIT",
"authors": [
{
"name": "jaguarjack",
"email": "njphper@gmail.com"
}
],
"autoload": {
"psr-4": {
"jaguarjack\\think\\module\\": "src"
}
},
"minimum-stability": "dev",
"require": {}
}

View File

@ -1,213 +0,0 @@
<?php
use Nwidart\Modules\Activators\FileActivator;
return [
/*
|--------------------------------------------------------------------------
| Module Namespace
|--------------------------------------------------------------------------
|
| Default module namespace.
|
*/
'namespace' => 'module',
/*
|--------------------------------------------------------------------------
| Module Stubs
|--------------------------------------------------------------------------
|
| Default module stubs.
|
*/
'stubs' => [
'enabled' => false,
'path' => base_path() . '/vendor/nwidart/laravel-modules/src/Commands/stubs',
'files' => [
'routes/web' => 'Routes/web.php',
'routes/api' => 'Routes/api.php',
'views/index' => 'Resources/views/index.blade.php',
'views/master' => 'Resources/views/layouts/master.blade.php',
'scaffold/config' => 'Config/config.php',
'composer' => 'composer.json',
'assets/js/app' => 'Resources/assets/js/app.js',
'assets/sass/app' => 'Resources/assets/sass/app.scss',
'webpack' => 'webpack.mix.js',
'package' => 'package.json',
],
'replacements' => [
'routes/web' => ['LOWER_NAME', 'STUDLY_NAME'],
'routes/api' => ['LOWER_NAME'],
'webpack' => ['LOWER_NAME'],
'json' => ['LOWER_NAME', 'STUDLY_NAME', 'MODULE_NAMESPACE', 'PROVIDER_NAMESPACE'],
'views/index' => ['LOWER_NAME'],
'views/master' => ['LOWER_NAME', 'STUDLY_NAME'],
'scaffold/config' => ['STUDLY_NAME'],
'composer' => [
'LOWER_NAME',
'STUDLY_NAME',
'VENDOR',
'AUTHOR_NAME',
'AUTHOR_EMAIL',
'MODULE_NAMESPACE',
'PROVIDER_NAMESPACE',
],
],
'gitkeep' => true,
],
'paths' => [
/*
|--------------------------------------------------------------------------
| Modules path
|--------------------------------------------------------------------------
|
| This path used for save the generated module. This path also will be added
| automatically to list of scanned folders.
|
*/
'module' => root_path('module'),
/*
|--------------------------------------------------------------------------
| Modules assets path
|--------------------------------------------------------------------------
|
| Here you may update the modules assets path.
|
*/
'assets' => public_path('module'),
/*
|--------------------------------------------------------------------------
| The migrations path
|--------------------------------------------------------------------------
|
| Where you run 'module:publish-migration' command, where do you publish the
| the migration files?
|
*/
'migration' => root_path('database/migrations'),
/*
|--------------------------------------------------------------------------
| Generator path
|--------------------------------------------------------------------------
| Customise the paths where the folders will be generated.
| Set the generate key to false to not generate that folder
*/
'generator' => [
'config' => ['path' => 'Config', 'generate' => true],
'command' => ['path' => 'Console', 'generate' => true],
'migration' => ['path' => 'Database/Migrations', 'generate' => true],
'seeder' => ['path' => 'Database/Seeders', 'generate' => true],
'factory' => ['path' => 'Database/factories', 'generate' => true],
'model' => ['path' => 'Entities', 'generate' => true],
'routes' => ['path' => 'Routes', 'generate' => true],
'controller' => ['path' => 'Http/Controllers', 'generate' => true],
'filter' => ['path' => 'Http/Middleware', 'generate' => true],
'request' => ['path' => 'Http/Requests', 'generate' => true],
'provider' => ['path' => 'Providers', 'generate' => true],
'assets' => ['path' => 'Resources/assets', 'generate' => true],
'lang' => ['path' => 'Resources/lang', 'generate' => true],
'views' => ['path' => 'Resources/views', 'generate' => true],
'test' => ['path' => 'Tests/Unit', 'generate' => true],
'test-feature' => ['path' => 'Tests/Feature', 'generate' => true],
'repository' => ['path' => 'Repositories', 'generate' => false],
'event' => ['path' => 'Events', 'generate' => false],
'listener' => ['path' => 'Listeners', 'generate' => false],
'policies' => ['path' => 'Policies', 'generate' => false],
'rules' => ['path' => 'Rules', 'generate' => false],
'jobs' => ['path' => 'Jobs', 'generate' => false],
'emails' => ['path' => 'Emails', 'generate' => false],
'notifications' => ['path' => 'Notifications', 'generate' => false],
'resource' => ['path' => 'Transformers', 'generate' => false],
],
],
/*
|--------------------------------------------------------------------------
| Scan Path
|--------------------------------------------------------------------------
|
| Here you define which folder will be scanned. By default will scan vendor
| directory. This is useful if you host the package in packagist website.
|
*/
'scan' => [
'enabled' => false,
'paths' => [
base_path('vendor/*/*'),
],
],
/*
|--------------------------------------------------------------------------
| Composer File Template
|--------------------------------------------------------------------------
|
| Here is the config for composer.json file, generated by this package
|
*/
'composer' => [
'vendor' => 'nwidart',
'author' => [
'name' => 'Nicolas Widart',
'email' => 'n.widart@gmail.com',
],
],
/*
|--------------------------------------------------------------------------
| Caching
|--------------------------------------------------------------------------
|
| Here is the config for setting up caching feature.
|
*/
'cache' => [
'enabled' => false,
'key' => 'laravel-modules',
'lifetime' => 60,
],
/*
|--------------------------------------------------------------------------
| Choose what laravel-modules will register as custom namespaces.
| Setting one to false will require you to register that part
| in your own Service Provider class.
|--------------------------------------------------------------------------
*/
'register' => [
'translations' => true,
/**
* load files on boot or register method
*
* Note: boot not compatible with asgardcms
*
* @example boot|register
*/
'files' => 'register',
],
/*
|--------------------------------------------------------------------------
| Activators
|--------------------------------------------------------------------------
|
| You can define new types of activators here, file, database etc. The only
| required parameter is 'class'.
| The file activator will store the activation status in storage/installed_modules
*/
'activators' => [
'file' => [
'class' => FileActivator::class,
'statuses-file' => base_path('modules_statuses.json'),
'cache-key' => 'activator.installed',
'cache-lifetime' => 604800,
],
],
'activator' => 'file',
];

View File

@ -1,17 +0,0 @@
<?php
namespace jaguarjack\think\module;
use jaguarjack\think\module\command\CreateModuleCommand;
use jaguarjack\think\module\command\DiscoverModuleServiceCommand;
use think\Service;
class ThinkModuleService extends Service
{
public function boot()
{
$this->commands([
CreateModuleCommand::class,
DiscoverModuleServiceCommand::class,
]);
}
}

View File

@ -1,131 +0,0 @@
<?php
namespace jaguarjack\think\module\command;
use catcher\CatchAdmin;
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\Output;
class CreateModuleCommand extends Command
{
protected $module;
protected $moduleDir;
protected $namespaces;
protected function configure()
{
$this->setName('module:create')
->addArgument('module', Argument::REQUIRED, 'module name')
->setDescription('create module service');
}
protected function execute(Input $input, Output $output)
{
$this->module = strtolower($input->getArgument('module'));
$this->moduleDir = CatchAdmin::moduleDirectory($this->module);
$this->namespaces = CatchAdmin::NAME . '\\\\' . $this->module . '\\\\';
$this->createController();
$this->createRequest();
$this->createModel();
// $this->createService();
$this->createView();
$this->createValidate();
$this->createRoute();
$this->moduleJson();
$output->warning('module created');
}
protected function createController()
{
mkdir($this->moduleDir . 'controller' . DIRECTORY_SEPARATOR);
return file_put_contents($this->moduleDir . 'controller' . DIRECTORY_SEPARATOR . 'Index.php', str_replace(
['{CLASS}', '{NAMESPACE}', '{MODULE}'],
['Index', $this->namespaces . 'controller', $this->module],
file_get_contents(__DIR__ . DIRECTORY_SEPARATOR .'stubs'.DIRECTORY_SEPARATOR. 'controller.stub')
));
}
protected function createModel()
{
}
protected function createView()
{
mkdir($this->moduleDir . DIRECTORY_SEPARATOR . 'view');
file_put_contents($this->moduleDir . DIRECTORY_SEPARATOR . 'view' . DIRECTORY_SEPARATOR . 'index.html', '');
file_put_contents($this->moduleDir . DIRECTORY_SEPARATOR . 'view' . DIRECTORY_SEPARATOR . 'create.html', '');
file_put_contents($this->moduleDir . DIRECTORY_SEPARATOR . 'view' . DIRECTORY_SEPARATOR . 'edit.html', '');
}
protected function createValidate()
{
$validatePath = $this->moduleDir . DIRECTORY_SEPARATOR . 'validate' . DIRECTORY_SEPARATOR;
mkdir($validatePath);
file_put_contents($validatePath . 'CreateValidate.php', str_replace(
['{Namespace}', '{Class}'],
[$this->namespaces . 'validate', 'Create'],
file_get_contents(__DIR__ . 'stubs' . DIRECTORY_SEPARATOR . 'validate.stub')));
file_put_contents($validatePath . 'UpdateValidate.php', str_replace(
['{Namespace}', '{Class}'],
[$this->namespaces . 'validate', 'Update'],
file_get_contents(__DIR__ . 'stubs' . DIRECTORY_SEPARATOR . 'validate.stub')));
}
protected function createRequest()
{
$requestPath = $this->moduleDir . DIRECTORY_SEPARATOR . 'request' . DIRECTORY_SEPARATOR;
mkdir($requestPath);
file_put_contents($validatePath . 'CreateRequest.php', str_replace(
['{Namespace}', '{Class}'],
[$this->namespaces . 'request', 'Create'],
file_get_contents(__DIR__ . 'stubs' . DIRECTORY_SEPARATOR . 'request.stub')));
file_put_contents($validatePath . 'UpdateRequest.php', str_replace(
['{Namespace}', '{Class}'],
[$this->namespaces . 'request', 'Update'],
file_get_contents(__DIR__ . 'stubs' . DIRECTORY_SEPARATOR . 'request.stub')));
}
protected function database()
{
mkdir($this->moduleDir . DIRECTORY_SEPARATOR . 'database');
mkdir($this->moduleDir . DIRECTORY_SEPARATOR . 'database'.DIRECTORY_SEPARATOR.'migrations');
mkdir($this->moduleDir . DIRECTORY_SEPARATOR . 'database'.DIRECTORY_SEPARATOR . 'seeds');
}
protected function moduleJson()
{
file_put_contents($this->moduleDir.DIRECTORY_SEPARATOR .'module.json', str_replace(
['{MODULE}', '{SERVICE}'],
[$this->module, $this->namespaces. ucfirst($this->module) . 'Service'],
file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'module.stub')));
}
protected function createRoute()
{
file_put_contents($this->moduleDir.DIRECTORY_SEPARATOR .'route.php',
file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'route.stub'));
}
protected function createService()
{
file_put_contents($this->moduleDir.DIRECTORY_SEPARATOR . ucfirst($this->module) . 'Service.php', str_replace(
['{CLASS}', '{NAMESPACE}'],
[ucfirst($this->module), $this->namespaces . '\\' . $this->module],
file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'provider.stub')));
}
}

View File

@ -1,83 +0,0 @@
<?php
namespace jaguarjack\think\module\command;
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;
class DiscoverModuleServiceCommand extends Command
{
protected function configure()
{
$this->setName('module:service')
->setDescription('discover module service');
}
protected function execute(Input $input, Output $output)
{
$this->getModuleServices();
$output->writeln('module service generator succeed!');
}
/**
* 获取模块
*
* @time 2019年11月27日
* @return bool
* @throws \ReflectionException
*/
protected function getModuleServices(): bool
{
$modules = glob(root_path('module') .'*');
$moduleServices = [];
foreach ($modules as $module) {
if (file_exists($module . DIRECTORY_SEPARATOR . 'module.json')) {
$moduleJson = file_get_contents($module . DIRECTORY_SEPARATOR . 'module.json');
$moduleServices = array_merge($moduleServices, \json_decode($moduleJson, true)['services']);
}
}
$moduleServices = $this->checkModuleService($moduleServices);
$header = '// This file is automatically generated at:' . date('Y-m-d H:i:s') . PHP_EOL . 'declare (strict_types = 1);' . PHP_EOL;
$content =
'<?php ' . PHP_EOL . $header . 'return ' .
var_export($moduleServices, true) . ';';
file_put_contents($this->app->getRootPath() . 'module/services.php', $content);
return true;
}
/**
*
* @time 2019年11月29日
* @param $moduleServices
* @throws \ReflectionException
* @return mixed
*/
protected function checkModuleService($moduleServices)
{
$new = [];
foreach ($moduleServices as $key => $service) {
$selfReflection = new \ReflectionClass($service);
// if service set property 'cache' && set cache => false
// the service will not be cached
// finally will boot it
if ($selfReflection->hasProperty('cache') && !$selfReflection->getProperty('cache')) {
$new[$service] = true;
} else {
$new[$service] = false;
}
}
return $new;
}
}

View File

@ -1,21 +0,0 @@
<?php
namespace {NAMESPACE};
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;
class {CLASS}Command extends Command
{
protected function configure()
{
$this->setName('')
->setDescription('');
}
protected function execute(Input $input, Output $output)
{
}
}

View File

@ -1,25 +0,0 @@
{
"name": "$VENDOR$/$LOWER_NAME$",
"description": "",
"authors": [
{
"name": "$AUTHOR_NAME$",
"email": "$AUTHOR_EMAIL$"
}
],
"extra": {
"laravel": {
"providers": [
"$MODULE_NAMESPACE$\\$STUDLY_NAME$\\$PROVIDER_NAMESPACE$\\$STUDLY_NAME$ServiceProvider"
],
"aliases": {
}
}
},
"autoload": {
"psr-4": {
"$MODULE_NAMESPACE$\\$STUDLY_NAME$\\": ""
}
}
}

View File

@ -1,35 +0,0 @@
<?php
namespace {NAMESPACE};
use app\BaseController;
class {CLASS} extends BaseController
{
public function index()
{
return $this->fetch('{MODULE}::index');
}
public function create()
{
return $this->fetch('{MODULE}::create');
}
public function save()
{}
public function read()
{}
public function edit()
{
return $this->fetch('{MODULE}::edit');
}
public function update()
{}
public function delete()
{}
}

View File

@ -1,11 +0,0 @@
<?php
declare (strict_types = 1);
namespace {NAMESPACE};
class {CLASS}
{
public function handle()
{
}
}

View File

@ -1,33 +0,0 @@
<?php
use think\migration\Migrator;
use think\migration\db\Column;
class {CLASS} extends Migrator
{
/**
* Change Method.
*
* Write your reversible migrations using this method.
*
* More information on writing migrations is available here:
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
*
* The following commands can be used in this method and Phinx will
* automatically reverse them when rolling back:
*
* createTable
* renameTable
* addColumn
* renameColumn
* addIndex
* addForeignKey
*
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
public function change()
{
}
}

View File

@ -1,10 +0,0 @@
<?php
namespace {NAMESPACE};
use think\Model;
class {CLASS} extends Model
{
protected $fillable = $FILLABLE$;
}

View File

@ -1,13 +0,0 @@
{
"name": "",
"alias": "{MODULE}",
"description": "",
"keywords": [],
"order": 0,
"services": [
"{SERVICE}"
],
"aliases": {},
"files": [],
"requires": []
}

View File

@ -1,23 +0,0 @@
<?php
namespace {NAMESPACE};
use think\Service;
class {CLASS}Service extends Service
{
/**
*
* @return void
*/
public function boot()
{
$this->loadRoutesFrom(__DIR__ . DIRECTORY_SEPARATOR . 'route.php');
$this->loadViewFrom();
}
protected function loadViewFrom(): void
{
moduleViewPathManager()->set('login', __DIR__ . DIRECTORY_SEPARATOR . 'view' .DIRECTORY_SEPARATOR);
}
}

View File

@ -1,17 +0,0 @@
<?php
namespace {NAMESPACE};
use catcher\base\BaseRequest;
class {CLASS}Request extends BaseRequest
{
/**
*
* @time 2019年11月27日
* @return string
*/
protected function getValidate()
{
// TODO: Implement getValidate() method.
}
}

View File

@ -1,5 +0,0 @@
<?php
// you should user `$router`
// $router->get('index', 'controller@method');

View File

@ -1,19 +0,0 @@
<?php
use think\migration\Seeder;
class {CLASS} extends Seeder
{
/**
* Run Method.
*
* Write your database seeder using this method.
*
* More information on writing seeders is available here:
* http://docs.phinx.org/en/latest/seeding.html
*/
public function run()
{
}
}

View File

@ -1,11 +0,0 @@
<?php
namespace {Namespace};
use catcher\base\BaseValidate;
class {Class}Validate extends BaseValidate
{
protected $rule = [
// todo your rules
];
}

View File

@ -0,0 +1,6 @@
{
"plugins": [["import", {
"libraryName": "view-design",
"libraryDirectory": "src/components"
}]]
}

View File

@ -0,0 +1,3 @@
> 1%
last 2 versions
not ie <= 10

Some files were not shown because too many files have changed in this diff Show More