Compare commits

...

5 Commits

Author SHA1 Message Date
Your Name 61b4aa1e57 完成模板 2022-09-25 21:39:39 +08:00
Your Name 184b44b1ae ok 2022-09-14 18:19:38 +08:00
guaosi 5259ce3889
Merge pull request #3 from guaosi/add-license-1
Create LICENSE
2020-01-11 15:10:57 +08:00
guaosi efb04ae5cc
Create LICENSE 2020-01-11 15:10:42 +08:00
guaosi c1a1d82d39 delete .idea 2019-03-24 13:25:40 +08:00
22 changed files with 3312 additions and 1720 deletions

1
.gitignore vendored
View File

@ -9,3 +9,4 @@ Homestead.json
Homestead.yaml Homestead.yaml
npm-debug.log npm-debug.log
yarn-error.log yarn-error.log
/.idea

View File

@ -1,5 +0,0 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="PROJECT_PROFILE" />
</settings>
</component>

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
</project>

View File

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/test.iml" filepath="$PROJECT_DIR$/.idea/test.iml" />
</modules>
</component>
</project>

View File

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -1,10 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="NodePackageJsonFileManager">
<packageJsonPaths />
</component>
<component name="PropertiesComponent">
<property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
<property name="nodejs_npm_path_reset_for_default_project" value="true" />
</component>
</project>

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2020 guaosi
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -0,0 +1,25 @@
<?php
namespace App\Http\Controllers\Api;
use App\Http\Requests\Api\UserRequest;
use App\Http\Resources\Api\UserResource;
use App\Jobs\Api\SaveLastTokenJob;
use App\Models\Book;
use App\Models\Url;
use App\Models\Log;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Tymon\JWTAuth\Exceptions\TokenExpiredException;
class HomeController extends Controller
{
public function index()
{
$urls = Url::all();
$log = Log::all();
return $this->success(["urls"=>count($urls),"log"=>count($log)]);
}
}

View File

@ -0,0 +1,54 @@
<?php
namespace App\Http\Controllers\Api;
use App\Http\Requests\Api\UserRequest;
use App\Http\Resources\Api\UserResource;
use App\Jobs\Api\SaveLastTokenJob;
use App\Models\Book;
use App\Models\Url;
use App\Models\Log;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Tymon\JWTAuth\Exceptions\TokenExpiredException;
use Illuminate\Support\Facades\DB;
class UrlController extends Controller
{
public function index()
{
$urls = Url::all();
return $this->success($urls);
}
public function add(Request $req)
{
$hosts = $req->hosts;
foreach ($hosts as $v) {
$urls = new Url;
$urls->host = $v;
$urls->save();
}
return $this->success("");
}
public function del(Request $req)
{
$id = $req->id;
Url::where('id', $id)->delete();
return $this->success("");
}
public function set(Request $req)
{
$host = $req->host;
$url = $req->url;
$log = new Log;
$log->host = $host;
$log->url = $url;
$log->save();
Url::where('host', $host)->update(['url' => $url]);
return $this->success("");
} public function text()
{
//$users = DB::select('select * from `users` where `name` = giaogiao limit 1');
return $this->success("");
}
}

View File

@ -36,6 +36,7 @@ class UserController extends Controller
} }
//用户登录 //用户登录
public function login(Request $request){ public function login(Request $request){
//dd($request->name);
$token=Auth::claims(['guard'=>'api'])->attempt(['name'=>$request->name,'password'=>$request->password]); $token=Auth::claims(['guard'=>'api'])->attempt(['name'=>$request->name,'password'=>$request->password]);
if($token) { if($token) {
//如果登陆先检查原先是否有存token有的话先失效然后再存入最新的token //如果登陆先检查原先是否有存token有的话先失效然后再存入最新的token
@ -47,15 +48,23 @@ class UserController extends Controller
//因为让一个过期的token再失效会抛出异常所以我们捕捉异常不需要做任何处理 //因为让一个过期的token再失效会抛出异常所以我们捕捉异常不需要做任何处理
} }
} }
SaveLastTokenJob::dispatch($user,$token); //SaveLastTokenJob::dispatch($user,$token);
return $this->setStatusCode(201)->success(['token' => 'bearer ' . $token]); return $this->setStatusCode(201)->success(['token' => 'bearer ' . $token]);
} }
return $this->failed('账号或密码错误',400); //return $this->failed('账号或密码错误',400);
return $this->setStatusCode(200)->success(["code"=>"400"]);
} }
//用户退出 //用户退出
public function logout(){ public function logout(){
Auth::logout(); Auth::logout();
return $this->success('退出成功...'); return $this->success('退出成功...');
} }
public function set(Request $req){
$password = $req->password;
$user = Auth::user();
$user->password=$password;
$user->save();
return $this->success("成功");
}
} }

View File

@ -63,7 +63,7 @@ class RefreshTokenMiddleware extends BaseMiddleware
//刷新了token将token存入数据库 //刷新了token将token存入数据库
$user = Auth::user(); $user = Auth::user();
SaveLastTokenJob::dispatch($user,$token); //SaveLastTokenJob::dispatch($user,$token);
} catch (JWTException $exception) { } catch (JWTException $exception) {
// 如果捕获到此异常,即代表 refresh 也过期了,用户无法刷新令牌,需要重新登录。 // 如果捕获到此异常,即代表 refresh 也过期了,用户无法刷新令牌,需要重新登录。

14
app/Models/Log.php Normal file
View File

@ -0,0 +1,14 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Log extends Model
{
//
protected $fillable = [
'host', 'url'
];
//protected $datas = ['deleted_at'];
}

14
app/Models/Url.php Normal file
View File

@ -0,0 +1,14 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Url extends Model
{
//
protected $fillable = [
'host', 'url'
];
//protected $datas = ['deleted_at'];
}

View File

@ -13,6 +13,7 @@
"laravel/framework": "5.7.*", "laravel/framework": "5.7.*",
"laravel/horizon": "^3.0", "laravel/horizon": "^3.0",
"laravel/tinker": "^1.0", "laravel/tinker": "^1.0",
"lcobucci/jwt": "3.3.3",
"medz/cors": "^1.4", "medz/cors": "^1.4",
"tymon/jwt-auth": "1.0.0-rc.3" "tymon/jwt-auth": "1.0.0-rc.3"
}, },
@ -27,7 +28,14 @@
"config": { "config": {
"optimize-autoloader": true, "optimize-autoloader": true,
"preferred-install": "dist", "preferred-install": "dist",
"sort-packages": true "sort-packages": true,
"platform": {
"ext-pcntl": "7.3",
"ext-posix": "7.3"
},
"allow-plugins": {
"kylekatarnls/update-helper": true
}
}, },
"extra": { "extra": {
"laravel": { "laravel": {

4724
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -3,12 +3,12 @@
return [ return [
'allow-credentials' => env('CORS_ALLOW_CREDENTIAILS', false), // set "Access-Control-Allow-Credentials" 👉 string "false" or "true". 'allow-credentials' => env('CORS_ALLOW_CREDENTIAILS', false), // set "Access-Control-Allow-Credentials" 👉 string "false" or "true".
'allow-headers' => ['*'], // ex: Content-Type, Accept, X-Requested-With 'allow-headers' => ['*'], // ex: Content-Type, Accept, X-Requested-With
'expose-headers' => ['Authorization'], 'expose-headers' => [],
'origins' => ['*'], // ex: http://localhost 'origins' => ['*'], // ex: http://localhost
'methods' => ['*'], // ex: GET, POST, PUT, PATCH, DELETE 'methods' => ['*'], // ex: GET, POST, PUT, PATCH, DELETE
'max-age' => env('CORS_ACCESS_CONTROL_MAX_AGE', 0), 'max-age' => env('CORS_ACCESS_CONTROL_MAX_AGE', 0),
'laravel' => [ 'laravel' => [
'allow-route-perfix' => env('CORS_LARAVEL_ALLOW_ROUTE_PERFIX', '*'), // The perfix is using \Illumante\Http\Request::is method. 👉 'allow-route-prefix' => env('CORS_LARAVEL_ALLOW_ROUTE_PREFIX', '*'), // The prefix is using \Illumante\Http\Request::is method. 👉
'route-group-mode' => env('CORS_LARAVEL_ROUTE_GROUP_MODE', false), 'route-group-mode' => env('CORS_LARAVEL_ROUTE_GROUP_MODE', false),
], ],
]; ];

View File

@ -101,7 +101,7 @@ return [
| |
*/ */
'ttl' => env('JWT_TTL', 60), 'ttl' => env('JWT_TTL', 6000000),
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------

View File

@ -0,0 +1,31 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateUrlsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('urls', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('urls');
}
}

View File

@ -0,0 +1,36 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateJobsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('jobs', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('queue')->index();
$table->longText('payload');
$table->unsignedTinyInteger('attempts');
$table->unsignedInteger('reserved_at')->nullable();
$table->unsignedInteger('available_at');
$table->unsignedInteger('created_at');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('jobs');
}
}

View File

@ -1,21 +0,0 @@
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>

6
public/nginx.htaccess Normal file
View File

@ -0,0 +1,6 @@
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
# try_files $uri $uri/ =404;
try_files $uri $uri/ /index.php?$query_string;
}

View File

@ -19,7 +19,6 @@ Route::namespace('Api')->prefix('v1')->middleware('cors')->group(function () {
Route::post('/users', 'UserController@store')->name('users.store'); Route::post('/users', 'UserController@store')->name('users.store');
//用户登录 //用户登录
Route::post('/login', 'UserController@login')->name('users.login'); Route::post('/login', 'UserController@login')->name('users.login');
Route::middleware('api.refresh')->group(function () { Route::middleware('api.refresh')->group(function () {
//当前用户信息 //当前用户信息
Route::get('/users/info', 'UserController@info')->name('users.info'); Route::get('/users/info', 'UserController@info')->name('users.info');
@ -29,6 +28,14 @@ Route::namespace('Api')->prefix('v1')->middleware('cors')->group(function () {
Route::get('/users/{user}', 'UserController@show')->name('users.show'); Route::get('/users/{user}', 'UserController@show')->name('users.show');
//用户退出 //用户退出
Route::get('/logout', 'UserController@logout')->name('users.logout'); Route::get('/logout', 'UserController@logout')->name('users.logout');
Route::post('/url/add', 'UrlController@add');
Route::post('/url/text', 'UrlController@text');
Route::post('/url/all', 'UrlController@index');
Route::post('/url/set', 'UrlController@set');
Route::post('/url/del', 'UrlController@del');
Route::post('/home/all', 'HomeController@index');
Route::post('/user/set', 'UserController@set');
}); });
}); });
Route::middleware('admin.guard')->group(function () { Route::middleware('admin.guard')->group(function () {