@@ -1,55 +1,55 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | use HtpasswdManager\Service\Factory\UserServiceFactory; |
| 3 | 3 | return array( |
| 4 | - 'controllers' => array( |
|
| 5 | - 'invokables' => array( |
|
| 6 | - 'HtpasswdManager\Controller\User' => 'HtpasswdManager\Controller\UserController' |
|
| 7 | - ) |
|
| 8 | - ), |
|
| 9 | - 'service_manager' => array( |
|
| 10 | - 'factories' => array( |
|
| 11 | - 'HtpasswdManager\Service\UserService' => 'HtpasswdManager\Service\Factory\UserServiceFactory' |
|
| 12 | - ) |
|
| 13 | - ), |
|
| 14 | - 'router' => array( |
|
| 15 | - 'routes' => array( |
|
| 16 | - 'htpasswdmanager' => array( |
|
| 17 | - 'type' => 'Segment', |
|
| 18 | - 'options' => array( |
|
| 19 | - // Change this to something specific to your module |
|
| 20 | - 'route' => '/usermanagement[/:action][/:user]', |
|
| 21 | - 'constraints' => array( |
|
| 22 | - 'action' => '[a-zA-Z][a-zA-Z0-9_-]*', |
|
| 23 | - 'user' => '[a-zA-Z0-9.!?_-]+' |
|
| 24 | - ), |
|
| 25 | - 'defaults' => array( |
|
| 26 | - // Change this value to reflect the namespace in which |
|
| 27 | - // the controllers for your module are found |
|
| 28 | - '__NAMESPACE__' => 'HtpasswdManager\Controller', |
|
| 29 | - 'controller' => 'User', |
|
| 30 | - 'action' => 'index' |
|
| 31 | - ) |
|
| 32 | - ), |
|
| 33 | - 'may_terminate' => true |
|
| 34 | - ) |
|
| 35 | - ) |
|
| 36 | - ), |
|
| 37 | - 'view_manager' => array( |
|
| 38 | - 'template_path_stack' => array( |
|
| 39 | - 'HtpasswdManager' => __DIR__ . '/../view' |
|
| 40 | - ) |
|
| 41 | - ), |
|
| 42 | - 'HtpasswdManager' => array( |
|
| 43 | - // Carefull! File needs to be writeable by apache-user (www-data) |
|
| 44 | - // The .htaccess file needs to be set to use this .htpasswd file for authentication |
|
| 45 | - 'htpasswd' => 'path/to/.htpasswd', |
|
| 4 | + 'controllers' => array( |
|
| 5 | + 'invokables' => array( |
|
| 6 | + 'HtpasswdManager\Controller\User' => 'HtpasswdManager\Controller\UserController' |
|
| 7 | + ) |
|
| 8 | + ), |
|
| 9 | + 'service_manager' => array( |
|
| 10 | + 'factories' => array( |
|
| 11 | + 'HtpasswdManager\Service\UserService' => 'HtpasswdManager\Service\Factory\UserServiceFactory' |
|
| 12 | + ) |
|
| 13 | + ), |
|
| 14 | + 'router' => array( |
|
| 15 | + 'routes' => array( |
|
| 16 | + 'htpasswdmanager' => array( |
|
| 17 | + 'type' => 'Segment', |
|
| 18 | + 'options' => array( |
|
| 19 | + // Change this to something specific to your module |
|
| 20 | + 'route' => '/usermanagement[/:action][/:user]', |
|
| 21 | + 'constraints' => array( |
|
| 22 | + 'action' => '[a-zA-Z][a-zA-Z0-9_-]*', |
|
| 23 | + 'user' => '[a-zA-Z0-9.!?_-]+' |
|
| 24 | + ), |
|
| 25 | + 'defaults' => array( |
|
| 26 | + // Change this value to reflect the namespace in which |
|
| 27 | + // the controllers for your module are found |
|
| 28 | + '__NAMESPACE__' => 'HtpasswdManager\Controller', |
|
| 29 | + 'controller' => 'User', |
|
| 30 | + 'action' => 'index' |
|
| 31 | + ) |
|
| 32 | + ), |
|
| 33 | + 'may_terminate' => true |
|
| 34 | + ) |
|
| 35 | + ) |
|
| 36 | + ), |
|
| 37 | + 'view_manager' => array( |
|
| 38 | + 'template_path_stack' => array( |
|
| 39 | + 'HtpasswdManager' => __DIR__ . '/../view' |
|
| 40 | + ) |
|
| 41 | + ), |
|
| 42 | + 'HtpasswdManager' => array( |
|
| 43 | + // Carefull! File needs to be writeable by apache-user (www-data) |
|
| 44 | + // The .htaccess file needs to be set to use this .htpasswd file for authentication |
|
| 45 | + 'htpasswd' => 'path/to/.htpasswd', |
|
| 46 | 46 | |
| 47 | - // Users, that can't be deleted with the GUI |
|
| 48 | - 'not_deletable_users' => array( |
|
| 49 | - 'admin' |
|
| 50 | - ), |
|
| 47 | + // Users, that can't be deleted with the GUI |
|
| 48 | + 'not_deletable_users' => array( |
|
| 49 | + 'admin' |
|
| 50 | + ), |
|
| 51 | 51 | |
| 52 | - // May be an array (for specific users) or boolean for general true / false |
|
| 53 | - 'usermanagement_users' => true |
|
| 54 | - ) |
|
| 52 | + // May be an array (for specific users) or boolean for general true / false |
|
| 53 | + 'usermanagement_users' => true |
|
| 54 | + ) |
|
| 55 | 55 | ); |
@@ -16,46 +16,46 @@ |
||
| 16 | 16 | |
| 17 | 17 | class Module implements AutoloaderProviderInterface { |
| 18 | 18 | |
| 19 | - public function getAutoloaderConfig() { |
|
| 20 | - return array( |
|
| 21 | - 'Zend\Loader\StandardAutoloader' => array( |
|
| 22 | - 'namespaces' => array( |
|
| 23 | - // if we're in a namespace deeper than one level we need to fix the \ in the path |
|
| 24 | - __NAMESPACE__ => __DIR__ . '/src/' . str_replace ( '\\', '/', __NAMESPACE__ ) |
|
| 25 | - ) |
|
| 26 | - ) |
|
| 27 | - ); |
|
| 28 | - } |
|
| 29 | - |
|
| 30 | - public function getConfig() { |
|
| 31 | - return include __DIR__ . '/config/module.config.php'; |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - public function onBootstrap(MvcEvent $e) { |
|
| 35 | - // You may not need to do this if you're doing it elsewhere in your |
|
| 36 | - // application |
|
| 37 | - $eventManager = $e->getApplication ()->getEventManager (); |
|
| 38 | - $moduleRouteListener = new ModuleRouteListener (); |
|
| 39 | - $moduleRouteListener->attach ( $eventManager ); |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - public function getServiceConfig() { |
|
| 43 | - return array( |
|
| 44 | - 'factories' => array( |
|
| 45 | - 'HtpasswdManager\Service\HtpasswdService' => function ($sm) { |
|
| 46 | - $config = $sm->get ( 'Config' ); |
|
| 19 | + public function getAutoloaderConfig() { |
|
| 20 | + return array( |
|
| 21 | + 'Zend\Loader\StandardAutoloader' => array( |
|
| 22 | + 'namespaces' => array( |
|
| 23 | + // if we're in a namespace deeper than one level we need to fix the \ in the path |
|
| 24 | + __NAMESPACE__ => __DIR__ . '/src/' . str_replace ( '\\', '/', __NAMESPACE__ ) |
|
| 25 | + ) |
|
| 26 | + ) |
|
| 27 | + ); |
|
| 28 | + } |
|
| 29 | + |
|
| 30 | + public function getConfig() { |
|
| 31 | + return include __DIR__ . '/config/module.config.php'; |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + public function onBootstrap(MvcEvent $e) { |
|
| 35 | + // You may not need to do this if you're doing it elsewhere in your |
|
| 36 | + // application |
|
| 37 | + $eventManager = $e->getApplication ()->getEventManager (); |
|
| 38 | + $moduleRouteListener = new ModuleRouteListener (); |
|
| 39 | + $moduleRouteListener->attach ( $eventManager ); |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + public function getServiceConfig() { |
|
| 43 | + return array( |
|
| 44 | + 'factories' => array( |
|
| 45 | + 'HtpasswdManager\Service\HtpasswdService' => function ($sm) { |
|
| 46 | + $config = $sm->get ( 'Config' ); |
|
| 47 | 47 | |
| 48 | - if (! isset ( $config ['HtpasswdManager'] ) || ! is_array ( $config ['HtpasswdManager'] ) || ! isset ( $config ['HtpasswdManager'] ['htpasswd'] ) || empty ( $config ['HtpasswdManager'] ['htpasswd'] )) { |
|
| 49 | - throw new \Exception ( 'HtpasswdManager Config not found' ); |
|
| 50 | - } |
|
| 48 | + if (! isset ( $config ['HtpasswdManager'] ) || ! is_array ( $config ['HtpasswdManager'] ) || ! isset ( $config ['HtpasswdManager'] ['htpasswd'] ) || empty ( $config ['HtpasswdManager'] ['htpasswd'] )) { |
|
| 49 | + throw new \Exception ( 'HtpasswdManager Config not found' ); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - $htpasswd_filename = $config ['HtpasswdManager'] ['htpasswd']; |
|
| 53 | - $service = new HtpasswdService ( $htpasswd_filename ); |
|
| 52 | + $htpasswd_filename = $config ['HtpasswdManager'] ['htpasswd']; |
|
| 53 | + $service = new HtpasswdService ( $htpasswd_filename ); |
|
| 54 | 54 | |
| 55 | - return $service; |
|
| 56 | - } |
|
| 57 | - ) |
|
| 58 | - ); |
|
| 59 | - } |
|
| 55 | + return $service; |
|
| 56 | + } |
|
| 57 | + ) |
|
| 58 | + ); |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | 61 | } |
| 62 | 62 | \ No newline at end of file |
@@ -58,7 +58,7 @@ |
||
| 58 | 58 | $userList = $service->getUserList(); |
| 59 | 59 | $this->assertEquals( |
| 60 | 60 | $expected = [ 'steven' => '$apr1$UF1l/6iv$tT3IJUH.QL82HAraXetNo0', |
| 61 | - 'blub' => '$apr1$jVosh5nC$q6KJ5EZNU6thOPETMQw8O/' |
|
| 61 | + 'blub' => '$apr1$jVosh5nC$q6KJ5EZNU6thOPETMQw8O/' |
|
| 62 | 62 | ], $userList, "UserList"); |
| 63 | 63 | } |
| 64 | 64 | |
@@ -6,26 +6,26 @@ |
||
| 6 | 6 | |
| 7 | 7 | class UserServiceFactory { |
| 8 | 8 | |
| 9 | - public function __invoke($sm) { |
|
| 10 | - $config = $sm->get ( 'Config' ); |
|
| 9 | + public function __invoke($sm) { |
|
| 10 | + $config = $sm->get ( 'Config' ); |
|
| 11 | 11 | |
| 12 | - // Default |
|
| 13 | - $not_deletable_users = array(); |
|
| 14 | - if (isset ( $config ['HtpasswdManager'] ['not_deletable_users'] ) && is_array ( $config ['HtpasswdManager'] ['not_deletable_users'] )) { |
|
| 15 | - $not_deletable_users = $config ['HtpasswdManager'] ['not_deletable_users']; |
|
| 16 | - } |
|
| 12 | + // Default |
|
| 13 | + $not_deletable_users = array(); |
|
| 14 | + if (isset ( $config ['HtpasswdManager'] ['not_deletable_users'] ) && is_array ( $config ['HtpasswdManager'] ['not_deletable_users'] )) { |
|
| 15 | + $not_deletable_users = $config ['HtpasswdManager'] ['not_deletable_users']; |
|
| 16 | + } |
|
| 17 | 17 | |
| 18 | - // Default |
|
| 19 | - $user_with_management_permission = true; |
|
| 20 | - if (isset ( $config ['HtpasswdManager'] ['usermanagement_users'] ) && is_array ( $config ['HtpasswdManager'] ['usermanagement_users'] )) { |
|
| 21 | - $user_with_management_permission = $config ['HtpasswdManager'] ['usermanagement_users']; |
|
| 22 | - } else if ($config ['HtpasswdManager'] ['usermanagement_users'] === false) { |
|
| 23 | - $user_with_management_permission = false; |
|
| 24 | - } |
|
| 18 | + // Default |
|
| 19 | + $user_with_management_permission = true; |
|
| 20 | + if (isset ( $config ['HtpasswdManager'] ['usermanagement_users'] ) && is_array ( $config ['HtpasswdManager'] ['usermanagement_users'] )) { |
|
| 21 | + $user_with_management_permission = $config ['HtpasswdManager'] ['usermanagement_users']; |
|
| 22 | + } else if ($config ['HtpasswdManager'] ['usermanagement_users'] === false) { |
|
| 23 | + $user_with_management_permission = false; |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - $request = $sm->get ( 'Request' ); |
|
| 26 | + $request = $sm->get ( 'Request' ); |
|
| 27 | 27 | |
| 28 | - return new UserService ( $request, $not_deletable_users, $user_with_management_permission ); |
|
| 29 | - } |
|
| 28 | + return new UserService ( $request, $not_deletable_users, $user_with_management_permission ); |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | 31 | } |
@@ -11,65 +11,65 @@ |
||
| 11 | 11 | use Zend\EventManager\EventManagerInterface; |
| 12 | 12 | |
| 13 | 13 | class UserService implements EventManagerAwareInterface { |
| 14 | - protected $request; |
|
| 15 | - protected $not_deletable_users; |
|
| 16 | - protected $user_with_management_permission; |
|
| 17 | - protected $eventManager; |
|
| 14 | + protected $request; |
|
| 15 | + protected $not_deletable_users; |
|
| 16 | + protected $user_with_management_permission; |
|
| 17 | + protected $eventManager; |
|
| 18 | 18 | |
| 19 | - public function __construct(Request $request, $not_deletable_users, $user_with_management_permission) { |
|
| 20 | - $this->request = $request; |
|
| 21 | - $this->not_deletable_users = $not_deletable_users; |
|
| 22 | - $this->user_with_management_permission = $user_with_management_permission; |
|
| 23 | - } |
|
| 19 | + public function __construct(Request $request, $not_deletable_users, $user_with_management_permission) { |
|
| 20 | + $this->request = $request; |
|
| 21 | + $this->not_deletable_users = $not_deletable_users; |
|
| 22 | + $this->user_with_management_permission = $user_with_management_permission; |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * Return the current used user |
|
| 27 | - * |
|
| 28 | - * @return string |
|
| 29 | - */ |
|
| 30 | - public function getCurrentUser() { |
|
| 31 | - return $this->request->getServer ()->get ( 'REMOTE_USER', null ); |
|
| 32 | - } |
|
| 25 | + /** |
|
| 26 | + * Return the current used user |
|
| 27 | + * |
|
| 28 | + * @return string |
|
| 29 | + */ |
|
| 30 | + public function getCurrentUser() { |
|
| 31 | + return $this->request->getServer ()->get ( 'REMOTE_USER', null ); |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - public function isUserDeleteable($username) { |
|
| 35 | - $eResult = $this->getEventManager ()->trigger ( 'pre_' . __FUNCTION__, $this, array( |
|
| 36 | - $username |
|
| 37 | - ) ); |
|
| 34 | + public function isUserDeleteable($username) { |
|
| 35 | + $eResult = $this->getEventManager ()->trigger ( 'pre_' . __FUNCTION__, $this, array( |
|
| 36 | + $username |
|
| 37 | + ) ); |
|
| 38 | 38 | |
| 39 | - if ($eResult->stopped ()) |
|
| 40 | - return $eResult->last (); |
|
| 39 | + if ($eResult->stopped ()) |
|
| 40 | + return $eResult->last (); |
|
| 41 | 41 | |
| 42 | - return ! in_array ( $username, $this->not_deletable_users ); |
|
| 43 | - } |
|
| 42 | + return ! in_array ( $username, $this->not_deletable_users ); |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - public function isUserAllowedToManageUsers($username) { |
|
| 46 | - $eResult = $this->getEventManager ()->trigger ( 'pre_' . __FUNCTION__, $this, array( |
|
| 47 | - 'user' => $username |
|
| 48 | - ) ); |
|
| 45 | + public function isUserAllowedToManageUsers($username) { |
|
| 46 | + $eResult = $this->getEventManager ()->trigger ( 'pre_' . __FUNCTION__, $this, array( |
|
| 47 | + 'user' => $username |
|
| 48 | + ) ); |
|
| 49 | 49 | |
| 50 | - if ($eResult->stopped ()) |
|
| 51 | - return $eResult->last (); |
|
| 50 | + if ($eResult->stopped ()) |
|
| 51 | + return $eResult->last (); |
|
| 52 | 52 | |
| 53 | - /* If parameter is an array => allow only users in list. IF parameter is boolean, return boolean value */ |
|
| 54 | - if (is_array ( $this->user_with_management_permission )) { |
|
| 55 | - $accessAllowed = in_array ( $username, $this->user_with_management_permission ); |
|
| 56 | - } else { |
|
| 57 | - $accessAllowed = ($this->user_with_management_permission === true); |
|
| 58 | - } |
|
| 53 | + /* If parameter is an array => allow only users in list. IF parameter is boolean, return boolean value */ |
|
| 54 | + if (is_array ( $this->user_with_management_permission )) { |
|
| 55 | + $accessAllowed = in_array ( $username, $this->user_with_management_permission ); |
|
| 56 | + } else { |
|
| 57 | + $accessAllowed = ($this->user_with_management_permission === true); |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - return $accessAllowed; |
|
| 61 | - } |
|
| 60 | + return $accessAllowed; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - public function setEventManager(EventManagerInterface $eventManager) { |
|
| 64 | - $eventManager->setIdentifiers ( array( |
|
| 65 | - __CLASS__, |
|
| 66 | - get_class ( $this ) |
|
| 67 | - ) ); |
|
| 68 | - $this->eventManager = $eventManager; |
|
| 69 | - } |
|
| 63 | + public function setEventManager(EventManagerInterface $eventManager) { |
|
| 64 | + $eventManager->setIdentifiers ( array( |
|
| 65 | + __CLASS__, |
|
| 66 | + get_class ( $this ) |
|
| 67 | + ) ); |
|
| 68 | + $this->eventManager = $eventManager; |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - public function getEventManager() { |
|
| 72 | - return $this->eventManager; |
|
| 73 | - } |
|
| 71 | + public function getEventManager() { |
|
| 72 | + return $this->eventManager; |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | 75 | } |