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\Component\HttpFoundation\Response; |
15
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Aimeos controller for the /admin route |
20
|
|
|
* |
21
|
|
|
* @package symfony |
22
|
|
|
* @subpackage Controller |
23
|
|
|
*/ |
24
|
|
|
class AdminController extends AbstractController |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* Returns the initial HTML view for the admin interface. |
28
|
|
|
* |
29
|
|
|
* @param Request $request Symfony request object |
30
|
|
|
* @return Response Generated HTML page for the admin interface |
31
|
|
|
*/ |
32
|
|
|
public function indexAction( Request $request, \Twig\Environment $twig ) : \Symfony\Component\HttpFoundation\Response |
33
|
|
|
{ |
34
|
|
|
if( $this->hasRole( ['ROLE_ADMIN', 'ROLE_SUPER_ADMIN'] ) ) |
35
|
|
|
{ |
36
|
|
|
$context = $this->get( 'aimeos.context' )->get( false ); |
|
|
|
|
37
|
|
|
$siteManager = \Aimeos\MShop::create( $context, 'locale/site' ); |
38
|
|
|
|
39
|
|
|
$user = $this->get( 'security.token_storage' )->getToken()->getUser(); |
40
|
|
|
$siteId = current( array_reverse( explode( '.', trim( $user->getSiteId(), '.' ) ) ) ); |
41
|
|
|
$siteCode = ( $siteId ? $siteManager->get( $siteId )->getCode() : 'default' ); |
42
|
|
|
|
43
|
|
|
$locale = $user->getLanguageId() ?: ( $this->container->hasParameter( 'locale' ) ? $this->container->getParameter( 'locale' ) : 'en' ); |
|
|
|
|
44
|
|
|
|
45
|
|
|
$params = array( |
46
|
|
|
'resource' => 'dashboard', |
47
|
|
|
'site' => $request->attributes->get( 'site', $request->query->get( 'site', $siteCode ) ), |
48
|
|
|
'locale' => $request->attributes->get( 'locale', $request->query->get( 'locale', $locale ) ), |
49
|
|
|
); |
50
|
|
|
return $this->redirect( $this->generateUrl( 'aimeos_shop_jqadm_search', $params ) ); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
$params = array( 'error' => '', 'username' => '' ); |
55
|
|
|
|
56
|
|
|
if( $this->container->has( 'security.authentication_utils' ) ) |
57
|
|
|
{ |
58
|
|
|
$auth = $this->container->get( 'security.authentication_utils' ); |
59
|
|
|
|
60
|
|
|
$params['error'] = $auth->getLastAuthenticationError(); |
61
|
|
|
$params['username'] = $auth->getLastUsername(); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
return new Response( $twig->render( '@AimeosShop/Admin/index.html.twig', $params ) ); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Checks if the used is authenticated and has the admin role |
70
|
|
|
* |
71
|
|
|
* @param array $roles List of role names where at least one must match |
72
|
|
|
* @return bool True if authenticated and is admin, false if not |
73
|
|
|
*/ |
74
|
|
|
protected function hasRole( array $roles ) : bool |
75
|
|
|
{ |
76
|
|
|
if( $this->container->has( 'security.authorization_checker' ) && $this->container->get( 'security.token_storage' )->getToken() ) |
77
|
|
|
{ |
78
|
|
|
$checker = $this->container->get( 'security.authorization_checker' ); |
79
|
|
|
|
80
|
|
|
foreach( $roles as $role ) |
81
|
|
|
{ |
82
|
|
|
if( $checker->isGranted( $role ) ) { |
83
|
|
|
return true; |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
return false; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.