Laravel 5.6 ckfinder 集成
Laravel 5.6 ckfinder integration
我想将 ckfinder 与我的 laravel 集成,但我受困于身份验证。
我找到了很多方法,但有一些方法适用于旧的 laravel 版本,none 适用于 5.6。
我找到了这个:
require '../../vendor/autoload.php';
$app = require_once '../../bootstrap/app.php';
$app->make('Illuminate\Contracts\Http\Kernel')
->handle(Illuminate\Http\Request::capture());
但是当我将它放入 config.php
时,我收到来自 Ckfinder 的无效请求
我想在身份验证中访问 Auth::check() 和 return 它
require __DIR__ . '/../../vendor/autoload.php';
$app = require_once __DIR__ . '/../../bootstrap/app.php';
$request = Illuminate\Http\Request::capture();
$request->setMethod('GET');
$app->make('Illuminate\Contracts\Http\Kernel')
->handle($request);
$config['authentication'] = function () {
return auth()->check();
};
编辑
所以我看了一下 index.php 并将其复制到 config.php:
define('LARAVEL_START', microtime(true));
require '/Applications/MAMP/htdocs/laravel-dealer/vendor/autoload.php';
$app = require_once '/Applications/MAMP/htdocs/laravel-dealer/bootstrap/app.php';
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
$response = $kernel->handle(
$request = Illuminate\Http\Request::capture()
);
但是我收到 $acl 参数的运行时异常。
Fatal error: Uncaught RuntimeException: Controller
"CKSource\CKFinder\Command\Init::execute()" requires that you provide
a value for the "$acl" argument. Either the argument is nullable and
no null value has been provided, no default value has been provided or
because there is a non optional argument after this one. in
/Applications/MAMP/htdocs/laravel-dealer/vendor/symfony/http-kernel/Controller/ArgumentResolver.php:78
Stack trace: #0
/Applications/MAMP/htdocs/laravel-dealer/vendor/symfony/http-kernel/HttpKernel.php(141):
Symfony\Component\HttpKernel\Controller\ArgumentResolver->getArguments(Object(Symfony\Component\HttpFoundation\Request),
Array) #1
/Applications/MAMP/htdocs/laravel-dealer/vendor/symfony/http-kernel/HttpKernel.php(66):
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request),
1) #2
/Applications/MAMP/htdocs/laravel-dealer/public/ckfinder/core/connector/php/vendor/cksource/ckfinder/src/CKSource/CKFinder/CKFinder.php(610):
Symfony\Component\HttpKernel\HttpKernel- in
/Applications/MAMP/htdocs/laravel-dealer/vendor/symfony/http-kernel/Controller/ArgumentResolver.php
on line 78
感谢您的帮助
这是我的一个项目中的身份验证部分的样子
/*============================ Enable PHP Connector HERE ==============================*/
// http://docs.cksource.com/ckfinder3-php/configuration.html#configuration_options_authentication
require __DIR__ . '/../../vendor/autoload.php';
$app = require_once __DIR__ . '/../../bootstrap/app.php';
$request = Illuminate\Http\Request::capture();
$request->setMethod('GET');
$app->make('Illuminate\Contracts\Http\Kernel')
->handle($request);
$config['authentication'] = function () {
return auth()->check();
};
好吧,我花了一些时间想出了这个解决方案:
此函数获取 $_COOKIE['allowCkfinder']
的值并使用密码和您的应用程序密钥对其进行解密。
// /public/ckfinder/config.php
$config['authentication'] = function () {
$APP_KEY = "YOUR_APP_KEY";
$cookie_contents = json_decode( base64_decode( $_COOKIE['allowCkfinder'], true ));
$value = base64_decode( $cookie_contents->value );
$iv = base64_decode( $cookie_contents->iv );
return unserialize( openssl_decrypt($value, "AES-256-CBC", base64_decode($APP_KEY), OPENSSL_RAW_DATA, $iv));
};
登录用户/管理员时设置名为 allowCkfinder 的 cookie:
也不要忘记在用户注销时删除 cookie。
// /app/Http/Controllers/LoginController.php
if (Auth::attempt(['user_email' => $validatedData['email'], 'password' => $validatedData['password'], "user_active" => 1, "user_banned" => 0]))
{
if (Auth::user()->user_admin == TRUE)
return redirect()->intended('/')->withCookie(cookie()->forever('allowCkfinder', "1"));
else
return redirect()->intended('/');
} else
{
$request->session()->flash('error', __("E-mail and/or password do not match"));
return redirect('login')->withInput();
}
这是我想出的最好的办法。
我想将 ckfinder 与我的 laravel 集成,但我受困于身份验证。
我找到了很多方法,但有一些方法适用于旧的 laravel 版本,none 适用于 5.6。
我找到了这个:
require '../../vendor/autoload.php';
$app = require_once '../../bootstrap/app.php';
$app->make('Illuminate\Contracts\Http\Kernel')
->handle(Illuminate\Http\Request::capture());
但是当我将它放入 config.php
时,我收到来自 Ckfinder 的无效请求我想在身份验证中访问 Auth::check() 和 return 它
require __DIR__ . '/../../vendor/autoload.php';
$app = require_once __DIR__ . '/../../bootstrap/app.php';
$request = Illuminate\Http\Request::capture();
$request->setMethod('GET');
$app->make('Illuminate\Contracts\Http\Kernel')
->handle($request);
$config['authentication'] = function () {
return auth()->check();
};
编辑
所以我看了一下 index.php 并将其复制到 config.php:
define('LARAVEL_START', microtime(true));
require '/Applications/MAMP/htdocs/laravel-dealer/vendor/autoload.php';
$app = require_once '/Applications/MAMP/htdocs/laravel-dealer/bootstrap/app.php';
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
$response = $kernel->handle(
$request = Illuminate\Http\Request::capture()
);
但是我收到 $acl 参数的运行时异常。
Fatal error: Uncaught RuntimeException: Controller "CKSource\CKFinder\Command\Init::execute()" requires that you provide a value for the "$acl" argument. Either the argument is nullable and no null value has been provided, no default value has been provided or because there is a non optional argument after this one. in /Applications/MAMP/htdocs/laravel-dealer/vendor/symfony/http-kernel/Controller/ArgumentResolver.php:78 Stack trace: #0 /Applications/MAMP/htdocs/laravel-dealer/vendor/symfony/http-kernel/HttpKernel.php(141): Symfony\Component\HttpKernel\Controller\ArgumentResolver->getArguments(Object(Symfony\Component\HttpFoundation\Request), Array) #1 /Applications/MAMP/htdocs/laravel-dealer/vendor/symfony/http-kernel/HttpKernel.php(66): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1) #2 /Applications/MAMP/htdocs/laravel-dealer/public/ckfinder/core/connector/php/vendor/cksource/ckfinder/src/CKSource/CKFinder/CKFinder.php(610): Symfony\Component\HttpKernel\HttpKernel- in /Applications/MAMP/htdocs/laravel-dealer/vendor/symfony/http-kernel/Controller/ArgumentResolver.php on line 78
感谢您的帮助
这是我的一个项目中的身份验证部分的样子
/*============================ Enable PHP Connector HERE ==============================*/
// http://docs.cksource.com/ckfinder3-php/configuration.html#configuration_options_authentication
require __DIR__ . '/../../vendor/autoload.php';
$app = require_once __DIR__ . '/../../bootstrap/app.php';
$request = Illuminate\Http\Request::capture();
$request->setMethod('GET');
$app->make('Illuminate\Contracts\Http\Kernel')
->handle($request);
$config['authentication'] = function () {
return auth()->check();
};
好吧,我花了一些时间想出了这个解决方案:
此函数获取 $_COOKIE['allowCkfinder']
的值并使用密码和您的应用程序密钥对其进行解密。
// /public/ckfinder/config.php
$config['authentication'] = function () {
$APP_KEY = "YOUR_APP_KEY";
$cookie_contents = json_decode( base64_decode( $_COOKIE['allowCkfinder'], true ));
$value = base64_decode( $cookie_contents->value );
$iv = base64_decode( $cookie_contents->iv );
return unserialize( openssl_decrypt($value, "AES-256-CBC", base64_decode($APP_KEY), OPENSSL_RAW_DATA, $iv));
};
登录用户/管理员时设置名为 allowCkfinder 的 cookie: 也不要忘记在用户注销时删除 cookie。
// /app/Http/Controllers/LoginController.php
if (Auth::attempt(['user_email' => $validatedData['email'], 'password' => $validatedData['password'], "user_active" => 1, "user_banned" => 0]))
{
if (Auth::user()->user_admin == TRUE)
return redirect()->intended('/')->withCookie(cookie()->forever('allowCkfinder', "1"));
else
return redirect()->intended('/');
} else
{
$request->session()->flash('error', __("E-mail and/or password do not match"));
return redirect('login')->withInput();
}
这是我想出的最好的办法。