1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license MIT, http://opensource.org/licenses/MIT |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2016 |
6
|
|
|
* @package symfony |
7
|
|
|
* @subpackage Controller |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
namespace Aimeos\ShopBundle\Controller; |
12
|
|
|
|
13
|
|
|
use Symfony\Component\HttpFoundation\Request; |
14
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Aimeos controller for the /admin route |
19
|
|
|
* |
20
|
|
|
* @package symfony |
21
|
|
|
* @subpackage Controller |
22
|
|
|
*/ |
23
|
|
|
class AdminController extends Controller |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* Returns the initial HTML view for the admin interface. |
27
|
|
|
* |
28
|
|
|
* @param Request $request Symfony request object |
29
|
|
|
* @return Response Generated HTML page for the admin interface |
|
|
|
|
30
|
|
|
*/ |
31
|
|
|
public function indexAction( Request $request ) : \Symfony\Component\HttpFoundation\Response |
32
|
|
|
{ |
33
|
|
|
if( $this->hasRole( ['ROLE_ADMIN', 'ROLE_SUPER_ADMIN'] ) ) |
34
|
|
|
{ |
35
|
|
|
$context = $this->get( 'aimeos.context' )->get( false ); |
36
|
|
|
$siteManager = \Aimeos\MShop::create( $context, 'locale/site' ); |
37
|
|
|
|
38
|
|
|
$user = $this->get( 'security.token_storage' )->getToken()->getUser(); |
39
|
|
|
$siteId = current( array_reverse( explode( '.', trim( $user->getSiteId(), '.' ) ) ) ); |
40
|
|
|
$siteCode = ( $siteId ? $siteManager->getItem( $siteId )->getCode() : 'default' ); |
41
|
|
|
|
42
|
|
|
$locale = $user->getLanguageId() ?: ( $this->container->hasParameter( 'locale' ) ? $this->container->getParameter( 'locale' ) : 'en' ); |
43
|
|
|
|
44
|
|
|
$params = array( |
45
|
|
|
'resource' => 'dashboard', |
46
|
|
|
'site' => $request->attributes->get( 'site', $request->query->get( 'site', $siteCode ) ), |
47
|
|
|
'lang' => $request->attributes->get( 'lang', $request->query->get( 'lang', $locale ) ), |
48
|
|
|
); |
49
|
|
|
return $this->redirect( $this->generateUrl( 'aimeos_shop_jqadm_search', $params ) ); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
|
53
|
|
|
$param = array( 'error' => '', 'username' => '' ); |
54
|
|
|
|
55
|
|
|
if( $this->has( 'security.authentication_utils' ) ) |
56
|
|
|
{ |
57
|
|
|
$auth = $this->get( 'security.authentication_utils' ); |
58
|
|
|
|
59
|
|
|
$param['error'] = $auth->getLastAuthenticationError(); |
60
|
|
|
$param['username'] = $auth->getLastUsername(); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
return $this->render( '@AimeosShop/Admin/index.html.twig', $param ); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Checks if the used is authenticated and has the admin role |
69
|
|
|
* |
70
|
|
|
* @param array $roles List of role names where at least one must match |
71
|
|
|
* @return bool True if authenticated and is admin, false if not |
72
|
|
|
*/ |
73
|
|
|
protected function hasRole( array $roles ) : bool |
74
|
|
|
{ |
75
|
|
|
if( $this->has( 'security.authorization_checker' ) && $this->get( 'security.token_storage' )->getToken() ) |
76
|
|
|
{ |
77
|
|
|
$checker = $this->get( 'security.authorization_checker' ); |
78
|
|
|
|
79
|
|
|
foreach( $roles as $role ) |
80
|
|
|
{ |
81
|
|
|
if( $checker->isGranted( $role ) ) { |
82
|
|
|
return true; |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
return false; |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths