D
D
des1roer2016-04-04 09:58:11
Yii
des1roer, 2016-04-04 09:58:11

Yii 1.* authorization by login?

I want to change the login to authorization only by login, without a password
now it's done like this des1roer.blogspot.ru/2015/03/yii-yii-for-dummies-a...
I think protected\components\UserIdentity.php needs to be changed

public function authenticate($silent = null)
    {
        $adldap = Yii::app()->ldap;

        $user = User::model()->find('LOWER(login)=?', array(strtolower($this->username)));
        
        $username = strtolower($this->username);
        $password = $this->password;
        $authUser = $adldap->user()->authenticate($username, $password);
        $ldapuser = null;
        if (empty($this->username)) $ldapuser = User::model()->find('LOWER(login)=?', array(strtolower(getenv("username"))));
        
        if ($ldapuser && !empty($silent))
        {
            $this->_id = $ldapuser->id;        
            $this->username = $ldapuser->login;
            $this->errorCode = self::ERROR_NONE;
        }
        else if ($user === null)
            $this->errorCode = self::ERROR_USERNAME_INVALID;
        else if ($authUser == true && isset($user))
        {
            $this->_id = $user->id;
            $this->username = $user->login;
            $this->errorCode = self::ERROR_NONE;
        }
        else if (!$user->validatePassword($this->password) && empty($silent))
            $this->errorCode = self::ERROR_PASSWORD_INVALID;
        else if ($user->ban == 1)
        {
            $this->errorCode = self::ERROR_UNKNOWN_IDENTITY;
            $cs = Yii::app()->getClientScript();  
            $cs->registerScript(
              'my-hello-world-1',
              'var popup = "Вы заблокированы. Можете обратиться в ДИТ";
              alert(popup);',
              CClientScript::POS_END
            );            
        }
        
        else
        {
            $this->_id = $user->id;
            $this->username = $user->login;
            $this->errorCode = self::ERROR_NONE;            
        }
        return !$this->errorCode;
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2016-04-04
@des1roer

have you tried deleting $password ?

$authUser = $adldap->user()->authenticate($username);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question