Problem with LDAP login

Hello community I am logging an application verifying the data through an LDAP server (user and password).

There are 2 types of users, those who have specific permissions to the system (store their data in an external database, but to access have to enter their user and LDAP password), this has no problem when logging in.

The problem is in logging users who do not have permissions (which are not their data in an external database), creating the User Object (and assigning each of its attributes is not logged)

Here I leave each of the models. I appreciate the help you can give me as soon as possible.

User.php




/**

 * @inheritdoc

 */


public static function findIdentityLdap($id)

{

    $new_identity = new User();

    $ldap = new Ldap();


    if (static::findByUsername($id)) {

        $new_identity = static::findByUsername($id);

    } else {

        $new_identity->setId(1);

        $new_identity->setEmail($ldap->bind_params_user($id, 'mail'));

        $new_identity->setUsername($ldap->bind_params_user($id, 'distinguishedname'));

        $new_identity->setFullname($ldap->bind_params_user($id, 'fullname'));

                  $new_identity->setStatus(self::STATUS_DELETED);

                $new_identity->setAuthKey();

        $new_identity->setPassword(Yii::$app->security->generateRandomString());


    }


    return $new_identity;




}





public function setEmail($email)

{

    $this->email = $email;

}


public function setUsername($username)

{

    $this->username = $username;

}


public function setId($id)

{

    $this->id = $id;

}


public function setFullname($fullname)

{

    $this->fullname = $fullname;

}


public function setStatus($status)

{

    $this->status = $status;

}


public function setAuthKey()

{

    return $this->auth_key = Yii::$app->security->generateRandomString();

}



Ldap.php




/**

 * Auth user

 *

 * @param $username

 * @param $password

 * @return bool

 */

public function bind($username, $password)

{

        if ($username == 'admin'&& $password == 'pass') {

        return true;

    } else {

        return false;

    }

}




/**

 * Get user params

 *

 * @param $username

 * @param $param

 * @return string

 */

public function bind_params_user($username, $param)

{

    

    if ($username == 'admin' && $param == 'fullname') {

        return 'Admin';

    }

    if $username == 'admin' && $param == 'mail') {

        return 'admin@example.com';

    }

    if $username == 'admin' &&  $param == 'distinguishedname') {

        return 'admin';


    }




}



LoginForm.php




class LoginForm extends Model

{

    public $username;

    public $password;

    public $rememberMe = true;


    private $_user = false;


    public function rules()

    {

        return [

            // username and password are both required

            [['username', 'password'], 'required'],

            // rememberMe must be a boolean value

            ['rememberMe', 'boolean'],

            // password is validated by validatePassword()

            ['password', 'validatePasswordLdap'],

        ];

    }




    public function validatePasswordLdap($attribute, $params)

    {

        $ldap = new Ldap();

        if (!$this->hasErrors()) {

            $user = $this->getUserLdap();

           if (!$user || !$ldap->bind($this->username, $this->password)) {

                $this->addError($attribute,'Error');

            }

        }

    }


    public function getUserLdap()

    {

        if ($this->_user === false) {

            $this->_user = User::findIdentityLdap($this->username);

        }


        return $this->_user;

    }


    public function login()

    {

        if ($this->validate()) {

            return Yii::$app->user->login($this->getUserLdap(), $this->rememberMe ? 3600 * 24 * 30 : 0);

        } else {

            return false;

        }

    }