Эх.. нашёл ошибку, надо было в LoginForm.php класс переписать.
User в Users
Код: Выделить всё
2015-04-29 07:40:35 [192.168.56.1][-][neijgqtsahfvop785qpkemo1v2][error][yii\base\ErrorException:1] exception 'yii\base\ErrorException' with message 'Class 'app\models\User' not found' in /var/www/tnved/models/LoginForm.php:74
Stack trace:
#0 /var/www/tnved/vendor/yiisoft/yii2/validators/InlineValidator.php(69): app\models\LoginForm->validatePassword()
#1 /var/www/tnved/vendor/yiisoft/yii2/validators/InlineValidator.php(69): ::call_user_func:{/var/www/tnved/vendor/yiisoft/yii2/validators/InlineValidator.php:69}()
#2 /var/www/tnved/vendor/yiisoft/yii2/validators/Validator.php(238): yii\validators\InlineValidator->validateAttribute()
#3 /var/www/tnved/vendor/yiisoft/yii2/base/Model.php(333): yii\validators\Validator->validateAttributes()
#4 /var/www/tnved/models/LoginForm.php(59): yii\base\Model->validate()
#5 /var/www/tnved/controllers/SiteController.php(62): app\models\LoginForm->login()
#6 /var/www/tnved/vendor/yiisoft/yii2/base/InlineAction.php(55): app\controllers\SiteController->actionLogin()
#7 /var/www/tnved/vendor/yiisoft/yii2/base/InlineAction.php(55): ::call_user_func_array:{/var/www/tnved/vendor/yiisoft/yii2/base/InlineAction.php:55}()
#8 /var/www/tnved/vendor/yiisoft/yii2/base/Controller.php(151): yii\base\InlineAction->runWithParams()
#9 /var/www/tnved/vendor/yiisoft/yii2/base/Module.php(455): yii\base\Controller->runAction()
#10 /var/www/tnved/vendor/yiisoft/yii2/web/Application.php(83): yii\base\Module->runAction()
#11 /var/www/tnved/vendor/yiisoft/yii2/base/Application.php(375): yii\web\Application->handleRequest()
#12 /var/www/tnved/web/index.php(12): yii\base\Application->run()
#13 {main}
2015-04-29 07:40:35 [192.168.56.1][-][neijgqtsahfvop785qpkemo1v2][info][application] $_POST = [
'_csrf' => 'YXFTWmVPemNSQxQoKhcMCiRGACMOGwBUNT4FbBUeKxszJCENJGINUw=='
'LoginForm' => [
'username' => 'demo'
'password' => ' 2f197c497b6220c0d34fb52987e73389'
'rememberMe' => '1'
]
'login-button' => 'Отправить'
]
$_COOKIE = [
'_csrf' => '04df536c743656e3679996062c42dc310bf7b0fcc96b5e639756188f9e159ee0a:2:{i:0;s:5:\"_csrf\";i:1;s:32:\"32GrOXviE7SykTz7TOV6pQQxRUrWA-w0\";}'
'PHPSESSID' => 'neijgqtsahfvop785qpkemo1v2'
]
$_SESSION = [
'__flash' => []
]
$_SERVER = [
'HTTP_USER_AGENT' => 'Opera/9.80 (Windows NT 6.1; WOW64) Presto/2.12.388 Version/12.17'
'HTTP_HOST' => 'www.tnved.test1.ru'
'HTTP_ACCEPT' => 'text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/webp, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1'
'HTTP_ACCEPT_LANGUAGE' => 'ru-RU,zh-cn;q=0.9,ru;q=0.8,en;q=0.7'
'HTTP_ACCEPT_ENCODING' => 'gzip, deflate'
'HTTP_REFERER' => 'http://www.tnved.test1.ru/index.php/site/login'
'HTTP_COOKIE' => '_csrf=04df536c743656e3679996062c42dc310bf7b0fcc96b5e639756188f9e159ee0a%3A2%3A%7Bi%3A0%3Bs%3A5%3A%22_csrf%22%3Bi%3A1%3Bs%3A32%3A%2232GrOXviE7SykTz7TOV6pQQxRUrWA-w0%22%3B%7D; PHPSESSID=neijgqtsahfvop785qpkemo1v2'
'HTTP_CACHE_CONTROL' => 'no-cache'
'HTTP_CONNECTION' => 'Keep-Alive'
'CONTENT_LENGTH' => '279'
'CONTENT_TYPE' => 'application/x-www-form-urlencoded'
'PATH' => '/usr/local/bin:/usr/bin:/bin'
'SERVER_SIGNATURE' => ''
'SERVER_SOFTWARE' => 'Apache/2.2.22 (Debian)'
'SERVER_NAME' => 'www.tnved.test1.ru'
'SERVER_ADDR' => '192.168.56.101'
'SERVER_PORT' => '80'
'REMOTE_ADDR' => '192.168.56.1'
'DOCUMENT_ROOT' => '/var/www/tnved/web'
'SERVER_ADMIN' => '[no address given]'
'SCRIPT_FILENAME' => '/var/www/tnved/web/index.php'
'REMOTE_PORT' => '45878'
'GATEWAY_INTERFACE' => 'CGI/1.1'
'SERVER_PROTOCOL' => 'HTTP/1.1'
'REQUEST_METHOD' => 'POST'
'QUERY_STRING' => ''
'REQUEST_URI' => '/index.php/site/login'
'SCRIPT_NAME' => '/index.php'
'PATH_INFO' => '/site/login'
'PATH_TRANSLATED' => 'redirect:/index.php/login'
'PHP_SELF' => '/index.php/site/login'
'REQUEST_TIME_FLOAT' => 1430293235.612
'REQUEST_TIME' => 1430293235
]
Users.php
Код: Выделить всё
<?php
namespace app\models;
use Yii;
use yii\base\NotSupportedException;
use yii\db\ActiveRecord;
use yii\helpers\Security;
use yii\web\IdentityInterface;
/**
* This is the model class for table "users".
*
* @property integer $id
* @property integer $owner_id
* @property integer $default_c_id
* @property integer $public
* @property string $login
* @property string $password
* @property string $role
* @property string $username
* @property string $email
* @property string $PersonSurname
* @property string $PersonMiddleName
* @property string $sex
* @property string $dateOfBirth
* @property string $Phone
* @property integer $tarif
* @property string $services
* @property integer $checked
* @property integer $checkMail
* @property integer $tng
* @property string $profile
*/
class Users extends \yii\db\ActiveRecord implements IdentityInterface
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'users';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['owner_id', 'default_c_id', 'login', 'password', 'username', 'email', 'tarif', 'profile'], 'required'],
[['owner_id', 'default_c_id', 'public', 'tarif', 'checked', 'checkMail', 'tng'], 'integer'],
[['role', 'sex'], 'string'],
[['dateOfBirth'], 'safe'],
[['login'], 'string', 'max' => 63],
[['password'], 'string', 'max' => 32],
[['username', 'email'], 'string', 'max' => 255],
[['PersonSurname', 'PersonMiddleName'], 'string', 'max' => 150],
[['Phone'], 'string', 'max' => 24],
[['services'], 'string', 'max' => 18],
[['profile'], 'string', 'max' => 250],
[['login'], 'unique'],
[['email'], 'unique'],
['role', 'default', 'value' => 'user'], // default role user(create users)
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'owner_id' => 'Owner ID',
'default_c_id' => 'Default C ID',
'public' => 'Public',
'login' => 'Login',
'password' => 'Password',
'role' => 'Role',
'username' => 'Username',
'email' => 'Email',
'PersonSurname' => 'Person Surname',
'PersonMiddleName' => 'Person Middle Name',
'sex' => 'Sex',
'dateOfBirth' => 'Date Of Birth',
'Phone' => 'Phone',
'tarif' => 'Tarif',
'services' => 'Services',
'checked' => 'Checked',
'checkMail' => 'Check Mail',
'tng' => 'Tng',
'profile' => 'Profile',
];
}
/** INCLUDE USER LOGIN VALIDATION FUNCTIONS**/
/**
* @inheritdoc
*/
public static function findIdentity($id)
{
return static::findOne($id);
}
/**
* @inheritdoc
*/
/* modified */
public static function findIdentityByAccessToken($token, $type = null)
{
return static::findOne(['access_token' => $token]);
}
/* removed
public static function findIdentityByAccessToken($token)
{
throw new NotSupportedException('"findIdentityByAccessToken" is not implemented.');
}
*/
/**
* Finds user by username
*
* @param string $username
* @return static|null
*/
public static function findByUsername($username)
{
return static::findOne(['login' => $username]);
}
/**
* Finds user by password reset token
*
* @param string $token password reset token
* @return static|null
*/
public static function findByPasswordResetToken($token)
{
$expire = \Yii::$app->params['user.passwordResetTokenExpire'];
$parts = explode('_', $token);
$timestamp = (int) end($parts);
if ($timestamp + $expire < time()) {
// token expired
return null;
}
return static::findOne([
'password_reset_token' => $token
]);
}
/**
* @inheritdoc
*/
public function getId()
{
return $this->getPrimaryKey();
}
/**
* @inheritdoc
*/
public function getAuthKey()
{
return $this->auth_key;
}
/**
* @inheritdoc
*/
public function validateAuthKey($authKey)
{
return $this->getAuthKey() === $authKey;
}
/**
* Validates password
*
* @param string $password password to validate
* @return boolean if password provided is valid for current user
*/
public function validatePassword($password)
{
//! BUG, need true encode
return $this->password === $password;
}
/**
* Generates password hash from password and sets it to the model
*
* @param string $password
*/
public function setPassword($password)
{
$this->password_hash = Security::generatePasswordHash($password);
}
/**
* Generates "remember me" authentication key
*/
public function generateAuthKey()
{
$this->auth_key = Security::generateRandomKey();
}
/**
* Generates new password reset token
*/
public function generatePasswordResetToken()
{
$this->password_reset_token = Security::generateRandomKey() . '_' . time();
}
/**
* Removes password reset token
*/
public function removePasswordResetToken()
{
$this->password_reset_token = null;
}
/** EXTENSION MOVIE **/
}
LoginForm.php
Код: Выделить всё
<?php
namespace app\models;
use Yii;
use yii\base\Model;
/**
* LoginForm is the model behind the login form.
*/
class LoginForm extends Model
{
public $username;
public $password;
public $rememberMe = true;
private $_user = false;
/**
* @return array the validation rules.
*/
public function rules()
{
return [
// username and password are both required
[['username', 'password'], 'required'],
// rememberMe must be a boolean value
['rememberMe', 'boolean'],
// password is validated by validatePassword()
['password', 'validatePassword'],
];
}
/**
* Validates the password.
* This method serves as the inline validation for password.
*
* @param string $attribute the attribute currently being validated
* @param array $params the additional name-value pairs given in the rule
*/
public function validatePassword($attribute, $params)
{
if (!$this->hasErrors()) {
$user = $this->getUser();
if (!$user || !$user->validatePassword($this->password)) {
$this->addError($attribute, 'Incorrect username or password.');
}
}
}
/**
* Logs in a user using the provided username and password.
* @return boolean whether the user is logged in successfully
*/
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;
}
}
74
Stack