Skip to content

Commit

Permalink
Time comparison via carbon
Browse files Browse the repository at this point in the history
  • Loading branch information
hz61p1 committed Aug 4, 2018
1 parent dcff49b commit bf59dad
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"require": {
"php": ">=7.0.0",
"illuminate/http": "5.5.x|5.6.x",
"illuminate/support": "5.5.x|5.6.x"
"illuminate/support": "5.5.x|5.6.x",
"nesbot/carbon": "^1.32"
},
"autoload": {
"psr-4": {
Expand Down
5 changes: 4 additions & 1 deletion src/TelegramLoginAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Azate\LaravelTelegramLoginAuth;

use Carbon\Carbon;
use Illuminate\Http\Request;

/**
Expand Down Expand Up @@ -73,7 +74,9 @@ public function validate(): bool
return false;
}

if ((time() - $data['auth_date'] ?? 0) > 86400) {
$authDate = Carbon::createFromTimestampUTC($data['auth_date']);

if (Carbon::now()->greaterThanOrEqualTo($authDate->addHour())) {
return false;
}

Expand Down

0 comments on commit bf59dad

Please sign in to comment.