PHP code example of yetopen / yii2-usuario-ldap

1. Go to this page and download the library: Download yetopen/yii2-usuario-ldap 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/ */

    

yetopen / yii2-usuario-ldap example snippets


//...
'bootstrap' => ['log', 'usuarioLdap'],
//...
'components' => [
    //...
    'usuarioLdap' => [
        'class' => 'yetopen\usuarioLdap\UsuarioLdapComponent',
        'ldapConfig' => [
            'hosts' => ['host.example.com'],
            'base_dn' => 'dc=mydomain,dc=local',
            'account_prefix' => 'cn=',
            'account_suffix' => ',ou=Users,dc=mydomain,dc=local',
            'use_ssl' => true,
            'username' => 'bind_username',
            'password' => 'bind_password',
        ],
        'createLocalUsers' => TRUE,
        'defaultRoles' => ['standardUser'],
        'syncUsersToLdap' => TRUE,
        'secondLdapConfig' => [
            'hosts' => ['host.example.com'],
            'base_dn' => 'dc=mydomain,dc=local',
            'account_prefix' => 'cn=',
            'account_suffix' => ',ou=Users,dc=mydomain,dc=local',
            'username' => 'bind_username',
            'password' => 'bind_password',
        ],
        'allowPasswordRecovery' => FALSE,
        'passwordRecoveryRedirect' => ['/controller/action']
    ],
    //...
]

[
    'class' => 'yii\log\FileTarget', // or another target if you prefer
    // Gets all the log and exceptions messages of the module
    'categories' => [
        'YII2_USUARIO_LDAP',
        'yetopen\usuarioLdap\NoLdapUserException',
        'yetopen\usuarioLdap\LdapConfigurationErrorException',
        'yetopen\usuarioLdap\MultipleUsersFoundException',
        'yetopen\usuarioLdap\RoleNotFoundException',
    ],
    'logFile' => '@runtime/logs/usuario_ldap.log', // or the log file destination that you prefer
]

php composer.phar