Compare commits

..

No commits in common. "61b4aa1e5762ca9f212a414992f719be39681f4e" and "89c08fb9c5406dfe3010c8d52fe70b1c94bf403a" have entirely different histories.

22 changed files with 1717 additions and 3309 deletions

1
.gitignore vendored
View File

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

View File

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

6
.idea/misc.xml Normal file
View File

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

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?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>

8
.idea/test.iml Normal file
View File

@ -0,0 +1,8 @@
<?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>

10
.idea/workspace.xml Normal file
View File

@ -0,0 +1,10 @@
<?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
View File

@ -1,21 +0,0 @@
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

@ -1,25 +0,0 @@
<?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

@ -1,54 +0,0 @@
<?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,7 +36,6 @@ class UserController extends Controller
}
//用户登录
public function login(Request $request){
//dd($request->name);
$token=Auth::claims(['guard'=>'api'])->attempt(['name'=>$request->name,'password'=>$request->password]);
if($token) {
//如果登陆先检查原先是否有存token有的话先失效然后再存入最新的token
@ -48,23 +47,15 @@ class UserController extends Controller
//因为让一个过期的token再失效会抛出异常所以我们捕捉异常不需要做任何处理
}
}
//SaveLastTokenJob::dispatch($user,$token);
SaveLastTokenJob::dispatch($user,$token);
return $this->setStatusCode(201)->success(['token' => 'bearer ' . $token]);
}
//return $this->failed('账号或密码错误',400);
return $this->setStatusCode(200)->success(["code"=>"400"]);
return $this->failed('账号或密码错误',400);
}
//用户退出
public function logout(){
Auth::logout();
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存入数据库
$user = Auth::user();
//SaveLastTokenJob::dispatch($user,$token);
SaveLastTokenJob::dispatch($user,$token);
} catch (JWTException $exception) {
// 如果捕获到此异常,即代表 refresh 也过期了,用户无法刷新令牌,需要重新登录。

View File

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

View File

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

View File

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

4726
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -3,12 +3,12 @@
return [
'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
'expose-headers' => [],
'expose-headers' => ['Authorization'],
'origins' => ['*'], // ex: http://localhost
'methods' => ['*'], // ex: GET, POST, PUT, PATCH, DELETE
'max-age' => env('CORS_ACCESS_CONTROL_MAX_AGE', 0),
'laravel' => [
'allow-route-prefix' => env('CORS_LARAVEL_ALLOW_ROUTE_PREFIX', '*'), // The prefix is using \Illumante\Http\Request::is method. 👉
'allow-route-perfix' => env('CORS_LARAVEL_ALLOW_ROUTE_PERFIX', '*'), // The perfix is using \Illumante\Http\Request::is method. 👉
'route-group-mode' => env('CORS_LARAVEL_ROUTE_GROUP_MODE', false),
],
];

View File

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

View File

@ -1,31 +0,0 @@
<?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

@ -1,36 +0,0 @@
<?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

@ -0,0 +1,21 @@
<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>

View File

@ -1,6 +0,0 @@
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,6 +19,7 @@ Route::namespace('Api')->prefix('v1')->middleware('cors')->group(function () {
Route::post('/users', 'UserController@store')->name('users.store');
//用户登录
Route::post('/login', 'UserController@login')->name('users.login');
Route::middleware('api.refresh')->group(function () {
//当前用户信息
Route::get('/users/info', 'UserController@info')->name('users.info');
@ -28,14 +29,6 @@ Route::namespace('Api')->prefix('v1')->middleware('cors')->group(function () {
Route::get('/users/{user}', 'UserController@show')->name('users.show');
//用户退出
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 () {