【发布时间】:2016-03-12 05:50:15
【问题描述】:
我正在尝试使用 Steam 的 Login With Slim Framework! 为此,我正在尝试使用 steamauth 库 (https://github.com/SmItH197/SteamAuthentication)
我可以通过 start.php 成功要求文件精简,但我如何调用 steamlogin() 和注销函数?
请帮帮我!
【问题讨论】:
我正在尝试使用 Steam 的 Login With Slim Framework! 为此,我正在尝试使用 steamauth 库 (https://github.com/SmItH197/SteamAuthentication)
我可以通过 start.php 成功要求文件精简,但我如何调用 steamlogin() 和注销函数?
请帮帮我!
【问题讨论】:
您需要为身份验证步骤添加一个中间件。
这是一个简单的例子,假设您使用的是 Slim 3:
$middleware = function (Request $request, Response $response, $next) {
$this->user = null;
if(!isset($_SESSION['steamid'])) {
//don't interfere with unmatched routes
$route = $request->getAttribute('route');
if ($route && !in_array($route->getName(), ['login'])) {
return $response->withStatus(403)->withHeader('Location', $this->router->pathFor('login'));
}
} else {
include ('steamauth/userInfo.php'); //To access the $steamprofile array
//Protected content
}
return $next($request, $response);
};
$app->add($middleware);
在你的/login 路由中只包含一个带有steamlogin() 的视图。您可以为此使用基本的php-view 模板。
【讨论】:
userInfo.php 后注入一个全局变量,其值为 $steamprofile