ldc-tousenselle/app/Providers/AuthServiceProvider.php

45 lines
1.3 KiB
PHP
Raw Permalink Normal View History

2021-06-09 11:43:25 +02:00
<?php
namespace App\Providers;
2021-07-05 16:34:50 +02:00
use App\Mail\UserEmailReset;
2021-06-09 11:43:25 +02:00
use App\Mail\UserEmailVerify;
use App\Models\Participation;
use App\Models\User;
use Illuminate\Auth\Notifications\VerifyEmail;
2021-07-05 16:34:50 +02:00
use Illuminate\Auth\Notifications\ResetPassword;
2021-06-09 11:43:25 +02:00
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);
});
2021-07-05 16:34:50 +02:00
ResetPassword::toMailUsing(function ($notifiable, $url) {
return new UserEmailReset($notifiable, $url);
});
2021-06-09 11:43:25 +02:00
Gate::define('participate', function (User $user) {
return
2021-07-05 18:26:37 +02:00
!is_null(app('clientIp'))
2021-06-09 11:43:25 +02:00
and !$user->participations()
->whereDate('updated_at', Carbon::now()->toDateString())
->count()
2021-07-05 18:26:37 +02:00
and Participation::where('ip', app('clientIp'))
2021-06-09 11:43:25 +02:00
->whereDate('updated_at', '=', Carbon::now()->toDateString())
->count() <= 3;
});
}
}