<?php
namespace app\middleware;

use Webman\MiddlewareInterface;
use Webman\Http\Response;
use Webman\Http\Request;

class Login implements MiddlewareInterface
{
    public function process(Request $request, callable $handler) : Response
    {
        $route = $request->route->getPath();
        $id=$request->cookie('id', 'blank');
        $key=$request->cookie('key', 'blank');
        if(substr($route, 0, 6) != "/login"){
            if($id=='blank' || $key='blank'){
                return redirect('/login');
            }
        }
        $request->id=$id;
        $request->key=$key;
        return $handler($request);
    }
}