PrlpController.php in Password Reset Landing Page (PRLP) 8
File
src/Controller/PrlpController.php
View source
<?php
namespace Drupal\prlp\Controller;
use Drupal\Core\Url;
use Drupal\user\Controller\UserController;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Drupal\Core\Messenger\MessengerInterface;
class PrlpController extends UserController {
public function prlpResetPassLogin(Request $request, $uid, $timestamp, $hash) {
$response = parent::resetPassLogin($uid, $timestamp, $hash);
try {
$parsed_url = parse_url($response
->getTargetUrl());
$response_route = Url::fromUserInput($parsed_url['path']);
if ($response_route && $response_route
->getRouteName() == 'entity.user.edit_form') {
if ($request->request
->has('pass') && ($passwords = $request->request
->get('pass'))) {
$pass = is_array($passwords) ? reset($passwords) : NULL;
if (!empty($pass)) {
$user = $this->userStorage
->load($uid);
$user
->setPassword($pass);
$user
->save();
$this
->messenger()
->deleteByType(MessengerInterface::TYPE_STATUS);
$this
->messenger()
->addStatus($this
->t('Your new password has been saved.'));
}
}
$login_destination = $this
->config('prlp.settings')
->get('login_destination');
if (!$login_destination) {
$login_destination = '/user/%user/edit';
}
$login_destination = str_replace('%user', $uid, $login_destination);
$login_destination = str_replace('%front', $this
->config('system.site')
->get('page.front'), $login_destination);
if (substr($login_destination, 0, 1) !== '/') {
$login_destination = '/' . $login_destination;
}
return new RedirectResponse($login_destination);
}
} catch (\InvalidArgumentException $exception) {
user_logout();
$this
->messenger()
->deleteAll();
$this
->messenger()
->addError($this
->t('You have tried to use a one-time login link that has either been used or is no longer valid. Please request a new one using the form below.'));
}
return $this
->redirect('user.pass');
}
}