After login the page is blank and status is still guest

i am trying to implement login function with database using yii 2.0. i have tried for 3 days but it still not working. what did i do wrong?

here is my user and loginform class

i managed to validate the password but after redirect my status is still guest

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;

    }

}



User.php


<?php


namespace app\models;


use yii\base\NotSupportedException;

use yii\db\ActiveRecord;

use yii\helpers\Security;

use yii\web\IdentityInterface;


class User extends \yii\db\ActiveRecord implements \yii\web\IdentityInterface

{

    public $id;

    public $username;

    public $password;

    public $authKey;

    public $accessToken;


    public static function tableName()

    {

        return 'tg_user';

    }


    public function rules()

    {

        return [

            [['user_username'], 'required'],

            [['user_level', 'user_is_active'], 'integer'],

            [['user_name', 'user_username', 'user_password'], 'string', 'max' => 255]

        ];

    }


    /**

     * @inheritdoc

     */

    public function attributeLabels()

    {

        return [

            'user_id' => 'User ID',

            'user_name' => 'User Name',

            'user_username' => 'User Username',

            'user_password' => 'User Password',

            'user_level' => 'User Level',

            'user_is_active' => 'User Is Active',

        ];

    }


    /**

     * @inheritdoc

     */

    public static function findIdentity($id)

    {

        return isset(self::$users[$id]) ? new static(self::$users[$id]) : null;

    }


    /**

     * @inheritdoc

     */

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

    {

        foreach (self::$users as $user) {

            if ($user['accessToken'] === $token) {

                return new static($user);

            }

        }


        return null;

    }


    /**

     * Finds user by username

     *

     * @param  string      $username

     * @return static|null

     */

    public static function findByUsername($username) {

        $user = self::find()

                ->where(["user_username" => $username])

                ->one();

        if (!count($user)) {

            return null;

        }

        return new static($user);

    }


    /**

     * @inheritdoc

     */

    public function getId()

    {

        return $this->id;

    }


    /**

     * @inheritdoc

     */

    public function getAuthKey()

    {

        return $this->authKey;

    }


    /**

     * @inheritdoc

     */

    public function validateAuthKey($authKey)

    {

        return $this->authKey === $authKey;

    }


    /**

     * Validates password

     *

     * @param  string  $password password to validate

     * @return boolean if password provided is valid for current user

     */

    public function validatePassword($password)

    {

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

    }

}



i am interested in this, did you solve it?

Hey delanri, remove these public variables:




    public $id;

    public $username;

    public $password;

    public $authKey;

    public $accessToken;



and tell me about the results, peace out.