primo upload
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace Vanguard\Providers;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Vanguard\Repositories\Country\CountryRepository;
|
||||
use Vanguard\Repositories\Country\EloquentCountry;
|
||||
use Vanguard\Repositories\Permission\EloquentPermission;
|
||||
use Vanguard\Repositories\Permission\PermissionRepository;
|
||||
use Vanguard\Repositories\Role\EloquentRole;
|
||||
use Vanguard\Repositories\Role\RoleRepository;
|
||||
use Vanguard\Repositories\Session\DbSession;
|
||||
use Vanguard\Repositories\Session\SessionRepository;
|
||||
use Vanguard\Repositories\User\EloquentUser;
|
||||
use Vanguard\Repositories\User\UserRepository;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
Carbon::setLocale(config('app.locale'));
|
||||
config(['app.name' => setting('app_name')]);
|
||||
\Illuminate\Database\Schema\Builder::defaultStringLength(191);
|
||||
|
||||
Factory::guessFactoryNamesUsing(function (string $modelName) {
|
||||
return 'Database\Factories\\'.class_basename($modelName).'Factory';
|
||||
});
|
||||
|
||||
\Illuminate\Pagination\Paginator::useBootstrap();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->app->singleton(UserRepository::class, EloquentUser::class);
|
||||
$this->app->singleton(RoleRepository::class, EloquentRole::class);
|
||||
$this->app->singleton(PermissionRepository::class, EloquentPermission::class);
|
||||
$this->app->singleton(SessionRepository::class, DbSession::class);
|
||||
$this->app->singleton(CountryRepository::class, EloquentCountry::class);
|
||||
|
||||
if ($this->app->environment('local')) {
|
||||
$this->app->register(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class);
|
||||
$this->app->register(\Barryvdh\Debugbar\ServiceProvider::class);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Vanguard\Providers;
|
||||
|
||||
use Illuminate\Contracts\Auth\Access\Gate as GateContract;
|
||||
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
|
||||
use Vanguard\User;
|
||||
|
||||
class AuthServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* The policy mappings for the application.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $policies = [
|
||||
'Vanguard\Model' => 'Vanguard\Policies\ModelPolicy',
|
||||
];
|
||||
|
||||
/**
|
||||
* Register any application authentication / authorization services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
\Blade::directive('role', function ($expression) {
|
||||
return "<?php if (\\Auth::user()->hasRole({$expression})) : ?>";
|
||||
});
|
||||
|
||||
\Blade::directive('endrole', function ($expression) {
|
||||
return "<?php endif; ?>";
|
||||
});
|
||||
|
||||
\Blade::directive('permission', function ($expression) {
|
||||
return "<?php if (\\Auth::user()->hasPermission({$expression})) : ?>";
|
||||
});
|
||||
|
||||
\Blade::directive('endpermission', function ($expression) {
|
||||
return "<?php endif; ?>";
|
||||
});
|
||||
|
||||
\Gate::define('manage-session', function (User $user, $session) {
|
||||
if ($user->hasPermission('users.manage')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return (int) $user->id === (int) $session->user_id;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace Vanguard\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Illuminate\Support\Facades\Broadcast;
|
||||
|
||||
class BroadcastServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
Broadcast::routes();
|
||||
|
||||
/*
|
||||
* Authenticate the user's personal channel...
|
||||
*/
|
||||
Broadcast::channel('Vanguard.User.*', function ($user, $userId) {
|
||||
return (int) $user->id === (int) $userId;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace Vanguard\Providers;
|
||||
|
||||
use Illuminate\Auth\Events\Registered;
|
||||
use Illuminate\Auth\Events\Verified;
|
||||
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
|
||||
use Vanguard\Events\User\Banned;
|
||||
use Vanguard\Events\User\LoggedIn;
|
||||
use Vanguard\Listeners\Users\ActivateUser;
|
||||
use Vanguard\Listeners\Users\InvalidateSessions;
|
||||
use Vanguard\Listeners\Login\UpdateLastLoginTimestamp;
|
||||
use Vanguard\Listeners\Registration\SendSignUpNotification;
|
||||
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
||||
|
||||
class EventServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* The event listener mappings for the application.
|
||||
*
|
||||
* @var array<class-string, array<int, class-string>>
|
||||
*/
|
||||
protected $listen = [
|
||||
Registered::class => [
|
||||
SendEmailVerificationNotification::class,
|
||||
SendSignUpNotification::class,
|
||||
],
|
||||
LoggedIn::class => [
|
||||
UpdateLastLoginTimestamp::class
|
||||
],
|
||||
Banned::class => [
|
||||
InvalidateSessions::class
|
||||
],
|
||||
Verified::class => [
|
||||
ActivateUser::class
|
||||
]
|
||||
];
|
||||
|
||||
/**
|
||||
* Register any events for your application.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if events and listeners should be automatically discovered.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function shouldDiscoverEvents()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Vanguard\Providers;
|
||||
|
||||
use Collective\Html\FormBuilder;
|
||||
use Collective\Html\HtmlBuilder;
|
||||
use Collective\Html\HtmlServiceProvider as BaseHtmlServiceProvider;
|
||||
|
||||
class HtmlServiceProvider extends BaseHtmlServiceProvider
|
||||
{
|
||||
protected function registerHtmlBuilder()
|
||||
{
|
||||
$this->app->singleton('html', function ($app) {
|
||||
if (env('FORCE_SSL')) {
|
||||
$app['url']->forceScheme('https');
|
||||
}
|
||||
|
||||
return new HtmlBuilder($app['url'], $app['view']);
|
||||
});
|
||||
}
|
||||
|
||||
protected function registerFormBuilder()
|
||||
{
|
||||
$this->app->singleton('form', function ($app) {
|
||||
if (env('FORCE_SSL')) {
|
||||
$app['url']->forceScheme('https');
|
||||
}
|
||||
|
||||
$form = new FormBuilder($app['html'], $app['url'], $app['view'], $app['session.store']->token());
|
||||
|
||||
return $form->setSessionStore($app['session.store']);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
|
||||
namespace Vanguard\Providers;
|
||||
|
||||
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
|
||||
use Route;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Vanguard\Repositories\Role\RoleRepository;
|
||||
use Vanguard\Repositories\Session\SessionRepository;
|
||||
use Vanguard\Repositories\User\UserRepository;
|
||||
|
||||
class RouteServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* The path to the "home" route for your application.
|
||||
*
|
||||
* This is used by Laravel authentication to redirect users after login.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public const HOME = '/';
|
||||
|
||||
/**
|
||||
* This namespace is applied to the controller routes in your web routes file.
|
||||
* In addition, it is set as the URL generator's root namespace.
|
||||
* @var string
|
||||
*/
|
||||
protected $webNamespace = 'Vanguard\Http\Controllers\Web';
|
||||
|
||||
/**
|
||||
* This namespace is applied to the controller routes in your api routes file.
|
||||
* @var string
|
||||
*/
|
||||
protected $apiNamespace = 'Vanguard\Http\Controllers\Api';
|
||||
|
||||
/**
|
||||
* Define your route model bindings, pattern filters, etc.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
$this->bindUser();
|
||||
$this->bindRole();
|
||||
$this->bindSession();
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the routes for the application.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function map()
|
||||
{
|
||||
if ($this->app['config']->get('auth.expose_api')) {
|
||||
$this->mapApiRoutes();
|
||||
}
|
||||
|
||||
$this->mapWebRoutes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the "web" routes for the application.
|
||||
*
|
||||
* These routes all receive session state, CSRF protection, etc.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function mapWebRoutes()
|
||||
{
|
||||
Route::group([
|
||||
'namespace' => $this->webNamespace,
|
||||
'middleware' => 'web',
|
||||
], function ($router) {
|
||||
require base_path('routes/web.php');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the "api" routes for the application.
|
||||
*
|
||||
* These routes are typically stateless.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function mapApiRoutes()
|
||||
{
|
||||
Route::group([
|
||||
'middleware' => 'api',
|
||||
'namespace' => $this->apiNamespace,
|
||||
'prefix' => 'api',
|
||||
], function () {
|
||||
require base_path('routes/api.php');
|
||||
});
|
||||
}
|
||||
|
||||
private function bindUser()
|
||||
{
|
||||
$this->bindUsingRepository('user', UserRepository::class);
|
||||
}
|
||||
|
||||
private function bindRole()
|
||||
{
|
||||
$this->bindUsingRepository('role', RoleRepository::class);
|
||||
}
|
||||
|
||||
private function bindSession()
|
||||
{
|
||||
$this->bindUsingRepository('session', SessionRepository::class);
|
||||
}
|
||||
|
||||
private function bindUsingRepository($entity, $repository, $method = 'find')
|
||||
{
|
||||
Route::bind($entity, function ($id) use ($repository, $method) {
|
||||
if ($object = app($repository)->$method($id)) {
|
||||
return $object;
|
||||
}
|
||||
|
||||
throw new NotFoundHttpException("Resource not found.");
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace Vanguard\Providers;
|
||||
|
||||
use Vanguard\Plugins\VanguardServiceProvider as BaseVanguardServiceProvider;
|
||||
use Vanguard\Support\Plugins\Dashboard\Widgets\BannedUsers;
|
||||
use Vanguard\Support\Plugins\Dashboard\Widgets\LatestRegistrations;
|
||||
use Vanguard\Support\Plugins\Dashboard\Widgets\NewUsers;
|
||||
use Vanguard\Support\Plugins\Dashboard\Widgets\RegistrationHistory;
|
||||
use Vanguard\Support\Plugins\Dashboard\Widgets\TotalUsers;
|
||||
use Vanguard\Support\Plugins\Dashboard\Widgets\UnconfirmedUsers;
|
||||
use Vanguard\Support\Plugins\Dashboard\Widgets\UserActions;
|
||||
use \Vanguard\UserActivity\Widgets\ActivityWidget;
|
||||
|
||||
class VanguardServiceProvider extends BaseVanguardServiceProvider
|
||||
{
|
||||
/**
|
||||
* List of registered plugins.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function plugins()
|
||||
{
|
||||
return [
|
||||
\Vanguard\Support\Plugins\Dashboard\Dashboard::class,
|
||||
\Vanguard\Support\Plugins\Users::class,
|
||||
\Vanguard\UserActivity\UserActivity::class,
|
||||
\Vanguard\Support\Plugins\RolesAndPermissions::class,
|
||||
\Vanguard\Support\Plugins\Settings::class,
|
||||
\Vanguard\Announcements\Announcements::class,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Dashboard widgets.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function widgets()
|
||||
{
|
||||
return [
|
||||
UserActions::class,
|
||||
TotalUsers::class,
|
||||
NewUsers::class,
|
||||
BannedUsers::class,
|
||||
UnconfirmedUsers::class,
|
||||
RegistrationHistory::class,
|
||||
LatestRegistrations::class,
|
||||
ActivityWidget::class,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user