Custom Login from a database


(Leno1232) #1

Hello to everyone!
I will go straight to the subject of my question.

Question: I made, a custom login system , that retrieves data, from a table ,from a localhost ,xampp, php my admin. But whenever ,I try to login, it seems that the id ,of every, user, is passed , but still though, Yii2, does not login my custom user.?
Anyone, had this issue before?
I searched but still ,got no answer.

Thank you for reading my post!


(Johnson) #2

Hi Leno,

Few Steps you should do …

Have you added the identity class in config?

    'components' => [
    'user' => [
        'identityClass' => 'app\models\User', //Typically your db model that used for login
        'enableAutoLogin' => true,
    ]
]

As well please make sure you have implemented IdentityInterface in your model as follows!
class User extends \yii\db\ActiveRecord implements IdentityInterface

In your controller make sure to call auto login!

$model = new User();
if ($model->load(Yii::$app->request->post()) && $model->login()) {
    return $this->goBack(); // Whatever your success operations
} else {
    // Your failiure error message collections
}

And thats it!


(Leno1232) #3

Thanks !! It worked!