forked from johndavedecano/laragym
-
Notifications
You must be signed in to change notification settings - Fork 0
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 801ce21
Showing
94 changed files
with
8,163 additions
and
0 deletions.
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,41 @@ | ||
APP_ENV=local | ||
APP_KEY= | ||
APP_DEBUG=true | ||
APP_LOG_LEVEL=debug | ||
APP_URL=http://localhost | ||
|
||
DB_CONNECTION=mysql | ||
DB_HOST=127.0.0.1 | ||
DB_PORT=3306 | ||
DB_DATABASE=homestead | ||
DB_USERNAME=homestead | ||
DB_PASSWORD=secret | ||
|
||
BROADCAST_DRIVER=log | ||
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 | ||
|
||
PUSHER_APP_ID= | ||
PUSHER_KEY= | ||
PUSHER_SECRET= | ||
|
||
API_PREFIX=api | ||
API_SUBTYPE=app | ||
API_VERSION=v1 | ||
|
||
SIGN_UP_RELEASE_TOKEN=false | ||
PASSWORD_RESET_RELEASE_TOKEN=false | ||
|
||
JWT_SECRET=my-dummy-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,3 @@ | ||
* text=auto | ||
*.css linguist-vendored | ||
*.scss 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,8 @@ | ||
/node_modules | ||
/public/storage | ||
/storage/*.key | ||
/vendor | ||
/.idea | ||
Homestead.json | ||
Homestead.yaml | ||
.env |
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,43 @@ | ||
<?php | ||
|
||
namespace App\Api\V1\Controllers; | ||
|
||
use App\User; | ||
use App\Http\Controllers\Controller; | ||
use Illuminate\Support\Facades\Password; | ||
use App\Api\V1\Requests\ForgotPasswordRequest; | ||
use Symfony\Component\HttpKernel\Exception\HttpException; | ||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; | ||
|
||
class ForgotPasswordController extends Controller | ||
{ | ||
public function sendResetEmail(ForgotPasswordRequest $request) | ||
{ | ||
$user = User::where('email', '=', $request->get('email'))->first(); | ||
|
||
if(!$user) { | ||
throw new NotFoundHttpException(); | ||
} | ||
|
||
$broker = $this->getPasswordBroker(); | ||
$sendingResponse = $broker->sendResetLink($request->only('email')); | ||
|
||
if($sendingResponse !== Password::RESET_LINK_SENT) { | ||
throw new HttpException(500); | ||
} | ||
|
||
return response()->json([ | ||
'status' => 'ok' | ||
], 200); | ||
} | ||
|
||
/** | ||
* Get the broker to be used during password reset. | ||
* | ||
* @return \Illuminate\Contracts\Auth\PasswordBroker | ||
*/ | ||
private function getPasswordBroker() | ||
{ | ||
return Password::broker(); | ||
} | ||
} |
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,44 @@ | ||
<?php | ||
|
||
namespace App\Api\V1\Controllers; | ||
|
||
use Symfony\Component\HttpKernel\Exception\HttpException; | ||
use Tymon\JWTAuth\JWTAuth; | ||
use App\Http\Controllers\Controller; | ||
use App\Api\V1\Requests\LoginRequest; | ||
use Tymon\JWTAuth\Exceptions\JWTException; | ||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; | ||
use Auth; | ||
|
||
class LoginController extends Controller | ||
{ | ||
/** | ||
* Log the user in | ||
* | ||
* @param LoginRequest $request | ||
* @param JWTAuth $JWTAuth | ||
* @return \Illuminate\Http\JsonResponse | ||
*/ | ||
public function login(LoginRequest $request, JWTAuth $JWTAuth) | ||
{ | ||
$credentials = $request->only(['email', 'password']); | ||
|
||
try { | ||
$token = Auth::guard()->attempt($credentials); | ||
|
||
if(!$token) { | ||
throw new AccessDeniedHttpException(); | ||
} | ||
|
||
} catch (JWTException $e) { | ||
throw new HttpException(500); | ||
} | ||
|
||
return response() | ||
->json([ | ||
'status' => 'ok', | ||
'token' => $token, | ||
'expires_in' => Auth::guard()->factory()->getTTL() * 60 | ||
]); | ||
} | ||
} |
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,32 @@ | ||
<?php | ||
|
||
namespace App\Api\V1\Controllers; | ||
|
||
use App\Http\Controllers\Controller; | ||
use Auth; | ||
|
||
class LogoutController extends Controller | ||
{ | ||
/** | ||
* Create a new AuthController instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct() | ||
{ | ||
$this->middleware('auth:api', []); | ||
} | ||
|
||
/** | ||
* Log the user out (Invalidate the token) | ||
* | ||
* @return \Illuminate\Http\JsonResponse | ||
*/ | ||
public function logout() | ||
{ | ||
Auth::guard()->logout(); | ||
|
||
return response() | ||
->json(['message' => 'Successfully logged out']); | ||
} | ||
} |
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,30 @@ | ||
<?php | ||
|
||
namespace App\Api\V1\Controllers; | ||
|
||
use Symfony\Component\HttpKernel\Exception\HttpException; | ||
use Tymon\JWTAuth\JWTAuth; | ||
use App\Http\Controllers\Controller; | ||
use App\Api\V1\Requests\LoginRequest; | ||
use Tymon\JWTAuth\Exceptions\JWTException; | ||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; | ||
use Auth; | ||
|
||
class RefreshController extends Controller | ||
{ | ||
/** | ||
* Refresh a token. | ||
* | ||
* @return \Illuminate\Http\JsonResponse | ||
*/ | ||
public function refresh() | ||
{ | ||
$token = Auth::guard()->refresh(); | ||
|
||
return response()->json([ | ||
'status' => 'ok', | ||
'token' => $token, | ||
'expires_in' => Auth::guard()->factory()->getTTL() * 60 | ||
]); | ||
} | ||
} |
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,76 @@ | ||
<?php | ||
|
||
namespace App\Api\V1\Controllers; | ||
|
||
use Config; | ||
use App\User; | ||
use Tymon\JWTAuth\JWTAuth; | ||
use App\Http\Controllers\Controller; | ||
use Illuminate\Support\Facades\Password; | ||
use App\Api\V1\Requests\ResetPasswordRequest; | ||
use Symfony\Component\HttpKernel\Exception\HttpException; | ||
|
||
class ResetPasswordController extends Controller | ||
{ | ||
public function resetPassword(ResetPasswordRequest $request, JWTAuth $JWTAuth) | ||
{ | ||
$response = $this->broker()->reset( | ||
$this->credentials($request), function ($user, $password) { | ||
$this->reset($user, $password); | ||
} | ||
); | ||
|
||
if($response !== Password::PASSWORD_RESET) { | ||
throw new HttpException(500); | ||
} | ||
|
||
if(!Config::get('boilerplate.reset_password.release_token')) { | ||
return response()->json([ | ||
'status' => 'ok', | ||
]); | ||
} | ||
|
||
$user = User::where('email', '=', $request->get('email'))->first(); | ||
|
||
return response()->json([ | ||
'status' => 'ok', | ||
'token' => $JWTAuth->fromUser($user) | ||
]); | ||
} | ||
|
||
/** | ||
* Get the broker to be used during password reset. | ||
* | ||
* @return \Illuminate\Contracts\Auth\PasswordBroker | ||
*/ | ||
public function broker() | ||
{ | ||
return Password::broker(); | ||
} | ||
|
||
/** | ||
* Get the password reset credentials from the request. | ||
* | ||
* @param ResetPasswordRequest $request | ||
* @return array | ||
*/ | ||
protected function credentials(ResetPasswordRequest $request) | ||
{ | ||
return $request->only( | ||
'email', 'password', 'password_confirmation', 'token' | ||
); | ||
} | ||
|
||
/** | ||
* Reset the given user's password. | ||
* | ||
* @param \Illuminate\Contracts\Auth\CanResetPassword $user | ||
* @param string $password | ||
* @return void | ||
*/ | ||
protected function reset($user, $password) | ||
{ | ||
$user->password = $password; | ||
$user->save(); | ||
} | ||
} |
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,33 @@ | ||
<?php | ||
|
||
namespace App\Api\V1\Controllers; | ||
|
||
use Config; | ||
use App\User; | ||
use Tymon\JWTAuth\JWTAuth; | ||
use App\Http\Controllers\Controller; | ||
use App\Api\V1\Requests\SignUpRequest; | ||
use Symfony\Component\HttpKernel\Exception\HttpException; | ||
|
||
class SignUpController extends Controller | ||
{ | ||
public function signUp(SignUpRequest $request, JWTAuth $JWTAuth) | ||
{ | ||
$user = new User($request->all()); | ||
if(!$user->save()) { | ||
throw new HttpException(500); | ||
} | ||
|
||
if(!Config::get('boilerplate.sign_up.release_token')) { | ||
return response()->json([ | ||
'status' => 'ok' | ||
], 201); | ||
} | ||
|
||
$token = $JWTAuth->fromUser($user); | ||
return response()->json([ | ||
'status' => 'ok', | ||
'token' => $token | ||
], 201); | ||
} | ||
} |
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,34 @@ | ||
<?php | ||
|
||
namespace App\Api\V1\Controllers; | ||
|
||
use Symfony\Component\HttpKernel\Exception\HttpException; | ||
use Tymon\JWTAuth\JWTAuth; | ||
use App\Http\Controllers\Controller; | ||
use App\Api\V1\Requests\LoginRequest; | ||
use Tymon\JWTAuth\Exceptions\JWTException; | ||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; | ||
use Auth; | ||
|
||
class UserController extends Controller | ||
{ | ||
/** | ||
* Create a new AuthController instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct() | ||
{ | ||
$this->middleware('auth:api', []); | ||
} | ||
|
||
/** | ||
* Get the authenticated User | ||
* | ||
* @return \Illuminate\Http\JsonResponse | ||
*/ | ||
public function me() | ||
{ | ||
return response()->json(Auth::guard()->user()); | ||
} | ||
} |
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\Requests; | ||
|
||
use Config; | ||
use Dingo\Api\Http\FormRequest; | ||
|
||
class ForgotPasswordRequest extends FormRequest | ||
{ | ||
public function rules() | ||
{ | ||
return Config::get('boilerplate.forgot_password.validation_rules'); | ||
} | ||
|
||
public function authorize() | ||
{ | ||
return 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,19 @@ | ||
<?php | ||
|
||
namespace App\Api\V1\Requests; | ||
|
||
use Config; | ||
use Dingo\Api\Http\FormRequest; | ||
|
||
class LoginRequest extends FormRequest | ||
{ | ||
public function rules() | ||
{ | ||
return Config::get('boilerplate.login.validation_rules'); | ||
} | ||
|
||
public function authorize() | ||
{ | ||
return true; | ||
} | ||
} |
Oops, something went wrong.