Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
autologout
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
autologout
Commits
1ae11d4a
Commit
1ae11d4a
authored
2 years ago
by
Hardik Patel
Committed by
Jakob P
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3101732
: After logout due to inactivity , login redirection is not right
parent
4d14dbb9
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
autologout.post_update.php
+13
-0
13 additions, 0 deletions
autologout.post_update.php
autologout.services.yml
+1
-1
1 addition, 1 deletion
autologout.services.yml
src/EventSubscriber/AutologoutSubscriber.php
+54
-1
54 additions, 1 deletion
src/EventSubscriber/AutologoutSubscriber.php
with
68 additions
and
2 deletions
autologout.post_update.php
0 → 100644
+
13
−
0
View file @
1ae11d4a
<?php
/**
* @file
* Perform updates once other modules have made their own updates.
*/
/**
* Clear Caches to reload services container, issue #3101732.
*/
function
autologout_post_update_fix_login_redirection_path
()
{
drupal_flush_all_caches
();
}
This diff is collapsed.
Click to expand it.
autologout.services.yml
+
1
−
1
View file @
1ae11d4a
...
...
@@ -3,7 +3,7 @@ services:
class
:
Drupal\autologout\EventSubscriber\AutologoutSubscriber
tags
:
-
{
name
:
event_subscriber
}
arguments
:
[
'
@autologout.manager'
,
'
@current_user'
,
'
@config.factory'
,
'
@theme.manager'
,
'
@datetime.time'
,
'
@request_stack'
]
arguments
:
[
'
@autologout.manager'
,
'
@current_user'
,
'
@config.factory'
,
'
@theme.manager'
,
'
@datetime.time'
,
'
@request_stack'
,
'
@language_manager'
]
autologout.manager
:
class
:
Drupal\autologout\AutologoutManager
...
...
This diff is collapsed.
Click to expand it.
src/EventSubscriber/AutologoutSubscriber.php
+
54
−
1
View file @
1ae11d4a
...
...
@@ -11,6 +11,9 @@ use Symfony\Component\HttpFoundation\RequestStack;
use
Symfony\Component\HttpKernel\KernelEvents
;
use
Symfony\Component\HttpKernel\Event\GetResponseEvent
;
use
Symfony\Component\EventDispatcher\EventSubscriberInterface
;
use
Drupal\Core\Language\LanguageManagerInterface
;
use
Drupal\Core\Url
;
use
Symfony\Component\HttpFoundation\RedirectResponse
;
/**
* Defines autologout Subscriber.
...
...
@@ -59,6 +62,13 @@ class AutologoutSubscriber implements EventSubscriberInterface {
*/
protected
$requestStack
;
/**
* The language manager.
*
* @var \Drupal\Core\Language\LanguageManagerInterface
*/
protected
$languageManager
;
/**
* Constructs an AutologoutSubscriber object.
*
...
...
@@ -74,14 +84,17 @@ class AutologoutSubscriber implements EventSubscriberInterface {
* The time service.
* @param \Symfony\Component\HttpFoundation\RequestStack $requestStack
* The request stack service.
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
* The language manager.
*/
public
function
__construct
(
AutologoutManagerInterface
$autologout
,
AccountInterface
$account
,
ConfigFactory
$config
,
ThemeManager
$theme
,
TimeInterface
$time
,
RequestStack
$requestStack
)
{
public
function
__construct
(
AutologoutManagerInterface
$autologout
,
AccountInterface
$account
,
ConfigFactory
$config
,
ThemeManager
$theme
,
TimeInterface
$time
,
RequestStack
$requestStack
,
LanguageManagerInterface
$language_manager
)
{
$this
->
autoLogoutManager
=
$autologout
;
$this
->
currentUser
=
$account
;
$this
->
config
=
$config
;
$this
->
theme
=
$theme
;
$this
->
time
=
$time
;
$this
->
requestStack
=
$requestStack
;
$this
->
languageManager
=
$language_manager
;
}
/**
...
...
@@ -104,6 +117,46 @@ class AutologoutSubscriber implements EventSubscriberInterface {
return
;
}
// If user is not anonymous.
if
(
$uid
!=
0
)
{
$session
=
$this
->
requestStack
->
getCurrentRequest
()
->
getSession
();
$auto_redirect
=
$session
->
get
(
'auto_redirect'
);
// Get http referer.
$referer
=
""
;
$request
=
$this
->
requestStack
->
getCurrentRequest
();
if
(
$request
->
server
->
get
(
'HTTP_REFERER'
))
{
$referer
=
$request
->
server
->
get
(
'HTTP_REFERER'
);
}
// Get query string from http referer url.
$parse_url
=
parse_url
(
$referer
,
PHP_URL_QUERY
);
// If http referer url has 'destination' and session is not set,
// then only redirect to user page if uid dosen't match.
if
((
strpos
(
$parse_url
,
'destination'
)
!==
FALSE
)
&&
empty
(
$auto_redirect
))
{
parse_str
(
$parse_url
,
$output
);
$destination_uid
=
explode
(
"/"
,
$output
[
'destination'
]);
// If array contains language code, remove it.
$languagecode
=
$this
->
languageManager
->
getCurrentLanguage
()
->
getId
();
if
(
$destination_uid
[
1
]
===
$languagecode
)
{
unset
(
$destination_uid
[
1
]);
$destination_uid
=
array_values
(
$destination_uid
);
}
// If destination uid and actual uid does not match then,
// redirect to loggedin user page.
if
((
$destination_uid
[
1
]
==
"user"
)
&&
(
$destination_uid
[
2
]
!=
$uid
))
{
$auto_redirect
=
$session
->
set
(
'auto_redirect'
,
1
);
$login_url
=
Url
::
fromRoute
(
'user.page'
,
[],
[
'absolute'
=>
TRUE
])
->
toString
();
// Redirect user to user page.
$response
=
new
RedirectResponse
(
$login_url
);
$event
->
setResponse
(
$response
);
$event
->
stopPropagation
();
}
}
}
if
(
$this
->
autoLogoutManager
->
preventJs
())
{
return
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment