我正在用Laravel 4.1创建一个api。对于身份验证,我想使用Laravel Basic身份验证。每次我填写输入字段时,它都不允许我进入。它只是清除输入并再次弹出表单。我不确定我做错了什么。我没有使用迁移来创建用户表。这只是一条基本路线:
Route::get('admin', function()
{
return "authenticated";
})->before('auth.basic');
这是我的过滤器:
Route::filter('auth.basic', function()
{
return Auth::basic('username');
});
这是我的用户模型:
<?php
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;
class User extends Eloquent implements UserInterface, RemindableInterface {
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'users';
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = array('password', 'pivot');
/**
* @var array
*/
protected $guarded = array('id', 'created_at', 'updated_at', 'is_admin');
protected $fillable = array('username', 'password', 'name_first', 'name_middle', 'name_last', 'email', 'address', 'city', 'state', 'zip_code', 'country', 'phone', 'title', 'profile_image', 'status');
/**
* @var array
*/
public static $rules = array();
/**
* 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;
}
/**
* Get the e-mail address where password reminders are sent.
*
* @return string
*/
public function getReminderEmail()
{
return $this->email;
}
}
答案 0 :(得分:0)
你为什么不试试
Route::get('admin', array( 'before' => 'auth.basic' ,function()
{
return "authenticated";
}));
您的密码需要在数据库中进行哈希处理。