class LogintobogganController in LoginToboggan 8
Class LogintobogganController.
@package Drupal\logintoboggan\Controller
Hierarchy
- class \Drupal\Core\Controller\ControllerBase implements ContainerInjectionInterface uses LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\logintoboggan\Controller\LogintobogganController
Expanded class hierarchy of LogintobogganController
File
- src/
Controller/ LogintobogganController.php, line 17
Namespace
Drupal\logintoboggan\ControllerView source
class LogintobogganController extends ControllerBase {
/**
* Basic create.
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('module_handler'));
}
/**
* This will return the output of the page.
*/
public function logintobogganValidateEmail($user, $timestamp, $hashed_pass, $operation) {
$account = user::load($user);
// $cur_account = \Drupal::currentUser();
$cur_account = $this
->currentUser();
$hash_2 = user_pass_rehash($account, $timestamp);
// If you don't need to verify email (i.e. can set password), that's
// effectively ok for immediate login.
$must_verify = $this
->config('user.settings')
->get('verify_mail');
// Does have to verify but has not logged in previously OR
// the user can login without verifying email first
// - the hashed password is correct.
$stop = '';
if ($must_verify && !$account
->getLastLoginTime() || !$must_verify && $hashed_pass == user_pass_rehash($account, $timestamp)) {
$this
->getLogger('user')
->notice('E-mail validation URL used for %name with
timestamp @timestamp.', [
'%name' => $account
->getAccountName(),
'@timestamp' => $timestamp,
]);
// Add trusted role.
LogintobogganUtility::processValidation($account);
// Where do we redirect after confirming the account?
$redirect_setting = $this
->config('logintoboggan.settings')
->get('redirect_on_confirm');
$redirect_on_register = !empty($redirect_setting) ? $redirect_setting : '/';
$redirect = LogintobogganUtility::processRedirect($redirect_on_register, $account);
switch ($operation) {
// Proceed with normal user login, as long as it's open registration and
// account hasn't been blocked.
case 'login':
// Only show the validated message if there's a valid trusted role.
if (!$must_verify) {
$this
->messenger()
->addMessage($this
->t('You have successfully validated your e-mail address.'), 'status');
}
if ($account
->isBlocked()) {
$this
->messenger()
->addMessage($this
->t('Your account is currently blocked -- login cancelled.'), 'error');
return new RedirectResponse(Url::fromRoute('<front>')
->toString());
}
else {
$redirect = logintoboggan_process_login($account, $redirect);
return new RedirectResponse($redirect
->toString());
}
break;
// Admin validation.
case 'admin':
if (!$must_verify) {
_user_mail_notify('status_activated', $account);
}
$this
->messenger()
->addMessage($this
->t('You have successfully validated %user.', [
'%user' => $account
->getUsername(),
]));
if ($cur_account
->isAnonymous()) {
return new RedirectResponse(Url::fromRoute('<front>', [
'user' => $user,
])
->toString());
}
else {
return new RedirectResponse(Url::fromRoute('entity.user.edit_form', [
'user' => $user,
])
->toString());
}
break;
// Catch all.
default:
$this
->messenger()
->addMessage($this
->t('You have successfully validated %user.', [
'%user' => $account
->getUsername(),
]));
return new RedirectResponse(Url::fromRoute('<front>')
->toString());
}
}
else {
$message = $this
->t('Sorry, you can only use your validation link once for security reasons.');
// No one currently logged in, go straight to user login page.
if ($cur_account
->isAnonymous()) {
$message .= $this
->t('Please log in with your username and password instead now.');
$goto = 'user.login';
}
else {
$goto = 'user.page';
}
$this
->messenger()
->addMessage($message, 'error');
return new RedirectResponse(Url::fromRoute($goto)
->toString());
}
}
/**
* This will return the output of the page.
*/
public function logintobogganResendValidation($user) {
$account = user::load($user);
_user_mail_notify('register_no_approval_required', $account);
// Notify admin or user that e-mail was sent and return to user edit form.
if ($this
->currentUser()
->hasPermission('administer users')) {
$this
->messenger()
->addMessage($this
->t("A validation e-mail has been sent to the user's e-mail address."));
}
else {
$this
->messenger()
->addMessage($this
->t('A validation e-mail has been sent to your e-mail address. You will need to follow the instructions in that message in order to gain full access to the site.'));
}
return new RedirectResponse(URL::fromRoute('entity.user.edit_form', [
'user' => $user,
])
->toString());
}
/**
* This will return the output of the page.
*/
public function logintobogganDenied() {
$account = $this
->currentUser();
if ($account
->isAnonymous()) {
$page['#title'] = $this
->t('Access Denied / User log in');
}
else {
$page = [
'#title' => $this
->t('Access Denied'),
'#theme' => 'lt_access_denied',
];
}
return $page;
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ControllerBase:: |
protected | property | The configuration factory. | |
ControllerBase:: |
protected | property | The current user service. | 1 |
ControllerBase:: |
protected | property | The entity form builder. | |
ControllerBase:: |
protected | property | The entity manager. | |
ControllerBase:: |
protected | property | The entity type manager. | |
ControllerBase:: |
protected | property | The form builder. | 2 |
ControllerBase:: |
protected | property | The key-value storage. | 1 |
ControllerBase:: |
protected | property | The language manager. | 1 |
ControllerBase:: |
protected | property | The module handler. | 2 |
ControllerBase:: |
protected | property | The state service. | |
ControllerBase:: |
protected | function | Returns the requested cache bin. | |
ControllerBase:: |
protected | function | Retrieves a configuration object. | |
ControllerBase:: |
private | function | Returns the service container. | |
ControllerBase:: |
protected | function | Returns the current user. | 1 |
ControllerBase:: |
protected | function | Retrieves the entity form builder. | |
ControllerBase:: |
protected | function | Retrieves the entity manager service. | |
ControllerBase:: |
protected | function | Retrieves the entity type manager. | |
ControllerBase:: |
protected | function | Returns the form builder service. | 2 |
ControllerBase:: |
protected | function | Returns a key/value storage collection. | 1 |
ControllerBase:: |
protected | function | Returns the language manager service. | 1 |
ControllerBase:: |
protected | function | Returns the module handler. | 2 |
ControllerBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
ControllerBase:: |
protected | function | Returns the state storage service. | |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
LogintobogganController:: |
public static | function |
Basic create. Overrides ControllerBase:: |
|
LogintobogganController:: |
public | function | This will return the output of the page. | |
LogintobogganController:: |
public | function | This will return the output of the page. | |
LogintobogganController:: |
public | function | This will return the output of the page. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |