This repository has been archived by the owner on Nov 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from cleaniquecoders/develop
Develop
- Loading branch information
Showing
26 changed files
with
618 additions
and
557 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 |
---|---|---|
|
@@ -38,3 +38,5 @@ DOCUMENT_SEQUENCE_LENGTH=6 | |
|
||
LAYOUT_ADMIN=default | ||
LAYOUT_PUBLIC=default | ||
|
||
JWT_SECRET= |
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\Console\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
use Illuminate\Support\Str; | ||
|
||
class MakeJwtTokenCommand extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'make:jwt'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Create a new JWT Token'; | ||
|
||
/** | ||
* Create a new command instance. | ||
*/ | ||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return mixed | ||
*/ | ||
public function handle() | ||
{ | ||
$key = Str::random(32); | ||
|
||
file_put_contents($this->laravel->environmentFilePath(), preg_replace( | ||
$this->keyReplacementPattern(), | ||
'JWT_SECRET=' . $key, | ||
file_get_contents($this->laravel->environmentFilePath()) | ||
)); | ||
|
||
$this->info("jwt-auth secret [$key] set successfully."); | ||
} | ||
|
||
/** | ||
* Get a regex pattern that will match env JWT_SECRET with any random key. | ||
* | ||
* @return string | ||
*/ | ||
protected function keyReplacementPattern() | ||
{ | ||
$escaped = preg_quote('=' . $this->laravel['config']['jwt.secret'], '/'); | ||
|
||
return "/^JWT_SECRET{$escaped}/m"; | ||
} | ||
} |
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
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
37 changes: 37 additions & 0 deletions
37
app/Http/Controllers/Api/Auth/ForgotPasswordController.php
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,37 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Api\Auth; | ||
|
||
use App\Http\Controllers\Controller; | ||
use Illuminate\Foundation\Auth\SendsPasswordResetEmails; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Password; | ||
|
||
class ForgotPasswordController extends Controller | ||
{ | ||
use SendsPasswordResetEmails; | ||
|
||
/** | ||
* Create a new controller instance. | ||
*/ | ||
public function __construct() | ||
{ | ||
$this->middleware('guest'); | ||
} | ||
|
||
public function __invoke(Request $request) | ||
{ | ||
$this->validateEmail($request); | ||
|
||
// We will send the password reset link to this user. Once we have attempted | ||
// to send the link, we will examine the response then see the message we | ||
// need to show to the user. Finally, we'll send out a proper response. | ||
$response = $this->broker()->sendResetLink( | ||
$request->only('email') | ||
); | ||
|
||
return Password::RESET_LINK_SENT == $response | ||
? response()->api([], 'Reset link sent to your email.') | ||
: response()->api([], 'Unable to send reset link'); | ||
} | ||
} |
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,26 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Api\Auth; | ||
|
||
use App\Http\Controllers\Controller; | ||
use Illuminate\Http\Request; | ||
use JWTAuth; | ||
use Tymon\JWTAuth\Exceptions\JWTException; | ||
|
||
class LoginController extends Controller | ||
{ | ||
public function __invoke(Request $request) | ||
{ | ||
$credentials = $request->only('email', 'password'); | ||
|
||
try { | ||
if (! $token = JWTAuth::attempt($credentials)) { | ||
return response()->api([], 'Invalid Credentials.', false, 401); | ||
} | ||
} catch (JWTException $e) { | ||
return response()->api([], 'Could not create token.', false, 500); | ||
} | ||
|
||
return response()->api($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,17 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Api\Auth; | ||
|
||
use App\Http\Controllers\Controller; | ||
use Illuminate\Http\Request; | ||
use JWTAuth; | ||
|
||
class LogoutController extends Controller | ||
{ | ||
public function __invoke(Request $request) | ||
{ | ||
JWTAuth::invalidate(JWTAuth::getToken()); | ||
|
||
return response()->api([], 'You have sucessfully logout.'); | ||
} | ||
} |
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\Http\Controllers\Api\Auth; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Models\User; | ||
use Illuminate\Auth\Events\Registered; | ||
use Illuminate\Http\Request; | ||
use JWTAuth; | ||
|
||
class RegisterController extends Controller | ||
{ | ||
public function __invoke(Request $request) | ||
{ | ||
$this->validate($request, [ | ||
'name' => 'required|string|max:255', | ||
'email' => 'required|string|email|max:255|unique:users', | ||
'password' => 'required|string|min:6|confirmed', | ||
]); | ||
|
||
$user = User::create([ | ||
'name' => $request->get('name'), | ||
'email' => $request->get('email'), | ||
'password' => bcrypt($request->get('password')), | ||
]); | ||
|
||
event(new Registered($user)); | ||
|
||
$token = JWTAuth::fromUser($user); | ||
|
||
return response()->api($token, 'Registration successful.', true, 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
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,62 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Api\User; | ||
|
||
use App\Http\Controllers\Controller; | ||
use Illuminate\Http\Request; | ||
|
||
class ProfileController extends Controller | ||
{ | ||
/** | ||
* Display a listing of the resource. | ||
* | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function index() | ||
{ | ||
} | ||
|
||
/** | ||
* Store a newly created resource in storage. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function store(Request $request) | ||
{ | ||
} | ||
|
||
/** | ||
* Display the specified resource. | ||
* | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function show() | ||
{ | ||
return response()->api(auth()->user()->only('name', 'email', 'hashslug')); | ||
} | ||
|
||
/** | ||
* Update the specified resource in storage. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @param int $id | ||
* | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function update(Request $request, $id) | ||
{ | ||
} | ||
|
||
/** | ||
* Remove the specified resource from storage. | ||
* | ||
* @param int $id | ||
* | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function destroy($id) | ||
{ | ||
} | ||
} |
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
Oops, something went wrong.