src/model/UserDbLdap.php
public static function findByUsername($username) {
        if(static::getExtensionOptions('ENABLE_YII2_PROFILING') == true) {
            Yii::beginProfile('findByUsername', static::YII2_PROFILE_NAME . 'findByUsername');
        }        
        
        $userObjectDb = static::findOne(['username' => $username]); 

        //Create user if not found in db
        if ($userObjectDb == null) {
            //Just create to get synchronisation options
            $userObjectDb = new static();
            
            if(static::getSyncOptions('ON_LOGIN_CREATE_USER', $userObjectDb->individualSyncOptions) == true) {
                $userObjectDb = static::createNewUser($username);
            } else {
                $userObjectDb = null;
            }
        } else {
            //Refresh group assignments of user if found in database
            if (static::getSyncOptions('ON_LOGIN_REFRESH_GROUP_ASSIGNMENTS', $userObjectDb->individualSyncOptions) == true) {
                $userObjectDb->updateGroupAssignment();
            }

            //Refresh account status of user if found in database
            if (static::getSyncOptions('ON_LOGIN_REFRESH_LDAP_ACCOUNT_STATUS', $userObjectDb->individualSyncOptions) == true &&
                static::getSyncOptions('ON_REQUEST_REFRESH_LDAP_ACCOUNT_STATUS', $userObjectDb->individualSyncOptions) == false)
            {
                $userObjectDb->updateAccountStatus();
            }
        }
        
        $checkedUserObjectDB = static::checkAllowedToLogin($userObjectDb);
        if(static::getExtensionOptions('ENABLE_YII2_PROFILING') == true) {
            Yii::endProfile('findByUsername', static::YII2_PROFILE_NAME . 'findByUsername');
        }        
        return $checkedUserObjectDB;
    }
public static function findByUsername($username) {
        if(static::getExtensionOptions('ENABLE_YII2_PROFILING') == true) {
            Yii::beginProfile('findByUsername', static::YII2_PROFILE_NAME . 'findByUsername');
        }        
        
        $userObjectDb = static::findOne(['username' => $username]); 

        //Create user if not found in db
        if ($userObjectDb == null) {
            //Just create to get synchronisation options
            $userObjectDb = new static();
            
            if(static::getSyncOptions('ON_LOGIN_CREATE_USER', $userObjectDb->individualSyncOptions) == true) {
                $userObjectDb = static::createNewUser($username);
            } else {
                $userObjectDb = null;
            }
        } else {
            //Refresh group assignments of user if found in database
            if (static::getSyncOptions('ON_LOGIN_REFRESH_GROUP_ASSIGNMENTS', $userObjectDb->individualSyncOptions) == true) {
                $userObjectDb->updateGroupAssignment();
            }

            //Refresh account status of user if found in database
            if (static::getSyncOptions('ON_LOGIN_REFRESH_LDAP_ACCOUNT_STATUS', $userObjectDb->individualSyncOptions) == true &&
                static::getSyncOptions('ON_REQUEST_REFRESH_LDAP_ACCOUNT_STATUS', $userObjectDb->individualSyncOptions) == false)
            {
                $userObjectDb->updateAccountStatus();
            }
        }
        
        $checkedUserObjectDB = static::checkAllowedToLogin($userObjectDb);
        if(static::getExtensionOptions('ENABLE_YII2_PROFILING') == true) {
            Yii::endProfile('findByUsername', static::YII2_PROFILE_NAME . 'findByUsername');
        }        
        return $checkedUserObjectDB;
    }
public static function findByUsername ( $ username ) { if ( static :: getExtensionOptions ( 'ENABLE_YII2_PROFILING' ) == true ) { Yii :: beginProfile ( 'findByUsername' , static :: YII2_PROFILE_NAME . 'findByUsername' ) ; } $ userObjectDb = static :: findOne ( [ 'username' => $ username ] ) ; //Create user if not found in db
 if ( $ userObjectDb == null ) { //Just create to get synchronisation options
 $ userObjectDb = new static ( ) ; if ( static :: getSyncOptions ( 'ON_LOGIN_CREATE_USER' , $ userObjectDb -> individualSyncOptions ) == true ) { $ userObjectDb = static :: createNewUser ( $ username ) ; } else { $ userObjectDb = null ; } } else { //Refresh group assignments of user if found in database
 if ( static :: getSyncOptions ( 'ON_LOGIN_REFRESH_GROUP_ASSIGNMENTS' , $ userObjectDb -> individualSyncOptions ) == true ) { $ userObjectDb -> updateGroupAssignment ( ) ; } //Refresh account status of user if found in database
 if ( static :: getSyncOptions ( 'ON_LOGIN_REFRESH_LDAP_ACCOUNT_STATUS' , $ userObjectDb -> individualSyncOptions ) == true && static :: getSyncOptions ( 'ON_REQUEST_REFRESH_LDAP_ACCOUNT_STATUS' , $ userObjectDb -> individualSyncOptions ) == false ) { $ userObjectDb -> updateAccountStatus ( ) ; } } $ checkedUserObjectDB = static :: checkAllowedToLogin ( $ userObjectDb ) ; if ( static :: getExtensionOptions ( 'ENABLE_YII2_PROFILING' ) == true ) { Yii :: endProfile ( 'findByUsername' , static :: YII2_PROFILE_NAME . 'findByUsername' ) ; } return $ checkedUserObjectDB ; }
Finds user by username (samaccountname)

Depending on the synchronisation options additional LDAP querys are done.

For a description of the options see the top of this class, where templates (e.g. SYNC_OPTIONS_TEMPLATE_WITHOUT_BACKEND_TASK) are defined.
This Templates can be used directly in params or you can define each param by yourself.

Example config/params.php
return [
...
'LDAP-User-Sync-Options' => Edvlerblog\Adldap2\model\UserDbLdap::SYNC_OPTIONS_TEMPLATE_WITHOUT_BACKEND_TASK,
...
];

If the user does not exists in database and the option [[ON_LOGIN_CREATE_USER]] is true
a LDAP query would be done to find the user in LDAP and sync it to database.

If the [[ON_LOGIN_REFRESH_GROUP_ASSIGNMENTS]] option is true, the group assigment is
queryied from LDAP and stored in database on login.

If the [[ON_LOGIN_REFRESH_LDAP_ACCOUNT_STATUS]] option is true, the account status is
queryied from LDAP and stored in database on login.

@param string $username username of the user object
@return Edvlerblog\Adldap2\model\UserDbLdap A User instance, if user is valid. Otherwise NULL.
Finds user by username ( samaccountname )