41 lines
1.2 KiB
PHP
41 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;
|
||
|
|
});
|
||
|
|
}
|
||
|
|
}
|