From baddf858d2bd17dcaf93532493975d95c00e3f80 Mon Sep 17 00:00:00 2001 From: kevin olson Date: Fri, 31 Aug 2018 08:48:21 -0500 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20sessions=20support?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 3 ++- src/Guards/HumbleGuard.php | 3 ++- src/Models/Session.php | 16 ++++++++++++++++ src/Traits/Humble.php | 2 +- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index c991a2b..c35b72d 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,8 @@ ], "require": { "illuminate/support": "5.1.* || 5.2.* || 5.3.* || 5.4.* || 5.5.* || 5.6.*", - "php": "~7.0" + "php": "~7.0", + "jenssegers/agent": "^2.6" }, "autoload": { "psr-4": { diff --git a/src/Guards/HumbleGuard.php b/src/Guards/HumbleGuard.php index c505260..5a1afbf 100644 --- a/src/Guards/HumbleGuard.php +++ b/src/Guards/HumbleGuard.php @@ -3,7 +3,8 @@ namespace acidjazz\Humble\Guards; use Illuminate\Contracts\Auth\Guard; -use Illuminate\Foundation\Auth\User; +// use Illuminate\Foundation\Auth\User; +use App\Models\User; use Illuminate\Contracts\Auth\Authenticatable; use acidjazz\Humble\Models\Session; diff --git a/src/Models/Session.php b/src/Models/Session.php index 85df628..f809a1a 100644 --- a/src/Models/Session.php +++ b/src/Models/Session.php @@ -4,17 +4,33 @@ use Illuminate\Database\Eloquent\Model; +use Jenssegers\Agent\Agent; + class Session extends Model { protected $fillable = ['token','user_id','source','cookie','verified', 'to', 'ip','agent']; protected $primaryKey = 'token'; public $incrementing = false; + public $appends = ['device']; public static function hash() { return hash('sha256', mt_rand()); } + public function getDeviceAttribute () + { + $agent = new Agent(); + $agent->setUserAgent($this->agent); + return [ + 'platform' => $agent->platform(), + 'browser' => $agent->browser(), + 'device' => $agent->device(), + 'desktop' => $agent->isDesktop(), + 'mobile' => $agent->isMobile(), + ]; + } + } diff --git a/src/Traits/Humble.php b/src/Traits/Humble.php index 04fd237..c265d70 100644 --- a/src/Traits/Humble.php +++ b/src/Traits/Humble.php @@ -16,7 +16,7 @@ public function getSession() public function sessions() { - return $this->HasMany(Session::class); + return $this->hasMany(Session::class); } }