-
-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #382 from arneruy/issue_194
[AdminBundle, GeneratorBundle, UserManagementBundle] Remove default hardcoded admin/admin
- Loading branch information
Showing
18 changed files
with
296 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
src/Kunstmaan/AdminBundle/EventListener/PasswordCheckListener.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?php | ||
|
||
namespace Kunstmaan\AdminBundle\EventListener; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Routing\Router; | ||
use Symfony\Component\HttpKernel\Controller\ControllerResolver; | ||
use Symfony\Component\HttpKernel\Event\GetResponseEvent; | ||
use Symfony\Component\HttpFoundation\RedirectResponse; | ||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; | ||
use Symfony\Component\Security\Core\Authorization\AuthorizationChecker; | ||
use Symfony\Component\HttpKernel\HttpKernelInterface; | ||
use Symfony\Component\HttpFoundation\Session\Session; | ||
|
||
/** | ||
* PasswordCheckListener to check if the user has to change his password | ||
*/ | ||
class PasswordCheckListener | ||
{ | ||
/** | ||
* @var $authorizationChecker | ||
*/ | ||
private $authorizationChecker; | ||
|
||
/** | ||
* @var $tokenStorage | ||
*/ | ||
private $tokenStorage; | ||
|
||
/** | ||
* @var $router | ||
*/ | ||
private $router; | ||
|
||
/** | ||
* @var $session | ||
*/ | ||
private $session; | ||
|
||
/** | ||
* @param AuthorizationChecker $authorizationChecker | ||
* @param TokenStorage $tokenStorage | ||
* @param Router $router | ||
* @param Session $session | ||
*/ | ||
function __construct(AuthorizationChecker $authorizationChecker, TokenStorage $tokenStorage, Router $router, Session $session) | ||
{ | ||
$this->authorizationChecker = $authorizationChecker; | ||
$this->tokenStorage = $tokenStorage; | ||
$this->router = $router; | ||
$this->session = $session; | ||
} | ||
|
||
/** | ||
* @param GetResponseEvent $event | ||
**/ | ||
public function onKernelRequest(GetResponseEvent $event) | ||
{ | ||
$url = $event->getRequest()->getRequestUri(); | ||
if($this->isAdminRoute($url)) { | ||
$route = $event->getRequest()->get('_route'); | ||
if($this->authorizationChecker->isGranted('IS_AUTHENTICATED_REMEMBERED') && $route != 'fos_user_change_password'){ | ||
$user = $this->tokenStorage->getToken()->getUser(); | ||
if($user->isPasswordChanged() == false) { | ||
$response = new RedirectResponse($this->router->generate('fos_user_change_password')); | ||
$this->session->getFlashBag()->add('error', 'Your password has not yet been changed'); | ||
$event->setResponse($response); | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @param string $url | ||
* | ||
* @return bool | ||
*/ | ||
private function isAdminRoute($url) | ||
{ | ||
preg_match('/^\/(app_(.*)\.php\/)?([a-zA-Z_-]{2,5}\/)?admin\/(.*)/', $url, $matches); | ||
|
||
// Check if path is part of admin area | ||
if (count($matches) === 0) { | ||
return false; | ||
} | ||
|
||
if (strpos($url, '/admin/preview') !== false) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/Kunstmaan/AdminBundle/EventListener/PasswordResettingListener.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace Kunstmaan\AdminBundle\EventListener; | ||
|
||
use FOS\UserBundle\Event\FilterUserResponseEvent; | ||
use FOS\UserBundle\Model\UserManager; | ||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; | ||
use Symfony\Component\HttpFoundation\RedirectResponse; | ||
|
||
/** | ||
* Set password_changed property to 1 after changing the password | ||
*/ | ||
class PasswordResettingListener | ||
{ | ||
|
||
/** | ||
* @var UserManager | ||
*/ | ||
private $userManager; | ||
|
||
/** | ||
* @param UserManager $userManager | ||
*/ | ||
function __construct(UserManager $userManager) | ||
{ | ||
$this->userManager = $userManager; | ||
} | ||
|
||
/** | ||
* @param FilterUserResponseEvent $event | ||
*/ | ||
public function onPasswordResettingSuccess(FilterUserResponseEvent $event) | ||
{ | ||
$user = $event->getUser(); | ||
$user->setPasswordChanged(true); | ||
$this->userManager->updateUser($user); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...Bundle/DataFixtures/ORM/GroupFixtures.php → ...Bundle/DataFixtures/ORM/GroupFixtures.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...nBundle/DataFixtures/ORM/RoleFixtures.php → ...rBundle/DataFixtures/ORM/RoleFixtures.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.