我想在我的网页上使用basic.auth
,但身份验证无效
admin
- 身份验证Route::get('admin', array('before' => 'auth.basic', function()
{
return 'Top secret';
}));
create
- 创建测试用户Route::get('create', function()
{
$user = new User;
$user->email = 'test@test.com';
$user->username = 'test';
$user->password = Hash::make('password');
$user->save();
});
app/config/app
- 定义了key
(创建了Laravel安装)app/config/auth
- 已定义model
(User
)和table
(users
)auth.basic
Route::filter('auth.basic', function()
{
return Auth::basic();
});
我致电/create
创建用户test@test.com
:password
以下是users
表:
然后我致电/admin
登录
但它不会让我进去。在登录之后 - 它只是清除输入。在取消之后 - 它返回Invalid credentials.
。
我尝试了实施UserInterface
<?php
use Illuminate\Auth\UserInterface;
class User extends Eloquent implements UserInterface {
protected $table = 'users';
/**
* Get the unique identifier for the user.
*
* @return mixed
*/
public function getAuthIdentifier()
{
return $this->getKey();
}
/**
* Get the password for the user.
*
* @return string
*/
public function getAuthPassword()
{
return $this->passsword;
}
}
我在User
模型return $this->passsword;
中输了错误有3 s
。
现在我使用默认的Laravel User model。
答案 0 :(得分:4)
确保在app / config / auth.php中将driver
设置为eloquent
。
您可能还需要实施UserInterface
界面(class User extends Eloquent implements UserInterface
) - 然后您需要在模型中包含这些方法:
/**
* Get the unique identifier for the user.
*
* @return mixed
*/
public function getAuthIdentifier()
{
return $this->getKey();
}
/**
* Get the password for the user.
*
* @return string
*/
public function getAuthPassword()
{
return $this->password;
}