<?php
namespace frontend\models;
use Yii;
/**
* This is the model class for table "User".
*
* @property string $username
* @property string $email
* @property string $phone
* @property string $ava
* @property integer $id
* @property string $auth_key
* @property string $token
* @property string $status
* @property string $pass
*/
class User extends \yii\db\ActiveRecord implements \yii\web\IdentityInterface
{
const DEFAULT_STATUS = 0;
const DEFAULT_ROLE = 'user';
/**
* @inheritdoc
*/
public static function tableName()
{
return 'User';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['username', 'email', 'phone', 'ava', 'id', 'auth_key', 'token', 'status', 'pass'], 'required'],
[['username', 'email', 'phone', 'ava', 'status', 'pass'], 'string'],
[['id'], 'integer'],
[['auth_key', 'token'], 'string', 'max' => 32],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'username' => 'Username',
'email' => 'Email',
'phone' => 'Phone',
'ava' => 'Ava',
'id' => 'ID',
'auth_key' => 'Auth Key',
'token' => 'Token',
'status' => 'Status',
'pass' => 'Pass',
];
}
public static function findIdentity($id)
{
return static::findOne($id);
}
public static function findByUsername($username)
{
return static::findOne(['username' => $username]);
}
public function validatePassword($password)
{
return \Yii::$app->security->validatePassword($password, $this->password);
}
public function getId()
{
return $this->id;
}
public static function findIdentityByAccessToken($token, $type = null)
{
}
public function getAuthKey()
{
}
public function validateAuthKey($authKey)
{
}
public function login()
{
if ($this->validate()) {
return Yii::$app->UserIdentity->login($this->getUser(), $this->rememberMe ? 3600 * 24 * 30 : 0);
}
return false;
}
}</spoiler>
Модель наследник<?php
namespace frontend\models;
class UserIdentity extends User implements \yii\web\IdentityInterface
{
private $pass;
public static function findIdentity($id)
{
return static::findOne($id);
}
/**
* @inheritdoc
*/
public static function findIdentityByAccessToken($token, $type = null)
{
return static::findOne(['token' => $token]);
}
/**
* Finds user by username
*
* @param string $username
* @return static|null
*/
public static function findByUsername($username)
{
return static::findOne(['username' => $username]);
}
/**
* @inheritdoc
*/
public function getId()
{
return $this->id;
}
/**
* @inheritdoc
*/
public function getAuthKey()
{
return $this->auth_key;
}
/**
* @inheritdoc
*/
public function validateAuthKey($authKey)
{
return $this->auth_key === $authKey;
}
/**
* Validates password
*
* @param string $password password to validate
* @return bool if password provided is valid for current user
*/
public function validatePassword($password)
{
return $this->pass === md5($password);
}
}
В БД есть таблицца Юзер с необходимыми полями, сама модель User была сгенерирована в GII.
Результат, после ввода правильных данных и не правильных данных, форма просто отправляется без ошибок.