1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace JhUser; |
4
|
|
|
|
5
|
|
|
use Zend\ModuleManager\Feature\ConfigProviderInterface; |
6
|
|
|
use Zend\ModuleManager\Feature\AutoloaderProviderInterface; |
7
|
|
|
use Zend\ModuleManager\Feature\DependencyIndicatorInterface; |
8
|
|
|
use Zend\ModuleManager\Feature\ConsoleUsageProviderInterface; |
9
|
|
|
use Zend\EventManager\EventInterface; |
10
|
|
|
use Zend\Console\Adapter\AdapterInterface as Console; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class Module |
14
|
|
|
* @package JhUser |
15
|
|
|
* @author Aydin Hassan <[email protected]> |
16
|
|
|
*/ |
17
|
|
|
class Module implements |
18
|
|
|
ConfigProviderInterface, |
19
|
|
|
AutoloaderProviderInterface, |
20
|
|
|
ConsoleUsageProviderInterface, |
21
|
|
|
DependencyIndicatorInterface |
22
|
|
|
{ |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @param EventInterface $e |
26
|
|
|
*/ |
27
|
|
|
public function onBootstrap(EventInterface $e) |
28
|
|
|
{ |
29
|
|
|
$application = $e->getTarget(); |
30
|
|
|
$events = $application->getEventManager()->getSharedManager(); |
31
|
|
|
|
32
|
|
|
//add roles to users created via HybridAuth |
33
|
|
|
$events->attach( |
34
|
|
|
'ScnSocialAuth\Authentication\Adapter\HybridAuth', |
35
|
|
|
'registerViaProvider', |
36
|
|
|
[$this, 'onRegister'] |
37
|
|
|
); |
38
|
|
|
|
39
|
|
|
//add roles to users created via ZfcUser |
40
|
|
|
$events->attach('ZfcUser\Service\User', 'register', [$this, 'onRegister']); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param EventInterface $e |
45
|
|
|
*/ |
46
|
|
|
public function onRegister(EventInterface $e) |
47
|
|
|
{ |
48
|
|
|
$application = $e->getTarget(); |
49
|
|
|
$sm = $application->getServiceManager(); |
50
|
|
|
$entityManager = $sm->get('JhUser\ObjectManager'); |
51
|
|
|
|
52
|
|
|
$user = $e->getParam('user'); |
53
|
|
|
//TODO: Pull default role from config |
54
|
|
|
$userRole = $sm->get('JhUser\Repository\RoleRepository')->findByName('user'); |
55
|
|
|
|
56
|
|
|
$user->addRole($userRole); |
57
|
|
|
$entityManager->flush(); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* {@inheritDoc} |
62
|
|
|
*/ |
63
|
|
|
public function getConfig() |
64
|
|
|
{ |
65
|
|
|
return include __DIR__ . '/../../config/module.config.php'; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* {@inheritDoc} |
70
|
|
|
*/ |
71
|
|
|
public function getAutoloaderConfig() |
72
|
|
|
{ |
73
|
|
|
return [ |
74
|
|
|
'Zend\Loader\StandardAutoloader' => [ |
75
|
|
|
'namespaces' => [ |
76
|
|
|
__NAMESPACE__ => __DIR__ . '/../../src/' . __NAMESPACE__, |
77
|
|
|
], |
78
|
|
|
], |
79
|
|
|
]; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* {@inheritDoc} |
84
|
|
|
*/ |
85
|
|
|
public function getModuleDependencies() |
86
|
|
|
{ |
87
|
|
|
return [ |
88
|
|
|
'DoctrineModule', |
89
|
|
|
'DoctrineORMModule', |
90
|
|
|
'ZfcUser', |
91
|
|
|
'ZfcUserDoctrineORM', |
92
|
|
|
'ScnSocialAuthDoctrineORM' |
93
|
|
|
]; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @param Console $console |
99
|
|
|
* @return array|null|string |
100
|
|
|
*/ |
101
|
|
|
public function getConsoleUsage(Console $console) |
102
|
|
|
{ |
103
|
|
|
return [ |
104
|
|
|
'set role <userEmail> <role>' => 'Set a user\'s role', |
105
|
|
|
]; |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|