Closed cansozeri closed 10 years ago
Looks fine, however, could you please merge the "orWhere" lines into one? That way will be avaluated as one instruction instead of separated conditions (when yii generates sql) Thanks in advance.
is this what you want ??
$user->orWhere(["email" => $this->username])
->orWhere(["username" => $this->username]);
I mean
$user->orWhere(['email' => $this->username, 'email' => $this->username]);
Thanks in advance.
Yeah I tried it first but the yii add an 'And' operator I don't know why ?? So I can not login with username...
$user->orWhere(['email' => $this->username, 'username' => $this->username]);
Than the query is ( yii2 debug tool)
SELECT * FROM `user` WHERE (`email`='cansozeri') AND (`username`='cansozeri')
This should be to login with username or email with 'Or' not 'And'
If I use it like this
$user->orWhere(["email" => $this->username])
->orWhere(["username" => $this->username]);
The query is ok with 'Or'
SELECT * FROM `user` WHERE (`email`='cansozeri') OR (`username`='cansozeri')
Right, please, change it to:
$user->where(['or', 'email' => $this->username, 'username' => $this->username]);
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'cansozeri' in 'where clause'
The SQL being executed was: SELECT * FROM user
WHERE (cansozeri) OR (cansozeri)
:))) I am lookin into it from google too it is strange but I can not add 'or' operator without errors.
Have you "composer.phar update" your project?
Yes I did it ...
I think the right way to do is the first one I send over here as this example ..
$model = User::find()
->where('userid > :userid', [':userid' => $userid])
->orWhere('primary_user = :primary_user', [':primary_user' => $primary_user])
->andWhere('status = :status', [':status' => $status])
->all();
I think like propel this ->orWhere and ->andWhere evaluated as one instruction...
So we should use
$user->orWhere(["email" => $this->username])->orWhere(["username" => $this->username]);
or
$user->where(["email" => $this->username])->orWhere(["username" => $this->username]);
or with one code...
$this->_user = User::find()
->where(["email" => $this->username])
->orWhere(["username" => $this->username])
->one();
After some tests, I realize the best alternative :)
Please change models/User.php Line 94 to:
return static::find()->andWhere(['and', ['or', ['username' => $username], ['email' => $username]], ['status' => static::STATUS_ACTIVE]])->one();
Then I will accept the pull request. Thanks.
: )))) Ok I did it but I think this is your pull request not mine : ))
Since pull request #24 fixes this issue, I will close it.
Thanks.
Functionality to login with username ... If you have a proper solution for this please provide or you can merge with this code . Thanx : )