Laravel 拉维尔基本认证
我想对我的网页使用Laravel 拉维尔基本认证,laravel,laravel-4,Laravel,Laravel 4,我想对我的网页使用basic.auth,但身份验证不起作用 routes.php 管理-身份验证 创建-创建测试用户 配置 app/config/app-定义了键(创建了Laravel安装) app/config/auth-定义了模型(用户)和表(用户) filters.php auth.basic 测试 我调用/create创建用户test@test.com:密码 以下是用户表格: 然后我调用/admin登录 但它不让我进去。登录后-只需清除输入。取消后-返回无效凭据。 用户模型 我
basic.auth
,但身份验证不起作用
routes.php
管理
-身份验证
创建
-创建测试用户
配置
-定义了app/config/app
键(创建了Laravel安装)
-定义了app/config/auth
模型(
)和用户
表(
)用户
auth.basic
测试
我调用/create
创建用户test@test.com
:密码
以下是用户
表格:
然后我调用/admin
登录
但它不让我进去。登录后-只需清除输入。取消后-返回无效凭据。
用户模型 我尝试实现
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;
}
}
确保在app/config/auth.php-driver
中设置为elount
您可能还需要实现UserInterface
接口(class-User-extends-elount-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;
}
1) 用户模型中是否有属性修饰符?-特别是对于密码(我有一个setter可以自动对给定值进行散列,所以我对密码进行了双重散列)和2)您是否尝试了另一个浏览器?@RobGordijn-1)用户模型只有-类用户扩展雄辩的{}
。2) google chrome,Firefox你的用户模型实现了用户界面吗???看看Laravel 4附带的默认user.php
模型。你到底在找什么?这是Laravel 4附带的默认模型:是的,它设置为eloquent |auth.php
-'driver'=>'eloquent'
您的答案非常好。。。我在return$this->passsword中输入了错别字代码>-3xs
哦,很好,PEBKAC错误。是的,我们很难诊断:)
Route::filter('auth.basic', function()
{
return Auth::basic();
});
<?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;
}
}
/**
* 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;
}