Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Listeners;
- use Cartalyst\Sentinel\Sentinel as Sentinel;
- use App\Services\ActionlogService;
- use Illuminate\Mail\Mailer;
- use App;
- class Handler
- {
- /**
- * Sentinel Instance
- * @var int
- */
- protected $sentinel;
- /**
- * Actionlog Service Instance
- * @var
- */
- protected $log;
- /**
- * Illuminate\Mail\Mailer Instance
- * @var
- */
- protected $mail;
- public function __construct()
- {
- $this->sentinel = App::make(Sentinel::class);
- $this->log = App::make(ActionlogService::class);
- $this->mail = App::make(Mailer::class);
- }
- protected function compileDetails($event)
- {
- $details['note'] = $event->note;
- if (empty(array_filter($event->entities))) {
- $details['entities'] = [
- 'actual' => null,
- 'before' => null,
- 'related' => null,
- ];
- } else {
- $details['entities'] = $event->entities;
- }
- return json_encode($details);
- }
- public function prepareSpamFilter($event)
- {
- $entity = new \stdClass();
- if (! empty($event->entities['actual'])) {
- $entity = json_decode($event->entities['actual']);
- } else {
- $entity->id = null;
- }
- return $entity;
- }
- protected function createSpamFilter($event)
- {
- $entity = $this->prepareSpamFilter($event);
- $logId = is_array($entity) ? json_encode($entity) : $entity->id;
- session(["log.{$event->name}.{$logId}" => \Carbon\Carbon::now()]);
- }
- protected function checkSpamFilter($event)
- {
- $entity = $this->prepareSpamFilter($event);
- $logId = is_array($entity) ? json_encode($entity) : $entity->id;
- $logInSession = session("log.{$event->name}.{$logId}");
- if (is_null($logInSession) || $logInSession <= \Carbon\Carbon::now()->subMinutes(1)) {
- \Session::forget("log.{$event->name}.{$logId}");
- return true;
- }
- return false;
- }
- }
Add Comment
Please, Sign In to add comment