yaroslawww/laravel-restricted-access

This package is abandoned and no longer maintained. The author suggests using the think.studio/laravel-restricted-access package instead.

Restrict access to any entities or pages, or create share links.

1.2.0 2023-07-18 12:46 UTC

This package is auto-updated.

Last update: 2023-07-18 12:47:15 UTC


README

Packagist License Packagist Version Total Downloads Build Status Code Coverage Scrutinizer Code Quality

Restrict access for pages, with pin code, email or name.

Installation

Install the package via composer:

composer require think.studio/laravel-restricted-access

Optionally you can publish the config file with:

php artisan vendor:publish --provider="LinkRestrictedAccess\ServiceProvider" --tag="config"

If you want change tables names or routes, you can do it via config file.

Run migrations:

php artisan migrate

Usage

Use trait HasRestrictedLink for model

class File extends Model 
{
    use \LinkRestrictedAccess\Models\HasRestrictedLink;
}

Then you can create link

/** @var RestrictedLink $shareLink */
$shareLink = $file->restrictedLinks()->make([
    'name'         => $request->input('name'),
    'pin'          => $request->input('pin'),
    'check_pin'    => $request->boolean('check_pin'),
    'check_name'   => $request->boolean('check_name'),
    'check_email'  => $request->boolean('check_email'),
]);

if ($user = $request->user()) {
    $shareLink->meta->toMorph('creator', $user);
}

$shareLink->save();

Example check verification.

if($shareUuid = $request->string('share')) {

    $sharedLink = \LinkRestrictedAccess\RestrictedAccess::restrictedLinkModel()::query()->byKey($shareUuid)->firstOrFail();

    if ($sharedLink->needVerification() && !$sharedLink->verifiedOpenActionFromCookie($request)) {
        return // display verification view
    }

    return $sharedLink->linkable;
}

To verify access you can use routes restricted-access-link.check-pin and restricted-access-link.open-document

Credits

  • Think Studio