我想用basic.auth
对于我的网页,但身份验证不起作用
路线.php
admin
- 验证
Route::get('admin', array('before' => 'auth.basic', function()
{
return 'Top secret';
}));
create
- 创建测试用户
Route::get('create', function()
{
$user = new User;
$user->email = '[email protected] /cdn-cgi/l/email-protection';
$user->username = 'test';
$user->password = Hash::make('password');
$user->save();
});
config
-
app/config/app
- 已定义key
(创建了 Laravel 安装)
-
app/config/auth
- 已定义model
(User
) and table
(users
)
过滤器.php
auth.basic
Route::filter('auth.basic', function()
{
return Auth::basic();
});
test
I call /create
创建用户[email protected] /cdn-cgi/l/email-protection
:password
Here is users
table after:
然后我打电话/admin
登录
But it doesnt let me in. After Login - it just clear inputs. After Cancel - it return 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
model return $this->passsword;
有 3 个s
.
现在我使用默认的 Laravel用户模型 http://github.com/laravel/laravel/blob/master/app/models/User.php.