允许前端用户访问受保护的文件
Allow front-end User to access protected files
我希望能够允许某些前端用户访问受保护的文件。前端用户正在使用 https://github.com/rainlab/user-plugin
目前我只能看到2个选项。 Public 并受保护。 Public 太不安全,任何人都可以查看,Protected 仅供后端用户使用。
有什么方法可以在插件中使用 routes.php 对某个目录进行身份验证,或者对受保护文件使用用户身份验证的解决方案?
这是我的示例 route.php 但不确定如何扩展到身份验证。
$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
});
根据插件的documentation,您可以通过应用 Auth 中间件来限制对某些路由的访问:
Route::group(['middleware' => 'RainLab\User\Classes\AuthMiddleware'], function () {
// All routes here will require authentication
});
因此,您可以轻松保护那些 return 文件响应的路由,方法是将它们放在上面的路由组中。
我希望能够允许某些前端用户访问受保护的文件。前端用户正在使用 https://github.com/rainlab/user-plugin
目前我只能看到2个选项。 Public 并受保护。 Public 太不安全,任何人都可以查看,Protected 仅供后端用户使用。
有什么方法可以在插件中使用 routes.php 对某个目录进行身份验证,或者对受保护文件使用用户身份验证的解决方案?
这是我的示例 route.php 但不确定如何扩展到身份验证。
$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
});
根据插件的documentation,您可以通过应用 Auth 中间件来限制对某些路由的访问:
Route::group(['middleware' => 'RainLab\User\Classes\AuthMiddleware'], function () {
// All routes here will require authentication
});
因此,您可以轻松保护那些 return 文件响应的路由,方法是将它们放在上面的路由组中。