簡體   English   中英

如何將CKFinder與Laravel集成?

[英]How to integrate CKFinder with Laravel?

我正在嘗試將CKFinder與Laravel整合在一起,而我在那里的成績約為95%。 我可以讓一切工作,除了CheckAuthentication函數 - 我必須使它return true無論上傳工作。

我嘗試做的是在config.php文件中引導Laravel,然后檢查用戶是否已登錄,如下所示:

公共/包/ ckfinder / config.php文件

<?php
/*
 * ### CKFinder : Configuration File - Basic Instructions
 *
 * In a generic usage case, the following tasks must be done to configure
 * CKFinder:
 *     1. Check the $baseUrl and $baseDir variables;
 *     2. If available, paste your license key in the "LicenseKey" setting;
 *     3. Create the CheckAuthentication() function that enables CKFinder for authenticated users;
 *
 * Other settings may be left with their default values, or used to control
 * advanced features of CKFinder.
 */

/** RIPPED FROM public/index.php **/

/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader
| for our application. We just need to utilize it! We'll require it
| into the script here so that we do not have to worry about the
| loading of any our classes "manually". Feels great to relax.
|
*/

require __DIR__.'/../../../bootstrap/autoload.php';

/*
|--------------------------------------------------------------------------
| Turn On The Lights
|--------------------------------------------------------------------------
|
| We need to illuminate PHP development, so let's turn on the lights.
| This bootstraps the framework and gets it ready for use, then it
| will load up this application so that we can run it and send
| the responses back to the browser and delight these users.
|
*/

$app = require __DIR__.'/../../../bootstrap/start.php';

/** END public/index.php **/

/**
 * This function must check the user session to be sure that he/she is
 * authorized to upload and access files in the File Browser.
 *
 * @return boolean
 */
function CheckAuthentication()
{
    // WARNING : DO NOT simply return "true". By doing so, you are allowing
    // "anyone" to upload and list the files in your server. You must implement
    // some kind of session validation here. Even something very simple as...

    return Auth::check();
}

但是,這總是返回false。 我也嘗試直接使用Laravel的Session在某人登錄時將變量設置為true,在他們注銷時將其設置為false,然后在config.php文件中檢查該變量,但它始終在Session::get("IsAuthorized", false);返回默認值Session::get("IsAuthorized", false); 任何人都可以提供一些指導 -

1)如何驗證是否允許用戶上傳?

2)為什么在另一個文件中引導Laravel似乎會導致它使用單獨的會話,即使它正在加載相同的文件?

我嘗試將simogeo的Filemanager和KCFinder集成到Laravel項目中,我發現了同樣的問題。

使用此代碼,可以共享Laravel的會話並檢查外部項目的身份驗證:

https://gist.github.com/frzsombor/ddd0e11f93885060ef35

根據我的經驗,從4.1.28開始,Application :: boot()不再初始化敏感會話數據。

因此,如果您要集成第三方庫,需要通過會話進行外部驗證檢查,則簡單檢查Auth :: check()將不起作用。 但是,我們仍然可以使用舊的$ _SESSION變量。

例如,這個不起作用:

require __DIR__.'/../bootstrap/autoload.php';
$app = require_once __DIR__.'/../bootstrap/start.php';
$app->boot();
return Auth::check();

Auth :: check()工作的會話變量僅在$ app-> run()序列中初始化。 但在這種情況下,路由將會發生,並且您可能會得到無法識別的頁面...除非您使用專用的Laravel程序包。

這個 - 下面 - 仍然有效:

// Somewhere in your app - e.g. in filters.php, "auth"/"guest" filters declaration
if (session_id() == '') {
    @session_start();
    /* or Session:start(); */
}
$_SESSION['isLoggedIn'] = Auth::check() ? true : false;

那么在你的情況下,函數將很簡單:

function CheckAuthentication()
{
    if (session_id() == '') {
        @session_start();
    }
    return isset( $_SESSION['isLoggedIn'] ) && $_SESSION['isLoggedIn'] == true;
}

注意如果您可以使用Ajax調用進行授權檢查,您仍然可以使用JSON請求創建一個自定義API,以便用戶記錄(作為示例)以查看用戶是否已經過身份驗證。

回答你的第二個問題 - 聽起來並不那么簡單。 作為默認值,Laravel使用文件系統進行會話存儲。 雖然會話數據仍然可訪問,但它是加密的 - 除非您編寫自己的會話管理器,否則您無法輕松地從中提取任何內容。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM