-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Mis en place de la fonctionnalite de rappel et reinitialisation du …
…mot de passe (#74)
- Loading branch information
1 parent
b8870b6
commit 6fd4567
Showing
11 changed files
with
200 additions
and
31 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
22 changes: 22 additions & 0 deletions
22
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,22 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Api\Auth; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Http\Requests\Api\ForgotPasswordRequest; | ||
use Illuminate\Http\JsonResponse; | ||
use Illuminate\Support\Facades\Password; | ||
|
||
class ForgotPasswordController extends Controller | ||
{ | ||
public function __invoke(ForgotPasswordRequest $request): JsonResponse | ||
{ | ||
$status = Password::sendResetLink( | ||
$request->only('email') | ||
); | ||
|
||
return $status === Password::RESET_LINK_SENT | ||
? response()->json(['message' => __('L\'e-mail de réinitialisation du mot de passe a été envoyé avec succès !')]) | ||
: response()->json(['error' => __('Un courriel ne pourrait être envoyé à cette adresse électronique !')], 401); | ||
} | ||
} |
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\Http\Requests\Api\ResetPasswordRequest; | ||
use Illuminate\Auth\Events\PasswordReset; | ||
use Illuminate\Http\JsonResponse; | ||
use Illuminate\Support\Facades\Hash; | ||
use Illuminate\Support\Facades\Password; | ||
use Illuminate\Support\Str; | ||
|
||
class ResetPasswordController extends Controller | ||
{ | ||
public function __invoke(ResetPasswordRequest $request): JsonResponse | ||
{ | ||
$status = Password::reset( | ||
$request->only('email', 'password', 'password_confirmation', 'token'), | ||
function ($user) use ($request) { | ||
$user->forceFill([ | ||
'password' => Hash::make($request->password), | ||
'remember_token' => Str::random(60), | ||
])->save(); | ||
|
||
event(new PasswordReset($user)); | ||
} | ||
); | ||
|
||
return $status === Password::PASSWORD_RESET | ||
? response()->json(['message' => __('Votre mot de passe a été réinitialisé avec succès !')]) | ||
: response()->json(['error' => __('Le jeton de réinitialisation du mot de passe est invalide !')], 401); | ||
} | ||
} |
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,30 @@ | ||
<?php | ||
|
||
namespace App\Http\Requests\Api; | ||
|
||
use Illuminate\Foundation\Http\FormRequest; | ||
|
||
class ForgotPasswordRequest extends FormRequest | ||
{ | ||
/** | ||
* Determine if the user is authorized to make this request. | ||
* | ||
* @return bool | ||
*/ | ||
public function authorize(): bool | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* Get the validation rules that apply to the request. | ||
* | ||
* @return array<string, mixed> | ||
*/ | ||
public function rules(): array | ||
{ | ||
return [ | ||
'email' => 'required|email|exists:users,email', | ||
]; | ||
} | ||
} |
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,39 @@ | ||
<?php | ||
|
||
namespace App\Http\Requests\Api; | ||
|
||
use Illuminate\Foundation\Http\FormRequest; | ||
use Illuminate\Validation\Rules\Password; | ||
|
||
class ResetPasswordRequest extends FormRequest | ||
{ | ||
/** | ||
* Determine if the user is authorized to make this request. | ||
* | ||
* @return bool | ||
*/ | ||
public function authorize(): bool | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* Get the validation rules that apply to the request. | ||
* | ||
* @return array<string, mixed> | ||
*/ | ||
public function rules(): array | ||
{ | ||
return [ | ||
'token' => 'required', | ||
'email' => ['required', 'email', 'exists:users,email'], | ||
'password' => [ | ||
'required', | ||
'confirmed', | ||
app()->environment('local') | ||
? Password::min(8) | ||
: Password::min(8)->mixedCase()->numbers()->symbols(), | ||
], | ||
]; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -23,4 +23,6 @@ | |
'token' => env('SLACK_API_TOKEN', null), | ||
], | ||
|
||
'spa_url' => env('FRONTEND_APP_URL', 'http://localhost:4200'), | ||
|
||
]; |
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
Oops, something went wrong.