From c7084415f04d5a440f9b161012b7b672829086a6 Mon Sep 17 00:00:00 2001 From: Aldarien Date: Tue, 18 Feb 2020 12:14:16 -0300 Subject: [PATCH] Auth global --- src/common/Auth.php | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/common/Auth.php b/src/common/Auth.php index c28ea77..ec87f8d 100644 --- a/src/common/Auth.php +++ b/src/common/Auth.php @@ -32,11 +32,16 @@ class Auth extends Model } public function time($time = null) { + if ($this->container === null) { + $timezone = config('app.timezone'); + } else { + $timezone = $this->container->get('settings')->app->timezone; + } if ($time == null) { - return Carbon::parse($this->time, $this->container->get('settings')->app->timezone); + return Carbon::parse($this->time, $timezone); } if (!\is_a($time, \DateTime::class)) { - $time = Carbon::parse($time, $this->container->get('settings')->app->timezone); + $time = Carbon::parse($time, $timezone); } $this->time = $time; } @@ -52,9 +57,19 @@ class Auth extends Model if ($this->status == 0) { return false; } - $now = Carbon::now($this->container->get('settings')->app->timezone); + if ($this->container === null) { + $timezone = config('app.timezone'); + } else { + $timezone = $this->container->get('settings')->app->timezone; + } + $now = Carbon::now($timezone); $diff = $now->diffAsCarbonInterval($this->time, true); - if ($diff->totalHours > $this->container->get('settings')->app->login->hours) { + if ($this->container === null) { + $total_hours = config('app.login.hours'); + } else { + $total_hours = $this->container->get('settings')->app->login->hours; + } + if ($diff->totalHours > $total_hours) { return false; } return true;