PHP code example of armenio / armenio-zf2-restrictaccess-module
1. Go to this page and download the library: Download armenio/armenio-zf2-restrictaccess-module library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
armenio / armenio-zf2-restrictaccess-module example snippets
'modules' => array(
'Application',
'RestrictAccess', //<==============================
)
'service_manager' => array(
'factories' => array(
'AuthenticationService' => function(\Zend\ServiceManager\ServiceManager $serviceManager) {
$service = new \RestrictAccess\Service\Authentication\DbTableService();
// $service = new \RestrictAccess\Service\Authentication\LdapService();
$service->setServiceManager($serviceManager);
return $service;
}
),
),
$username = $data['username'];
$password = $data['password'];
$authService = $this->getServiceLocator()->get('AuthenticationService');
$authService->setNamespace('Default');
$authService->setTableName('users');
$authService->setIdentityColumn('username');
$authService->setCredentialColumn('password');
$authenticationResult = $authService->authenticate($username, $password);
if( ! $authenticationResult->isValid() ){
var_dump($authenticationResult->getMessages());
}
// else var_dump($authService->getIdentity());
$username = $post['username'];
$password = $post['password'];
$ldapOptions = array(
'server1' => array(
'host' => 'dc1.w.net',
'useStartTls' => 'false',
'useSsl' => 'false',
'baseDn' => 'CN=Users,DC=w,DC=net',
'accountCanonicalForm' => 3,
'accountDomainName' => 'w.net',
'accountDomainNameShort' => 'W',
),
);
$authService = $this->getServiceLocator()->get('AuthenticationService');
$authService->setNamespace('Default');
$authService->setOptions($ldapOptions);
$authenticationResult = $authService->authenticate($username, $password);
if( ! $authenticationResult->isValid() ){
var_dump($authenticationResult->getMessages());
}
// else var_dump($authService->getIdentity());
if( $authService->hasIdentity() ){
var_dump($authService->getIdentity());
}