首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >laravel 5的CKFinder认证问题

laravel 5的CKFinder认证问题
EN

Stack Overflow用户
提问于 2015-06-05 11:40:06
回答 3查看 3.5K关注 0票数 2

我使用的是Laravel 5,我在/public/plugins/ckfinder目录中有引用ckfinder的文件夹。

CheckAuthentication函数在config.php中是我需要使用的,但是会话值和Auth是空的。

我试过了

代码语言:javascript
复制
function CheckAuthentication(){
    return Auth::check();
}

代码语言:javascript
复制
 //Ckfinder Config.php
function CheckAuthentication(){
        if($_SESSION['ckfinder_enabled'] == 'enabled') {
            return true;
        } else {
            return false;
        }
    }
代码语言:javascript
复制
        //App\Http\Middleware\Authenticate.php
    public function handle($request, Closure $next)
            {
                if ($this->auth->guest()){
                        if ($request->ajax()){
                            return response('Unauthorized.', 401);
                        }else{
                            return redirect()->guest('auth/login');
                        }
                    }

                if($this->auth->check()) {
                     $_SESSION['ckfinder_enabled'] = 'enabled';
                    return $next($request);
                }
            }
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2015-06-05 11:43:53

我也有同样的问题。对于Laravel4.2,您的代码很有用,但对于laravel 5,您需要在ckfinder文件夹的config.php中这样做:

代码语言:javascript
复制
require _DIR_.'/../../../bootstrap/autoload.php';
$app = require_once _DIR_.'/../../../bootstrap/app.php';

$app->make('Illuminate\Contracts\Http\Kernel')
  ->handle(Illuminate\Http\Request::capture());

那么,您就可以使用以下代码:

代码语言:javascript
复制
function CheckAuthentication(){
    return Auth::check();
}

这应该能行。

票数 5
EN

Stack Overflow用户

发布于 2019-01-27 02:22:48

Laravel 5.7+:

代码语言:javascript
复制
require  $_SERVER['DOCUMENT_ROOT'] . '/../vendor/autoload.php';
$app = require_once  $_SERVER['DOCUMENT_ROOT']. '/../bootstrap/app.php';
$response = $app->make('Illuminate\Contracts\Http\Kernel')->handle(Illuminate\Http\Request::capture());
$cookie = $_COOKIE[$app['config']['session']['cookie']] ?? false;
if ($cookie) {
    $id = $app['encrypter']->decrypt($cookie, false);
    $session = $app['session']->driver();
    $session->setId($id);
    $session->start();
}

if (!$app['auth']->check()){
    header('HTTP/1.0 403 Forbidden'); exit();
}
票数 0
EN

Stack Overflow用户

发布于 2021-11-13 13:37:39

CKFinder 3 for PHP

Laravel v7.30.4

为我工作

代码语言:javascript
复制
use Illuminate\Support\Facades\Auth;

$config['authentication'] = function () {
  require $_SERVER['DOCUMENT_ROOT'] . '/vendor/autoload.php';
  $app = require_once  $_SERVER['DOCUMENT_ROOT']. '/bootstrap/app.php';
  $request = Illuminate\Http\Request::capture();
  $request->setMethod('GET');
  $app->make('Illuminate\Contracts\Http\Kernel')->handle($request);
  if (Auth::check() && Auth::user()->is_admin ) {
    return true;
  } else {
    header('HTTP/1.0 403 Forbidden');
    exit();
  }
};
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30665618

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档