ldc-tousenselle/app/Providers/AuthServiceProvider.php
Jérémy Munsch f7a3f5d5f9 first draw
2021-06-14 09:34:42 +02:00

40 lines
1.2 KiB
PHP

<?php
namespace App\Providers;
use App\Mail\UserEmailVerify;
use App\Models\Participation;
use App\Models\User;
use Illuminate\Auth\Notifications\VerifyEmail;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Gate;
class AuthServiceProvider extends ServiceProvider
{
/**
* Register any authentication / authorization services.
*
* @return void
*/
public function boot()
{
$this->registerPolicies();
VerifyEmail::toMailUsing(function ($notifiable, $url) {
return new UserEmailVerify($notifiable, $url);
});
Gate::define('participate', function (User $user) {
return true;
return
!is_null(request()->getClientIp())
and !$user->participations()
->whereDate('updated_at', Carbon::now()->toDateString())
->count()
and Participation::where('ip', request()->getClientIp())
->whereDate('updated_at', '=', Carbon::now()->toDateString())
->count() <= 3;
});
}
}