/** * Authenticate to a protected file. * * @param File $file * @param Request $request * @param Store $session * @return \Illuminate\Http\RedirectResponse */ public function authenticate(File $file, Request $request, Store $session) { if (!$file->authenticate($request->input('password'))) { flash()->warning('Wrong password'); return redirect()->back(); } $session->flash('files_auth', true); return redirect()->route('files.show', $file->slug->slug); }
/** * Display the specified file. * * @param File $file * @return Response */ public function show(File $file) { if ($file->isProtected() && \Hash::check(app()->request->password, $file->password)) { return response()->download($file->path); } if (!$file->userHasAccess()) { return "Not authorized." . PHP_EOL; } return response()->download($file->path); }
public function run() { $faker = Faker\Factory::create(); $users = \DarkShare\Users\User::lists('id')->all(); foreach (range(1, 100) as $index) { $file = File::create(['user_id' => $faker->boolean() ? $faker->randomElement($users) : null, 'title' => $faker->sentence(), 'path' => '/home/vagrant/sites/darkshare/storage/app/testfile.md', 'password' => $faker->boolean() ? 'secret' : null]); FileSlug::create(['file_id' => $file->id, 'slug' => $file]); } }
/** * Handle the command. * * @param StoreNewFileCommand $command * @return void */ public function handle(StoreNewFileCommand $command) { $command->path = $this->handleUploadedFile($command->file); if (empty($command->title)) { $command->title = htmlentities($command->file->getClientOriginalName()); } $file = File::create(['user_id' => $this->auth->user() ? $this->auth->user()->id : null, 'title' => $command->title, 'path' => $command->path, 'password' => $command->password]); FileSlug::create(['file_id' => $file->id, 'slug' => $file]); return $file; }