blue-twilight/app/Providers/AuthServiceProvider.php

51 lines
1.1 KiB
PHP

<?php
namespace App\Providers;
use App\Album;
use App\Facade\UserConfig;
use App\Photo;
use App\Policies\AlbumPolicy;
use Illuminate\Support\Facades\Gate;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
class AuthServiceProvider extends ServiceProvider
{
/**
* The policy mappings for the application.
*
* @var array
*/
protected $policies = [
Album::class => AlbumPolicy::class
];
/**
* Register any authentication / authorization services.
*
* @return void
*/
public function boot()
{
$this->registerPolicies();
Gate::define('admin-access', function ($user)
{
return $user->is_admin;
});
Gate::define('admin-create-albums', function ($user)
{
return $user->can_create_albums;
});
Gate::define('photo.download_original', function ($user, Photo $photo)
{
if (!UserConfig::get('restrict_original_download'))
{
return true;
}
return ($user->id == $photo->user_id);
});
}
}