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
|
|
|
* @return Response Generated HTML page for the admin interface |
29
|
|
|
*/ |
30
|
|
|
public function indexAction() |
31
|
|
|
{ |
32
|
|
|
if( $this->isAdmin() ) |
33
|
|
|
{ |
34
|
|
|
$params = array( 'site' => 'default', 'resource' => 'product', 'lang' => 'en' ); |
35
|
|
|
return $this->redirect( $this->generateUrl( 'aimeos_shop_jqadm_search', $params ) ); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
$param = array(); |
39
|
|
|
|
40
|
|
|
if( $this->has( 'security.authentication_utils' ) ) |
41
|
|
|
{ |
42
|
|
|
$auth = $this->get( 'security.authentication_utils' ); |
43
|
|
|
|
44
|
|
|
$param['error'] = $auth->getLastAuthenticationError(); |
45
|
|
|
$param['username'] = $auth->getLastUsername(); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
return $this->render( 'AimeosShopBundle:Admin:index.html.twig', $param ); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Checks if the used is authenticated and has the admin role |
54
|
|
|
* |
55
|
|
|
* @return boolean True if authenticated and is admin, false if not |
56
|
|
|
*/ |
57
|
|
|
protected function isAdmin() |
58
|
|
|
{ |
59
|
|
|
if( $this->has( 'security.authorization_checker' ) && $this->get( 'security.token_storage' )->getToken() |
60
|
|
|
&& $this->get( 'security.authorization_checker' )->isGranted( 'ROLE_ADMIN' ) |
61
|
|
|
|| $this->has( 'security.context' ) && $this->get( 'security.context' )->getToken() |
62
|
|
|
&& $this->get( 'security.context' )->isGranted( 'ROLE_ADMIN' ) |
63
|
|
|
) { |
64
|
|
|
return true; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
return false; |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|