Lia*_*ter 7 php authentication http-authentication laravel
我正在使用Laravel中提供的基本HTTP身份验证登录我的网站.但是,当我打电话时,即使我已登录,Auth::Check()我总是得到错误的回复.
难道Auth::Check()不符合基本的身份验证模式工作,如果没有,有没有什么办法来检查基本身份验证,看是否有用户登录?
这是我的用户类:
namespace App;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'email', 'password',
];
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
public function getRememberToken()
{
return $this->remember_token;
}
public function setRememberToken($value)
{
$this->remember_token = $value;
}
public function getRememberTokenName()
{
return 'remember_token';
}
}
Run Code Online (Sandbox Code Playgroud)
这是我设置要使用的身份验证过滤器的代码段
$this->middleware('auth.basic', ['only' => ['create', 'store', 'edit', 'update', 'destroy']]);
Run Code Online (Sandbox Code Playgroud)
这是我的Auth::Check()电话(总是打印0):
public function show($id)
{
echo \Auth::check() ? '1' : '0';
die();
#.......
}
Run Code Online (Sandbox Code Playgroud)
在5.2版本中有所改变。
如果您将使用会话、csrf、cookie ext。你应该在你的路由中使用像这样的“web”中间件:
Route::group(['middleware' => ['web']], function () {
//
});
Run Code Online (Sandbox Code Playgroud)
你可以在你的项目中看到新的 kernel.php 文件是这样的:
/**
* The application's route middleware groups.
*
* @var array
*/
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
],
'api' => [
'throttle:60,1',
],
];
Run Code Online (Sandbox Code Playgroud)
更多信息: https: //laravel.com/docs/5.2/releases
| 归档时间: |
|
| 查看次数: |
2826 次 |
| 最近记录: |