Skip to content

Commit

Permalink
fix: forgot password request with non existing email now returns a fo…
Browse files Browse the repository at this point in the history
…rm request validator error
  • Loading branch information
ArielMejiaDev committed Oct 13, 2021
1 parent 7453453 commit 80c33ac
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
7 changes: 7 additions & 0 deletions .idea/json-api-auth.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/php.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class PasswordResetLinkController
{
public function __invoke(PasswordResetLinkRequest $request): JsonResponse
{
/** @var User $user */
$user = $request->getUser();
$token = Str::random(60);

Expand Down
15 changes: 5 additions & 10 deletions stubs/App/Http/Requests/JsonApiAuth/PasswordResetLinkRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Models\User;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class PasswordResetLinkRequest extends FormRequest
{
Expand All @@ -12,7 +13,7 @@ class PasswordResetLinkRequest extends FormRequest
*
* @return bool
*/
public function authorize()
public function authorize(): bool
{
return true;
}
Expand All @@ -22,23 +23,17 @@ public function authorize()
*
* @return array
*/
public function rules()
public function rules(): array
{
return [
'email' => 'required|email',
'email' => ['required', 'email', Rule::exists(User::class)],
];
}

public function getUser()
{
$email = $this->get('email');

if(User::where('email', $email)->doesntExist()) {
return response()->json([
'message' => 'User does not exists',
], 404);
}

return User::whereEmail($email)->first();
return User::query()->where('email', $email)->first();
}
}

0 comments on commit 80c33ac

Please sign in to comment.