101 lines
2.4 KiB
PHP
101 lines
2.4 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Http\Controllers\Club\Auth;
|
||
|
|
|
||
|
|
use App\Http\Controllers\Controller;
|
||
|
|
use Illuminate\Auth\Events\PasswordReset;
|
||
|
|
use Illuminate\Contracts\Auth\PasswordBroker;
|
||
|
|
use Illuminate\Contracts\Auth\StatefulGuard;
|
||
|
|
use Illuminate\Contracts\View\View;
|
||
|
|
use Illuminate\Foundation\Auth\ResetsPasswords;
|
||
|
|
use Illuminate\Http\Request;
|
||
|
|
use Illuminate\Support\Facades\Auth;
|
||
|
|
use Illuminate\Support\Facades\Password;
|
||
|
|
use Illuminate\Support\Str;
|
||
|
|
|
||
|
|
class ResetPasswordController extends Controller
|
||
|
|
{
|
||
|
|
use ResetsPasswords;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Create a new controller instance.
|
||
|
|
*
|
||
|
|
* @return void
|
||
|
|
*/
|
||
|
|
public function __construct()
|
||
|
|
{
|
||
|
|
$this->middleware('guest:club');
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get the guard to be used during authentication.
|
||
|
|
*
|
||
|
|
* @return \Illuminate\Contracts\Auth\StatefulGuard
|
||
|
|
*/
|
||
|
|
protected function guard(): StatefulGuard
|
||
|
|
{
|
||
|
|
return Auth::guard('club');
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Display the password reset view for the given token.
|
||
|
|
*
|
||
|
|
* If no token is present, display the link request form.
|
||
|
|
*
|
||
|
|
* @param \Illuminate\Http\Request $request
|
||
|
|
* @return \Illuminate\Contracts\View\View
|
||
|
|
*/
|
||
|
|
public function showResetForm(Request $request): View
|
||
|
|
{
|
||
|
|
$token = $request->route()->parameter('token');
|
||
|
|
|
||
|
|
return view('club.auth.passwords.reset')->with(
|
||
|
|
['token' => $token, 'email' => $request->email]
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Reset the given user's password.
|
||
|
|
*
|
||
|
|
* @param mixed $customer
|
||
|
|
* @param mixed $password
|
||
|
|
* @return void
|
||
|
|
* @throws \Illuminate\Validation\ValidationException If something goes wrong.
|
||
|
|
*/
|
||
|
|
protected function resetPassword(mixed $customer, mixed $password): void
|
||
|
|
{
|
||
|
|
/** @var \App\Models\Customer $customer */
|
||
|
|
|
||
|
|
$customer->password = $password;
|
||
|
|
|
||
|
|
$customer->setRememberToken(Str::random(60));
|
||
|
|
$customer->last_connection = \now();
|
||
|
|
|
||
|
|
$customer->saveOrFail();
|
||
|
|
|
||
|
|
event(new PasswordReset($customer));
|
||
|
|
|
||
|
|
$this->guard()->login($customer);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get the post register / login redirect path.
|
||
|
|
*
|
||
|
|
* @return string
|
||
|
|
*/
|
||
|
|
public function redirectPath(): string
|
||
|
|
{
|
||
|
|
return $this->authLoggedRedirectPath();
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get the broker to be used during password reset.
|
||
|
|
*
|
||
|
|
* @return \Illuminate\Contracts\Auth\PasswordBroker
|
||
|
|
*/
|
||
|
|
public function broker(): PasswordBroker
|
||
|
|
{
|
||
|
|
return Password::broker('customers');
|
||
|
|
}
|
||
|
|
}
|