Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Api 基本授权文件4如何使用?_Api_Laravel 4_Basic Authentication - Fatal编程技术网

Api 基本授权文件4如何使用?

Api 基本授权文件4如何使用?,api,laravel-4,basic-authentication,Api,Laravel 4,Basic Authentication,我试图用凭据保护我的restAPI,并阅读有关基本身份验证的文章。我试图实现一个基本的身份验证系统 用户选项卡已存在并已填充数据 在filter.php中,我设置了 路由::过滤器'auth.basic',函数{ 返回Auth::basic;} 比在api路由中 // ============================================= // API ROUTES ================================== // =================

我试图用凭据保护我的restAPI,并阅读有关基本身份验证的文章。我试图实现一个基本的身份验证系统

用户选项卡已存在并已填充数据

在filter.php中,我设置了

路由::过滤器'auth.basic',函数{ 返回Auth::basic;}

比在api路由中

// =============================================
// API ROUTES ==================================
// =============================================
Route::group(array('prefix' => 'api', 'before' => 'auth.basic'), function() {

            Route::resource('products', 'ProductController', array('only' => array('index', 'store', 'destroy', 'update', 'show', 'edit')));
            Route::get('products/{id}', 'ProductController@get', array('only' => array('show')));
        });
控制器非常简单

<?php

use App\Models\Product;

class ProductController extends \BaseController {

    private $model;

    function __construct() {
        $this->model = new Product();
    }

    /**
     * Display a listing of the resource.
     *
     * @return Response
     */
    public function index() {
        $model = new Product();
        $page           =      Input::get('pageNumber');
        $limit          =      Input::get('pageNumber');
        $ram            =      Input::get('limit');
        $cpu            =      Input::get('cpu');
        $price_range    =      Input::get('price_range');
        $keyword       =      Input::get('keyword');
        return Response::json($model->getProducts($page));
    }

    /**
     * Store a newly created resource in storage.
     *
     * @return Response
     */
    public function store() {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return Response
     */
    public function destroy($id) {

    }

    public function get($id) {
        $model = new Product();
        return Response::json($model->getProduct($id));
    }

    public function show($id) {       
        return Response::json($this->model->getProduct($id));
    }

    public function update($id) {       
        return Response::json($this->model->getProduct($id));
    }

    public function pause($id) {
        var_dump('pause');
    }

    public function create(){

    }

    public function edit(){
        var_dump('test_edit');
    }

}
路线

路由::获取'admin/login',数组'as'=>'admin.login','uses' =>'应用程序\控制器\管理员\AuthController@getLogin';

控制器


您似乎没有定义登录函数

顺便说一下,您应该更改:

Route::group(array('prefix' => 'api', 'before' => 'auth.basic'), function() {

            Route::resource('products', 'ProductController', array('only' => array('index', 'store', 'destroy', 'update', 'show', 'edit')));
            Route::get('products/{id}', 'ProductController@get', array('only' => array('show')));
        });
致:


感谢您的更正,登录系统已经存在,但backen的代码已从frontendok分离。请使用登录/注销功能和路径更新问题,如果您更改了,请使用过滤器更新问题。然后使用HTML代码检查登录表单是否提交到正确的URL。
<?php namespace App\Controllers\Admin;

use Auth, BaseController, Form, Input, Redirect, Sentry, View;

class AuthController extends BaseController {

    /**
     * Display the login page
     * @return View
     */
    public function getLogin()
    {
        return View::make('admin.auth.login');
    }

    /**
     * Login action
     * @return Redirect
     */
    public function postLogin()
    {
        $credentials = array(
            'email'    => Input::get('email'),
            'password' => Input::get('password')
        );

        try
        {
            $user = Sentry::authenticate($credentials, false);

            if ($user)
            {
                return Redirect::route('admin.pages.index');
            }
        }
        catch(\Exception $e)
        {
            return Redirect::route('admin.login')->withErrors(array('login' => $e->getMessage()));
        }
    }

    /**
     * Logout action
     * @return Redirect
     */
    public function getLogout()
    {
        Sentry::logout();

        return Redirect::route('admin.login');
    }

}
Route::group(array('prefix' => 'api', 'before' => 'auth.basic'), function() {

            Route::resource('products', 'ProductController', array('only' => array('index', 'store', 'destroy', 'update', 'show', 'edit')));
            Route::get('products/{id}', 'ProductController@get', array('only' => array('show')));
        });
Route::group(array('prefix' => 'api', 'before' => 'auth.basic'), function(){

    Route::get('products/{id}', 'ProductController@get'));
    Route::resource('products', 'ProductController', array('except' => array('show')));
});