2016-09-03 21:09:00 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Http\Controllers\Auth;
|
|
|
|
|
2018-07-04 18:41:56 +00:00
|
|
|
use Illuminate\Support\Str;
|
|
|
|
use Prologue\Alerts\AlertsMessageBag;
|
|
|
|
use Illuminate\Contracts\Hashing\Hasher;
|
|
|
|
use Illuminate\Auth\Events\PasswordReset;
|
|
|
|
use Illuminate\Contracts\Events\Dispatcher;
|
2016-09-03 21:09:00 +00:00
|
|
|
use Pterodactyl\Http\Controllers\Controller;
|
|
|
|
use Illuminate\Foundation\Auth\ResetsPasswords;
|
2018-07-04 18:41:56 +00:00
|
|
|
use Pterodactyl\Contracts\Repository\UserRepositoryInterface;
|
2016-09-03 21:09:00 +00:00
|
|
|
|
|
|
|
class ResetPasswordController extends Controller
|
|
|
|
{
|
|
|
|
use ResetsPasswords;
|
|
|
|
|
2017-03-19 23:36:50 +00:00
|
|
|
/**
|
|
|
|
* The URL to redirect users to after password reset.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2016-09-04 23:08:46 +00:00
|
|
|
public $redirectTo = '/';
|
|
|
|
|
2018-07-04 18:41:56 +00:00
|
|
|
/**
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
protected $hasTwoFactor = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Prologue\Alerts\AlertsMessageBag
|
|
|
|
*/
|
|
|
|
private $alerts;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Illuminate\Contracts\Events\Dispatcher
|
|
|
|
*/
|
|
|
|
private $dispatcher;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Illuminate\Contracts\Hashing\Hasher
|
|
|
|
*/
|
|
|
|
private $hasher;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Contracts\Repository\UserRepositoryInterface
|
|
|
|
*/
|
|
|
|
private $userRepository;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ResetPasswordController constructor.
|
|
|
|
*
|
|
|
|
* @param \Prologue\Alerts\AlertsMessageBag $alerts
|
|
|
|
* @param \Illuminate\Contracts\Events\Dispatcher $dispatcher
|
|
|
|
* @param \Illuminate\Contracts\Hashing\Hasher $hasher
|
|
|
|
* @param \Pterodactyl\Contracts\Repository\UserRepositoryInterface $userRepository
|
|
|
|
*/
|
|
|
|
public function __construct(AlertsMessageBag $alerts, Dispatcher $dispatcher, Hasher $hasher, UserRepositoryInterface $userRepository)
|
|
|
|
{
|
|
|
|
$this->alerts = $alerts;
|
|
|
|
$this->dispatcher = $dispatcher;
|
|
|
|
$this->hasher = $hasher;
|
|
|
|
$this->userRepository = $userRepository;
|
|
|
|
}
|
|
|
|
|
2017-03-19 23:36:50 +00:00
|
|
|
/**
|
|
|
|
* Return the rules used when validating password reset.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
2017-11-18 21:09:58 +00:00
|
|
|
protected function rules(): array
|
2016-12-07 22:46:38 +00:00
|
|
|
{
|
2016-10-30 20:02:39 +00:00
|
|
|
return [
|
2017-04-28 03:44:26 +00:00
|
|
|
'token' => 'required',
|
|
|
|
'email' => 'required|email',
|
2017-11-18 21:09:58 +00:00
|
|
|
'password' => 'required|confirmed|min:8',
|
2016-10-30 20:02:39 +00:00
|
|
|
];
|
|
|
|
}
|
2018-07-04 18:41:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Reset the given user's password. If the user has two-factor authentication enabled on their
|
|
|
|
* account do not automatically log them in. In those cases, send the user back to the login
|
|
|
|
* form with a note telling them their password was changed and to log back in.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Contracts\Auth\CanResetPassword|\Pterodactyl\Models\User $user
|
|
|
|
* @param string $password
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
|
|
|
*/
|
|
|
|
protected function resetPassword($user, $password)
|
|
|
|
{
|
|
|
|
$user = $this->userRepository->update($user->id, [
|
|
|
|
'password' => $this->hasher->make($password),
|
|
|
|
$user->getRememberTokenName() => Str::random(60),
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->dispatcher->dispatch(new PasswordReset($user));
|
|
|
|
|
|
|
|
// If the user is not using 2FA log them in, otherwise skip this step and force a
|
|
|
|
// fresh login where they'll be prompted to enter a token.
|
|
|
|
if (! $user->use_totp) {
|
|
|
|
$this->guard()->login($user);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->hasTwoFactor = $user->use_totp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the response for a successful password reset.
|
|
|
|
*
|
|
|
|
* @param string $response
|
|
|
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse
|
|
|
|
*/
|
|
|
|
protected function sendResetResponse($response)
|
|
|
|
{
|
|
|
|
if ($this->hasTwoFactor) {
|
|
|
|
$this->alerts->success('Your password was successfully updated. Please log in to continue.')->flash();
|
|
|
|
}
|
|
|
|
|
|
|
|
return redirect($this->hasTwoFactor ? route('auth.login') : $this->redirectPath())
|
|
|
|
->with('status', trans($response));
|
|
|
|
}
|
2016-09-03 21:09:00 +00:00
|
|
|
}
|