Skip to content

Commit

Permalink
fix guest user cannot shorten the link (#931)
Browse files Browse the repository at this point in the history
  • Loading branch information
realodix authored Nov 14, 2023
1 parent 69de070 commit a2266c0
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
14 changes: 14 additions & 0 deletions app/Helpers/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@

class Helper
{
/**
* Parse any User Agent
*
* @return \DeviceDetector\DeviceDetector
*/
public static function deviceDetector()
{
$dd = new \DeviceDetector\DeviceDetector(request()->userAgent());
$dd->setCache(new \DeviceDetector\Cache\LaravelCache);
$dd->parse();

return $dd;
}

/**
* Display the link according to what You need.
*
Expand Down
10 changes: 7 additions & 3 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Models;

// use Illuminate\Contracts\Auth\MustVerifyEmail;
use App\Helpers\Helper;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Foundation\Auth\User as Authenticatable;
Expand Down Expand Up @@ -84,11 +85,14 @@ public function totalGuestUsers(): int
public function signature(): string
{
if (auth()->check() === false) {
$dd = Helper::deviceDetector();

return hash('sha3-256', implode([
'ip' => request()->ip(),
'browser' => \Browser::browserFamily(),
'os' => \Browser::platformFamily(),
'device' => \Browser::deviceFamily().\Browser::deviceModel(),
'browser' => $dd->getClient('name'),
'os' => $dd->getOs('name').$dd->getOs('version'),
'device' => $dd->getDeviceName().$dd->getModel().$dd->getBrandName(),
'lang' => request()->getPreferredLanguage(),
]));
}

Expand Down
5 changes: 4 additions & 1 deletion app/Services/VisitorService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Services;

use App\Helpers\Helper;
use App\Models\Url;
use App\Models\User;
use App\Models\Visit;
Expand All @@ -22,7 +23,9 @@ public function __construct(
public function create(Url $url)
{
$logBotVisit = config('urlhub.track_bot_visits');
if ($logBotVisit === false && \Browser::isBot() === true) {
$dd = Helper::deviceDetector();

if ($logBotVisit === false && $dd->isBot() === true) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
"embed/embed": "^4.4",
"endroid/qr-code": "^4.8",
"guzzlehttp/guzzle": "^7.8",
"hisorange/browser-detect": "^5.0",
"laravel/fortify": "^1.18",
"laravel/framework": "^10.29",
"laravel/sanctum": "^3.3",
"laravel/tinker": "^2.8",
"livewire/livewire": "^3.0",
"matomo/device-detector": "^6.1",
"paragonie/random-lib": "^2.0",
"paragonie/random_compat": "^2.0",
"power-components/livewire-powergrid": "^5.1",
Expand Down

0 comments on commit a2266c0

Please sign in to comment.