-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 25c5647
Showing
5,562 changed files
with
691,305 additions
and
0 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
APP_ENV=local | ||
APP_DEBUG=true | ||
APP_KEY=hBL5DxgNJZZBWnfoWkE6tOEn9ReLYaSD | ||
APP_URL=http://localhost | ||
|
||
DB_HOST=127.0.0.1 | ||
DB_DATABASE=ucenter | ||
DB_USERNAME=root | ||
DB_PASSWORD=ucenter | ||
|
||
CACHE_DRIVER=file | ||
SESSION_DRIVER=file | ||
QUEUE_DRIVER=sync | ||
|
||
REDIS_HOST=127.0.0.1 | ||
REDIS_PASSWORD=null | ||
REDIS_PORT=6379 | ||
|
||
MAIL_DRIVER=smtp | ||
MAIL_HOST=mailtrap.io | ||
MAIL_PORT=2525 | ||
MAIL_USERNAME=null | ||
MAIL_PASSWORD=null | ||
MAIL_ENCRYPTION=null | ||
|
||
API_STANDARDS_TREE=vnd | ||
API_PREFIX=api | ||
API_VERSION=v1 | ||
API_DEBUG=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
APP_ENV=local | ||
APP_DEBUG=true | ||
APP_KEY=SomeRandomString | ||
APP_URL=http://localhost | ||
|
||
DB_HOST=127.0.0.1 | ||
DB_DATABASE=homestead | ||
DB_USERNAME=homestead | ||
DB_PASSWORD=secret | ||
|
||
CACHE_DRIVER=file | ||
SESSION_DRIVER=file | ||
QUEUE_DRIVER=sync | ||
|
||
REDIS_HOST=127.0.0.1 | ||
REDIS_PASSWORD=null | ||
REDIS_PORT=6379 | ||
|
||
MAIL_DRIVER=smtp | ||
MAIL_HOST=mailtrap.io | ||
MAIL_PORT=2525 | ||
MAIL_USERNAME=null | ||
MAIL_PASSWORD=null | ||
MAIL_ENCRYPTION=null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
* text=auto | ||
*.css linguist-vendored | ||
*.less linguist-vendored |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/node_modules | ||
/public/storage | ||
Homestead.yaml | ||
Homestead.json | ||
.svn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# laravel-dingo | ||
|
||
> Laravel5.2 + dingo api + JWT + swagger + 路由分割,让laravel5.2更加适合API开发者开发API的工作环境。 | ||
具体使用[wiki](https://github.com/turtleliangzi/laravel-dingo/wiki) | ||
|
||
联系方式:1639672490@qq.com | ||
|
||
blog地址: [turtletl.com](http://www.turtletl.com) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
namespace App\Api\V1\Controllers\Auth; | ||
|
||
use App\Api\V1\Controllers\BaseController; | ||
use Illuminate\Http\Request; | ||
use JWTAuth; | ||
use Tymon\JWTAuth\Exceptions\JWTException; | ||
use App\User; | ||
|
||
class AuthController extends BaseController { | ||
|
||
/** | ||
* @SWG\Post( | ||
* path="/auth/login", | ||
* summary="用户登录", | ||
* tags={"Auth"}, | ||
* @SWG\Response( | ||
* response=200, | ||
* description="token" | ||
* ), | ||
* @SWG\Parameter(name="email", in="query", required=true, type="string", description="登录邮箱"), | ||
* @SWG\Parameter(name="password", in="query", required=true, type="string", description="登录密码"), | ||
* @SWG\Response( | ||
* response="default", | ||
* description="an ""unexpected"" error" | ||
* ) | ||
* ) | ||
*/ | ||
|
||
public function authenticate(Request $request) { | ||
// grab credentials from the request | ||
$credentials = $request->only('email', 'password'); | ||
|
||
try { | ||
// attempt to verify the credentials and create a token for the user | ||
if (! $token = JWTAuth::attempt($credentials)) { | ||
return response()->json(['error' => 'invalid_credentials'], 401); | ||
} | ||
} catch (JWTException $e) { | ||
// something went wrong whilst attempting to encode the token | ||
return response()->json(['error' => 'could_not_create_token'], 500); | ||
} | ||
|
||
// all good so return the token | ||
return response()->json(compact('token')); | ||
} | ||
/** | ||
* @SWG\Post( | ||
* path="/auth/register", | ||
* summary="用户注册", | ||
* tags={"Auth"}, | ||
* @SWG\Response( | ||
* response=200, | ||
* description="register success" | ||
* ), | ||
* @SWG\Parameter(name="name", in="query", required=true, type="string", description="用户名"), | ||
* @SWG\Parameter(name="email", in="query", required=true, type="string", description="登录邮箱"), | ||
* @SWG\Parameter(name="password", in="query", required=true, type="string", description="登录密码"), | ||
* @SWG\Response( | ||
* response="default", | ||
* description="an ""unexpected"" error" | ||
* ) | ||
* ) | ||
*/ | ||
public function register(Request $request) { | ||
|
||
$newUser = [ | ||
'name' => $request->get('name'), | ||
'email' => $request->get('email'), | ||
'password' => bcrypt($request->get('password')), | ||
]; | ||
$user = User::create($newUser); | ||
$token = JWTAuth::fromUser($user); | ||
|
||
return response()->json(compact('token')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
/* | ||
* Auth Controller Routes | ||
* | ||
*/ | ||
|
||
$api->post('/auth/login', 'Auth\AuthController@authenticate'); | ||
$api->post('/auth/register', 'Auth\AuthController@register'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace App\Api\V1\Controllers; | ||
|
||
use App\Http\Controllers\Controller; | ||
use Dingo\Api\Routing\Helpers; | ||
|
||
class BaseController extends Controller { | ||
use Helpers; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
namespace App\Api\V1\Controllers\Lesson; | ||
|
||
use App\Api\V1\Controllers\BaseController; | ||
use App\Lesson; | ||
use Swagger\Annotations as SWG; | ||
use App\Api\V1\Transformers\LessonTransformer; | ||
|
||
|
||
class LessonController extends BaseController { | ||
|
||
/** | ||
* @SWG\Get( | ||
* path="/lessons/all", | ||
* summary="显示所有教程", | ||
* tags={"Lessons"}, | ||
* @SWG\Parameter(name="Authorization", in="header", required=true, description="用户凭证", type="string"), | ||
* @SWG\Response( | ||
* response=200, | ||
* description="all lessons" | ||
* ), | ||
* @SWG\Response( | ||
* response="default", | ||
* description="an ""unexpected"" error" | ||
* ) | ||
* ) | ||
*/ | ||
|
||
public function show() { | ||
$lessons = Lesson::all(); | ||
return $this->response->collection($lessons, new LessonTransformer); | ||
} | ||
|
||
/** | ||
* @SWG\Get( | ||
* path="/lessons/one/{id}", | ||
* summary="显示单个教程", | ||
* tags={"Lessons"}, | ||
* @SWG\Parameter(name="id", in="path", required=true, description="id", type="string"), | ||
* @SWG\Parameter(name="Authorization", in="header", required=true, description="用户凭证", type="string"), | ||
* @SWG\Response( | ||
* response=200, | ||
* description="one lessons" | ||
* ), | ||
* @SWG\Response( | ||
* response="default", | ||
* description="an ""unexpected"" error" | ||
* ) | ||
* ) | ||
*/ | ||
public function one($id) { | ||
$id = intval($id); | ||
$lesson = Lesson::find($id); | ||
if (empty($lesson)) { | ||
return $this->response->errorNotFound('lesson not found'); | ||
} | ||
return $this->response->item($lesson, new LessonTransformer); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php | ||
|
||
// Lesson Controller Routes | ||
|
||
$api->get('/lessons/all', 'Lesson\LessonController@show'); | ||
$api->get('/lessons/one/{id}', 'Lesson\LessonController@one'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<?php | ||
|
||
namespace App\Api\V1\Controllers\User; | ||
|
||
use App\Api\V1\Controllers\BaseController; | ||
use App\User; | ||
use Swagger\Annotations as SWG; | ||
use JWTAuth; | ||
use Tymon\JWTAuth\Exceptions\TokenExpiredException; | ||
use Tymon\JWTAuth\Exceptions\TokenInvalidException; | ||
use Tymon\JWTAuth\Exceptions\JWTException; | ||
use App\Api\V1\Transformers\UserTransformer; | ||
|
||
/** | ||
* @SWG\Swagger( | ||
* @SWG\Info( | ||
* title="Laravel-dingo", | ||
* version="1.0.0" | ||
* ), | ||
* @SWG\Tag(name="Auth", description="验证模块"), | ||
* @SWG\Tag(name="Users", description="用户模块"), | ||
* @SWG\Tag(name="Lessons", description="教程模块"), | ||
* schemes={"http"}, | ||
* host="ucenter.turtletl.com:81", | ||
* basePath="/api" | ||
* ) | ||
*/ | ||
|
||
class UserController extends BaseController { | ||
/** | ||
* @SWG\Get( | ||
* path="/users/all", | ||
* summary="显示所有用户", | ||
* tags={"Users"}, | ||
* @SWG\Parameter(name="Authorization", in="header", required=true, description="用户凭证", type="string"), | ||
* @SWG\Response( | ||
* response=200, | ||
* description="all users" | ||
* ), | ||
* @SWG\Response( | ||
* response="default", | ||
* description="an ""unexpected"" error" | ||
* ) | ||
* ) | ||
*/ | ||
|
||
public function show() { | ||
$users = User::all(); | ||
$users = User::paginate(25); | ||
return $this->response->paginator($users, new UserTransformer)->setStatusCode(200); | ||
//return $this->response->collection($users, new UserTransformer); | ||
} | ||
/** | ||
* @SWG\Get( | ||
* path="/users/one", | ||
* summary="获取当前用户", | ||
* tags={"Users"}, | ||
* @SWG\Parameter(name="Authorization", in="header", required=true, description="用户凭证", type="string"), | ||
* @SWG\Response( | ||
* response=200, | ||
* description="one user" | ||
* ), | ||
* @SWG\Response( | ||
* response="default", | ||
* description="an ""unexpected"" error" | ||
* ) | ||
* ) | ||
*/ | ||
public function getAuthenticatedUser() | ||
{ | ||
try { | ||
|
||
if (! $user = JWTAuth::parseToken()->authenticate()) { | ||
return response()->json(['user_not_found'], 404); | ||
} | ||
|
||
} catch (TokenExpiredException $e) { | ||
|
||
return response()->json(['token_expired'], $e->getStatusCode()); | ||
|
||
} catch (TokenInvalidException $e) { | ||
|
||
return response()->json(['token_invalid'], $e->getStatusCode()); | ||
|
||
} catch (JWTException $e) { | ||
|
||
return response()->json(['token_absent'], $e->getStatusCode()); | ||
|
||
} | ||
|
||
// the token is valid and we have found the user via the sub claim | ||
return response()->json(compact('user')); | ||
//return $this->response->item(compact('user'), new UserTransformer); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
/* | ||
* User Controller Routes | ||
* | ||
*/ | ||
|
||
$api->get('/users/all', 'User\UserController@show'); | ||
$api->get('/users/one', 'User\UserController@getAuthenticatedUser'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace App\Api\V1\Transformers; | ||
|
||
use League\Fractal\TransformerAbstract; | ||
use App\Lesson; | ||
|
||
class LessonTransformer extends TransformerAbstract { | ||
|
||
public function transform(Lesson $lesson) { | ||
return [ | ||
'title' => $lesson['title'], | ||
'content' => $lesson['body'], | ||
'is_free' => (boolean)($lesson['free']), | ||
]; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace App\Api\V1\Transformers; | ||
|
||
use League\Fractal\TransformerAbstract; | ||
use App\User; | ||
|
||
class UserTransformer extends TransformerAbstract { | ||
|
||
public function transform(User $user) { | ||
return [ | ||
'id' => $user['id'], | ||
'name' => $user['name'], | ||
'email' => $user['email'], | ||
]; | ||
} | ||
} | ||
|
||
|
Oops, something went wrong.