function opigno_dashboard_user_login in Opigno dashboard 8
Implements hook_user_login().
File
- ./
opigno_dashboard.module, line 188 - Contains opigno_dashboard.module.
Code
function opigno_dashboard_user_login(UserInterface $account) {
$route_name = \Drupal::routeMatch()
->getRouteName();
// Skip on user reset routed and reset pass.
if (strpos($route_name, 'rest.') !== FALSE || $route_name === 'user.reset.login') {
return;
}
if (!empty($_GET['profile']) && $_GET['profile'] == 'opigno_lms' && !empty($_POST['form_id']) && $_POST['form_id'] == 'install_configure_form') {
// Do not use this during installation.
return;
}
// Redirect to the previous page (if exists), otherwise - or to the homepage
// after the login.
$previous = \Drupal::service('user.private_tempstore')
->get('opigno_dashboard')
->get('prev_path') ?? NULL;
// Add the "tour" parameter to the url to avoid the unneeded page reload in
// the next case: if the tour module exists and enabled and if the route is in
// the list of tour-enabled and hasn't been already viewed.
$params = [];
$default_path = \Drupal::config('system.site')
->get('page.front') ?? '<front>';
$default_route = \Drupal::pathValidator()
->getUrlIfValid($default_path)
->getRouteName();
if (\Drupal::moduleHandler()
->moduleExists('opigno_tour') && OpignoTourFunctions::checkRouteTour($default_route) && !OpignoTourFunctions::isPageUserViewed($default_route, $account
->id())) {
$params = [
'query' => [
'tour' => 1,
],
];
}
$url = $previous ? Url::fromUri('internal:' . $previous)
->toString() : Url::fromRoute('<front>', [], $params)
->toString();
$url = $url instanceof GeneratedUrl ? $url
->getGeneratedUrl() : $url;
$response = new RedirectResponse($url);
$response
->send();
}