Sentinel和Laravel 5.2

时间:2016-02-13 14:03:29

标签: laravel authentication sentinel

我无法让Sentinel工作。我不知道该怎么做,我尝试了一切,希望其他人有一些建议。 问题在于在线中间件,其中检查方法是错误的......

编辑:我发现问题是会话在中间件中不起作用,仍然没有解决方案

EDIT2:看起来像它的permisions,我在ubuntu上,我在win10上用xampp运行相同的代码,一切正常,仍然没有ubuntu的解决方案

routes.php文件

Route::group(['middleware' => ['web']], function () {

Route::get('/',          ['as' => 'index'    , 'uses' => 'UserController@index']);
Route::post('login',     ['as' => 'login'    , 'uses' => 'UserController@login']);
Route::post('register',  ['as' => 'register' , 'uses' => 'UserController@register']);
Route::get('logout',    ['as' => 'logout'   , 'uses' => 'UserController@logout']);

Route::group(['prefix' => 'viva' , 'middleware' => ['online']], function () {
    Route::get('/',     ['as' => 'dashboard'    , 'uses' => 'VivaController@dashboard']);
});
});

登录方法

public function login(){
    $data = Input::all();

    $credentials = [
        'email'    => $data["username"],
        'password' => $data["password"],
    ];

    $user = Sentinel::authenticate($credentials);

    if (!empty($user)){
        Sentinel::login($user);
        //dd(Sentinel::check()); //---> this gives logged user...
        return Redirect::route('dashboard');
    }
    else{
        return Redirect::back()->withErrors(['fail', 'Neuspjela prijava! Molimo pokušajte ponovo.']);
    }


}

online.php中间件

 class online
{
/**
 * Handle an incoming request.
 *
 * @param  \Illuminate\Http\Request  $request
 * @param  \Closure  $next
 * @return mixed
 */
public function handle($request, Closure $next )
{
    dd(Sentinel::check()); //---> this is always false


    if (Sentinel::check())
    {
        return Redirect::route('dashboard');
    }
    else
    {
        return Redirect::route('index')->withErrors(['fail', 'Nemate prava na pristup ovim stranicama!']);
    }

    return $next($request);

}
}

1 个答案:

答案 0 :(得分:0)

对于会话,我相信您可能需要这些权限。

注意:假设Laravel安装在/var/www/laravel

cd /var/www/laravel
sudo chgrp -R www-data storage bootstrap/cache
sudo chmod -R ug+rwx storage bootstrap/cache