101 lines
3.2 KiB
PHP
101 lines
3.2 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Http\Controllers\Backend\Auth;
|
||
|
|
|
||
|
|
use App\Http\Controllers\Controller;
|
||
|
|
use App\Providers\RouteServiceProvider;
|
||
|
|
use App\Rules\Password as PasswordRule;
|
||
|
|
use Illuminate\Support\Facades\Password;
|
||
|
|
use Illuminate\Foundation\Auth\ResetsPasswords;
|
||
|
|
use Illuminate\Http\Request;
|
||
|
|
|
||
|
|
class ResetPasswordController extends Controller
|
||
|
|
{
|
||
|
|
/*
|
||
|
|
|--------------------------------------------------------------------------
|
||
|
|
| Password Reset Controller
|
||
|
|
|--------------------------------------------------------------------------
|
||
|
|
|
|
||
|
|
| This controller is responsible for handling password reset requests
|
||
|
|
| and uses a simple trait to include this behavior. You're free to
|
||
|
|
| explore this trait and override any methods you wish to tweak.
|
||
|
|
|
|
||
|
|
*/
|
||
|
|
|
||
|
|
use ResetsPasswords;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Where to redirect users after resetting their password.
|
||
|
|
*
|
||
|
|
* @var string
|
||
|
|
*/
|
||
|
|
protected $redirectTo = RouteServiceProvider::HOME;
|
||
|
|
|
||
|
|
public function showResetForm(Request $request)
|
||
|
|
{
|
||
|
|
$token = $request->route()->parameter('token');
|
||
|
|
|
||
|
|
return view('backend.auth.passwords.reset')->with(
|
||
|
|
['token' => $token, 'email' => $request->email]
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Reset the given user's password.
|
||
|
|
*
|
||
|
|
* @param \Illuminate\Http\Request $request
|
||
|
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse
|
||
|
|
*/
|
||
|
|
public function reset(Request $request)
|
||
|
|
{
|
||
|
|
$request->validate($this->rules($request->all()), $this->validationErrorMessages());
|
||
|
|
|
||
|
|
// 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
|
||
|
|
// database. Otherwise we will parse the error and return the response.
|
||
|
|
$response = $this->broker()->reset(
|
||
|
|
$this->credentials($request), function ($user, $password) {
|
||
|
|
$this->resetPassword($user, $password);
|
||
|
|
}
|
||
|
|
);
|
||
|
|
|
||
|
|
// If the password was successfully reset, we will redirect the user back to
|
||
|
|
// the application's home authenticated view. If there is an error we can
|
||
|
|
// redirect them back to where they came from with their error message.
|
||
|
|
return $response == Password::PASSWORD_RESET
|
||
|
|
? $this->sendResetResponse($request, $response)
|
||
|
|
: $this->sendResetFailedResponse($request, $response);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get the password reset validation rules.
|
||
|
|
*
|
||
|
|
* @return array
|
||
|
|
*/
|
||
|
|
protected function rules(array $data)
|
||
|
|
{
|
||
|
|
return [
|
||
|
|
'token' => ['required'],
|
||
|
|
'email' => ['required','email'],
|
||
|
|
'password' => ['required','confirmed', PasswordRule::min(8)]
|
||
|
|
];
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get the password reset credentials from the request.
|
||
|
|
*
|
||
|
|
* @param \Illuminate\Http\Request $request
|
||
|
|
* @return array
|
||
|
|
*/
|
||
|
|
protected function credentials(Request $request)
|
||
|
|
{
|
||
|
|
$email = strtolower($request->get('email'));
|
||
|
|
return [
|
||
|
|
'email_hash' => md5($email),
|
||
|
|
'password' => $request->get('password'),
|
||
|
|
'password_confirmation' => $request->get('password_confirmation'),
|
||
|
|
'token' => $request->get('token')
|
||
|
|
];
|
||
|
|
}
|
||
|
|
}
|