【问题标题】:Allow front-end User to access protected files允许前端用户访问受保护的文件
【发布时间】:2017-10-26 06:02:18
【问题描述】:

我希望能够允许某些前端用户访问受保护的文件。前端用户使用https://github.com/rainlab/user-plugin

目前我只能看到有 2 个选项。公共和受保护。 Public 太不安全了,任何人都可以查看,而 Protected 仅对后端用户可用。

有什么方法可以在插件中使用 routes.php 对某个目录进行身份验证,或者在受保护文件上使用用户身份验证的解决方案?

这是我的 route.php 的示例,但不知道如何扩展到 auth。

$cmsStorage = AppConfig::get('cms.storage.uploads.path', '/storage/app/uploads');
$uploadsPath = $cmsStorage. '/privatefiles/{dir1}/{dir2}/{dir3}/{disk_name}';


Routes::get($uploadsPath, function ($dir1, $dir2, $dir3) {

// some login in here to return file


});

【问题讨论】:

    标签: php laravel octobercms


    【解决方案1】:

    根据插件的documentation,您可以通过应用Auth中间件来限制对某些路由的访问:

    Route::group(['middleware' => 'RainLab\User\Classes\AuthMiddleware'], function () {
        // All routes here will require authentication
    });
    

    因此,您可以通过将它们放在上面的路由组中来轻松保护那些返回文件响应的路由。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-19
      • 2018-08-03
      • 2019-04-28
      • 2021-06-02
      • 1970-01-01
      相关资源
      最近更新 更多