<?php namespace App\Filters;

use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use CodeIgniter\Filters\FilterInterface;

/*********************************************
*        针对页面访问的过滤器
*********************************************/

class LoginPageFilter implements FilterInterface
{
    public function before(RequestInterface $request)
    {
        $username = $request->getGet("username");
        $token = $request->getGet("token");

        if($username == "" || $token == ""){
            return redirect("sign");
        }else{
            $signModel = new \App\Models\SignModel();
            $userInfo = $signModel->getItemByUsername($username);
            if($userInfo[0]["token"] != $token){
                return redirect("sign");                   
            }
        }
    }

    //--------------------------------------------------------------------

    public function after(RequestInterface $request, ResponseInterface $response)
    {
        // Do something here
    }
}