Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
kohinos-tav
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
6
Merge Requests
6
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
agplv3
kohinos-tav
Commits
0ece0ca1
Commit
0ece0ca1
authored
Aug 11, 2023
by
Damien Moulard
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop'
parents
d200c690
2a3af91b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
2 deletions
+56
-2
services.yaml
config/services.yaml
+8
-2
LoginListener.php
src/EventListener/LoginListener.php
+48
-0
No files found.
config/services.yaml
View file @
0ece0ca1
...
@@ -750,4 +750,10 @@ services:
...
@@ -750,4 +750,10 @@ services:
app.menu_listener
:
app.menu_listener
:
class
:
App\EventListener\MenuBuilderListener
class
:
App\EventListener\MenuBuilderListener
tags
:
tags
:
-
{
name
:
kernel.event_listener
,
event
:
sonata.admin.event.configure.menu.sidebar
,
method
:
addMenuItems
}
-
{
name
:
kernel.event_listener
,
event
:
sonata.admin.event.configure.menu.sidebar
,
method
:
addMenuItems
}
\ No newline at end of file
App\EventListener\LoginListener
:
arguments
:
-
'
@session'
tags
:
-
{
name
:
'
kernel.event_listener'
,
event
:
'
security.interactive_login'
}
\ No newline at end of file
src/EventListener/LoginListener.php
0 → 100644
View file @
0ece0ca1
<?php
namespace
App\EventListener
;
use
App\Entity\Usergroup
;
use
FOS\UserBundle\Model\UserInterface
;
use
Symfony\Component\HttpFoundation\Session\SessionInterface
;
use
Symfony\Component\Security\Http\Event\InteractiveLoginEvent
;
//https://redmine.coopdev.fr/issues/4878
//Fill session again after remember_me login
//https://stackoverflow.com/questions/7995366/how-can-i-listen-for-remember-me-reauthentication-events-in-symfony2
//https://rihards.com/2018/symfony-login-event-listener/
class
LoginListener
{
private
$session
;
public
function
__construct
(
SessionInterface
$session
)
{
$this
->
session
=
$session
;
}
public
function
onSecurityInteractiveLogin
(
InteractiveLoginEvent
$event
)
{
$tokenName
=
(
string
)
$event
->
getAuthenticationToken
();
if
(
strpos
(
$tokenName
,
"RememberMeToken"
)
!==
false
)
{
$user
=
$event
->
getAuthenticationToken
()
->
getUser
();
if
(
$user
->
getGroups
()
->
count
()
>
0
)
{
$groupe
=
$user
->
getGroups
()
->
first
();
$this
->
updateSessionGroup
(
$user
,
$groupe
);
}
}
}
private
function
updateSessionGroup
(
UserInterface
$user
,
Usergroup
$groupe
)
{
if
(
in_array
(
'ROLE_PRESTATAIRE'
,
$groupe
->
getRoles
())
&&
count
(
$user
->
getPrestataires
())
>=
1
)
{
$this
->
session
->
set
(
'_prestagere'
,
$user
->
getPrestataires
()[
0
]);
}
elseif
(
in_array
(
'ROLE_CAISSIER'
,
$groupe
->
getRoles
())
&&
count
(
$user
->
getCaissiers
())
>=
1
)
{
$this
->
session
->
set
(
'_prestagere'
,
$user
->
getCaissiers
()[
0
]);
}
elseif
(
in_array
(
'ROLE_COMPTOIR'
,
$groupe
->
getRoles
())
&&
count
(
$user
->
getComptoirsGeres
())
>=
1
)
{
$this
->
session
->
set
(
'_comptoirgere'
,
$user
->
getComptoirsGeres
()[
0
]);
}
elseif
((
in_array
(
'ROLE_TRESORIER'
,
$groupe
->
getRoles
())
||
in_array
(
'ROLE_CONTACT'
,
$groupe
->
getRoles
())
||
in_array
(
'ROLE_GESTION_GROUPE'
,
$groupe
->
getRoles
()))
&&
count
(
$user
->
getGroupesGeres
())
>=
1
)
{
$this
->
session
->
set
(
'_groupegere'
,
$user
->
getGroupesGeres
()[
0
]);
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment