P
P
Petr Fronin2016-08-02 04:12:58
Yii
Petr Fronin, 2016-08-02 04:12:58

Yii2 how to login user with status not 10?

By default, after registration, the status field is filled => 10, introduced a new status => 3 - awaiting moderation. The user should have the same capabilities as with status 10. But after logging in, it does not give any errors, but does not log in. Where can you dig it?
In the User model

public static function findByUsername($username)
    {
        return static::findOne(['username' => $username]);
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kirill Arutyunov, 2016-08-02
@arutyunov

So add a condition so that it looks for users with status 10 and 3.

return static::findOne(['username' => $username, [
    'or', ['status' => self::STATUS_ACTIVE], ['status' => self::STATUS_MODERATE]
]]);

There may be syntax errors, because I did not check.
Also don't forget rules()
['status', 'default', 'value' => self::STATUS_ACTIVE],
['status', 'in', 'range' => [self::STATUS_ACTIVE, self::STATUS_DELETED]],

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question