Authentication not working in yii2

1. I have Employee table whose structure is as follows:

EmpId

FirstName

LastName

Username

Password

[b]2. Now in application component I have included my custom class as follows:

[/b]

‘user’ =>

[ ‘identityClass’ => ‘app\models\Employee’,

‘enableSession’ => true,

],

3.I have implemented foll methods in Employee model as follows:

public static function findIdentityByAccessToken($token, $type = null)

{

throw new NotSupportedException();

}

public function getId()

{

return $this->EmpId;

}

public function getAuthKey()

{

throw new NotSupportedException();

}

public function validateAuthKey($authKey)

{

throw new NotSupportedException();

}

public static function findByUsername($username)

{

return self::findOne([‘Username’=>$username]);

}

public function validatePassword($password)

{

return $this->Password === $password;

}

4. And in LoginForm model, I have following. Insted of User, I have included custom class Employee.

public function getUser()

{

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

{

$this->_user = Employee::findByUsername($this->username);

}

return $this->_user;

}

5. Now when I try to login and provide username and password, it gives the foll error:

Unknown Property – yii\base\UnknownPropertyException

Getting unknown property: app\models\Employee::username

Is Username capitalized?

Your Employee table doesn’t have a username property. If you’re using the advanced template, Employee is missing a number of fields:




 * @property integer $id

 * @property string $username

 * @property string $auth_key

 * @property string $password_hash

 * @property string $password_reset_token

 * @property string $email

 * @property integer $created_at

 * @property integer $updated_at

 * @property string $password write-only password



Created/Updated may not be there/needed either, but I modified the init migration and some columns.

Is there a difference between a User and an Employee? and Why an Employee Table? Not asking to be difficult. I’s working on a site that the Employees are the Users, so I just used the User table and related (one to one) a profile table with other info.

In the UI I have a menu item that says ‘Employees’ and made a controller called EmployeeController so that the web address would say \employee\index, but it is getting the information from the User & Profile models. I think I even generated the CRUD with GII, just said the controller was Employee not User. Worked fine.