Есть форма Login:
<div data-role="page" id="login">
<div data-role="header">
<h2>Авторизация</h2>
</div>
<div role="main" class="ui-content jqm-content">
<form role="form" action="/login" method="POST" class="userform">
<div class="ui-grid-solo">
<div class="ui-grid-a">
<label for="username">Имя</label>
<input type="text" name="login" id="login" value="" data-clear-btn="true" data-mini="true">
<label for="password">Пароль</label>
<input type="password" name="password" id="password" value="" data-clear-btn="true" autocomplete="off" data-mini="true">
<input type="checkbox" name="remind" id="remind" value="1">
<label for="remind">Запомнить меня</label>
<br>
<input type="submit" value="Логин" onclick="this.form.submit();">
</div>
</div>
</form>
</div>
</div>
Я в SiteController делаю так:
public function actionIndex()
{
$r = Yii::$app->request;
if (\Yii::$app->user->isGuest) {
return $this->render('login');
}
else {
return $this->render('index');
}
}
public function actionLogin()
{
if (!\Yii::$app->user->isGuest) {
return $this->render('login');
}
$model = new LoginForm();
if ($model->load(Yii::$app->request->post()) && $model->login()) {
return $this->render('about');
} else {
/*
return $this->render('login', [
'model' => $model,
]);
*/
return $this->render('contact');
}
}
В LoginForm:
public function login()
{
if ($this->validate()) {
return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600 * 24 * 30 : 0);
} else {
return false;
}
}
/**
* Finds user by [[username]]
*
* @return User|null
*/
public function getUser()
{
if ($this->_user === false) {
$this->_user = User::findByUsername($this->username);
}
return $this->_user;
}
В models/User:
public $username = 'admin';
public $password = 'admin';
public $rememberMe = true;
public function findByUsername($username) {
if ($this->$username === $username) {
return true;
}
else {
return false;
}
}
public function validatePassword($password)
{
if ($this->$username === $username) {
return true;
}
else {
return false;
}
//return Yii::$app->security->validatePassword($password, $this->password_hash);
}
Почему при submit меня опять выбрасывает в форму Login?