Forgot and Reset controller changed request methods

This commit is contained in:
Cüneyt Şentürk 2023-04-20 17:49:34 +03:00
parent 2534d28dca
commit 9b58482613
4 changed files with 73 additions and 8 deletions

View File

@ -5,7 +5,7 @@ namespace App\Http\Controllers\Auth;
use App\Abstracts\Http\Controller; use App\Abstracts\Http\Controller;
use Illuminate\Foundation\Auth\SendsPasswordResetEmails; use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
use Illuminate\Http\Request; use App\Http\Requests\Auth\Forgot as Request;
use Illuminate\Support\Facades\Password; use Illuminate\Support\Facades\Password;
class Forgot extends Controller class Forgot extends Controller
@ -42,13 +42,11 @@ class Forgot extends Controller
/** /**
* Send a reset link to the given user. * Send a reset link to the given user.
* *
* @param \Illuminate\Http\Request $request * @param \App\Http\Requests\Auth\Forgot $request
* @return \Illuminate\Http\RedirectResponse * @return \Illuminate\Http\RedirectResponse
*/ */
public function store(Request $request) public function store(Request $request)
{ {
$this->validateEmail($request);
// We will send the password reset link to this user. Once we have attempted // 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 // 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. // need to show to the user. Finally, we'll send out a proper response.
@ -96,7 +94,7 @@ class Forgot extends Controller
'error' => true, 'error' => true,
'message' => trans('passwords.user'), 'message' => trans('passwords.user'),
'data' => null, 'data' => null,
'redirect' => null, 'redirect' => route('forgot'),
]; ];
return response()->json($response); return response()->json($response);

View File

@ -4,7 +4,7 @@ namespace App\Http\Controllers\Auth;
use App\Abstracts\Http\Controller; use App\Abstracts\Http\Controller;
use Illuminate\Foundation\Auth\ResetsPasswords; use Illuminate\Foundation\Auth\ResetsPasswords;
use Illuminate\Http\Request; use App\Http\Requests\Auth\Reset as Request;
use Illuminate\Support\Facades\Password; use Illuminate\Support\Facades\Password;
use Illuminate\Support\Str; use Illuminate\Support\Str;
@ -36,10 +36,15 @@ class Reset extends Controller
); );
} }
/**
* Send a reset link to the given user.
*
* @param \App\Http\Requests\Auth\Reset $request
*
* @return \Illuminate\Http\JsonResponse
*/
public function store(Request $request) public function store(Request $request)
{ {
$this->validate($request, $this->rules(), $this->validationErrorMessages());
// Here we will attempt to reset the user's password. If it is successful we // Here we will attempt to reset the user's password. If it is successful we
// will update the password on an actual user model and persist it to the // will update the password on an actual user model and persist it to the
// database. Otherwise we will parse the error and return the response. // database. Otherwise we will parse the error and return the response.

View File

@ -0,0 +1,30 @@
<?php
namespace App\Http\Requests\Auth;
use Illuminate\Foundation\Http\FormRequest;
class Forgot extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'email' => 'required|email',
];
}
}

View File

@ -0,0 +1,32 @@
<?php
namespace App\Http\Requests\Auth;
use Illuminate\Foundation\Http\FormRequest;
class Reset extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'token' => 'required',
'email' => 'required|email',
'password' => 'required|confirmed|min:6',
];
}
}