Код: Выделить всё
<?php
namespace common\models;
use Yii;
use yii\db\ActiveRecord;
use yii\web\IdentityInterface;
/**
* This is the model class for table "Myuser".
*
* @property integer $id
* @property string $username
* @property string $password
* @property string $hesh
*/
class Myuser extends ActiveRecord implements IdentityInterface
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'Myuser';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['username'], 'string', 'max' => 150],
[['password', 'hesh'], 'string', 'max' => 250],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'username' => 'Username',
'password' => 'Password',
'hesh' => 'Hesh',
];
}
public static function findIdentity($id)
{
return static::findOne($id);
}
public static function findIdentityByAccessToken($token, $type = null)
{
/* return static::findOne(['access_token' => $token]);*/
}
public function getId()
{
return $this->id;
}
public function getAuthKey()
{
return $this->auth_key;
}
public function validateAuthKey($authKey)
{
return $this->getAuthKey() === $authKey;
}
public static function findByUsername($username)
{
return static::findOne(['username' => $username]);
}
}
Код: Выделить всё
<?php
namespace common\models;
use Yii;
use yii\base\Model;
class Mylogin extends Model
{
public $username;
public $password;
private $_user;
public function rules()
{
return [
// username and password are both required
[['username', 'password'], 'required'],
];
}
public function attributeLabels(){
return [
'username' => 'Логин',
'password' => 'Пароль',
];
}
public function login()
{
if ($this->validate()) {
return Yii::$app->user->login($this->getUser(),0);
} else {
return false;
}
}
protected function getUser()
{
if ($this->_user === null) {
$this->_user = Myuser::findByUsername($this->username);
}
return $this->_user;
}
}
?>
Код: Выделить всё
public function actionAutoform(){
if (!Yii::$app->user->isGuest) {
return $this->goHome();
}
$model = new Mylogin();
//return $this->render('autoform',['model'=>$model]);
if ($model->load(Yii::$app->request->post()) && $model->login()) {
return $this->goBack();
}
else
{
return $this->render('autoform',['model'=>$model]);
}
}
Код: Выделить всё
Argument 1 passed to yii\web\User::login() must implement interface yii\web\IdentityInterface, null given, called in C:\WebServer\OpenServer\domains\billing\common\models\Mylogin.php on line 37 and defined