From 70c845dc5fa37fcdcda0a932ca24c5e8d47b5151 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=27Guessan=20Kouadio=20Elis=C3=A9e?= Date: Wed, 23 Mar 2022 23:03:06 +0000 Subject: [PATCH] fix: password forgot testing --- app/Http/Actions/UserActions.php | 5 +++++ app/Http/Controllers/Auth/ForgotPasswordController.php | 6 +++--- core/Database/Model.php | 1 + tests/Application/Auth/PasswordForgotTest.php | 8 ++++---- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/app/Http/Actions/UserActions.php b/app/Http/Actions/UserActions.php index 086d15cb..1070c780 100644 --- a/app/Http/Actions/UserActions.php +++ b/app/Http/Actions/UserActions.php @@ -34,4 +34,9 @@ public static function update(array $data, string $email) return $user; } + + public static function updatPassword(string $password, string $email) + { + return self::update(['password' => $password], $email); + } } diff --git a/app/Http/Controllers/Auth/ForgotPasswordController.php b/app/Http/Controllers/Auth/ForgotPasswordController.php index c6747cc9..4f74275f 100644 --- a/app/Http/Controllers/Auth/ForgotPasswordController.php +++ b/app/Http/Controllers/Auth/ForgotPasswordController.php @@ -62,10 +62,10 @@ public function reset(Request $request, Response $response) $response->redirect()->to("password/new?email={$request->email}")->go(); } - public function update(Request $request, Response $response) + public function update(Request $request, Response $response, LoginValidator $loginValidator) { - LoginValidator::make($request->inputs())->redirectBackOnFail($response); - $user = UserActions::update(['password' => $request->password], $request->email); + $loginValidator->validate($request->inputs()); + $user = UserActions::updatPassword($request->password, $request->email); if (!$user) { Alert::default(__('password_not_reset'))->error(); diff --git a/core/Database/Model.php b/core/Database/Model.php index c342be1c..f3395bfe 100644 --- a/core/Database/Model.php +++ b/core/Database/Model.php @@ -13,6 +13,7 @@ */ class Model { + public $id; public static $table = ''; public function __construct(string $table, $data = null) diff --git a/tests/Application/Auth/PasswordForgotTest.php b/tests/Application/Auth/PasswordForgotTest.php index ce8f51b5..2254fa2b 100644 --- a/tests/Application/Auth/PasswordForgotTest.php +++ b/tests/Application/Auth/PasswordForgotTest.php @@ -6,12 +6,12 @@ * @link https://github.com/eliseekn/tinymvc */ -use App\Database\Factories\TokenFactory; -use App\Database\Factories\UserFactory; -use App\Database\Models\Token; -use App\Database\Models\User; use Core\Support\Encryption; +use App\Database\Models\User; +use App\Database\Models\Token; use Core\Testing\ApplicationTestCase; +use App\Database\Factories\UserFactory; +use App\Database\Factories\TokenFactory; use Core\Testing\Concerns\RefreshDatabase; class PasswordForgotTest extends ApplicationTestCase