ユーザーがログインしているかどうかを確認したいので、クラスの魔女がtrueまたはfalseを返します。今、ユーザーがログインしているかどうかを確認するミドルウェアが必要です。
$app->get('/login', '\Controller\AccountController:loginGet')->add(Auth::class)->setName('login');
$app->post('/login', '\Controller\AccountController:loginPost')->add(Auth::class);
認証クラス
class Auth {
protected $ci;
private $account;
//Constructor
public function __construct(ContainerInterface $ci) {
$this->ci = $ci;
$this->account = new \Account($this->ci);
}
public function __invoke($request, \Slim\Http\Response $response, $next) {
if($this->account->login_check()) {
$response = $next($request, $response);
return $response;
} else {
//Redirect to Homepage
}
}
}
したがって、ユーザーがログインすると、ページは正しくレンダリングされます。しかし、ユーザーが自動化されていない場合、ホームページにリダイレクトしたいと考えています。しかし、どうやって?
$response->withRedirect($router->pathFor('home');
これはうまくいきません!