diff --git a/app/Models/Key.php b/app/Models/Key.php index caef0430f53badc80ab164a30c463a049db8567d..d6116425fa6a3da76a366c94693439819ebacd42 100644 --- a/app/Models/Key.php +++ b/app/Models/Key.php @@ -4,12 +4,14 @@ namespace App\Models; use Illuminate\Support\Facades\Redis; use Request; +use \Carbon\Carbon; class Key { public $key; public $status; # valid key = true, invalid key = false, unidentified key = null private $keyserver = "https://key.metager.de/"; + private $keyinfo; public function __construct($key, $status = null) { @@ -71,6 +73,7 @@ class Key try { $link = $this->keyserver . "v2/key/". urlencode($this->key); $result = json_decode(file_get_contents($link, false, $context)); + $this->keyinfo = $result; if ($result->{'apiAccess'} == 'unlimited') { $this->status = true; return true; @@ -149,4 +152,27 @@ class Key return false; } } + + /** + * Tells if this key is liable to change to a custom key + * Currently only members are allowed to do so and only every 2 days + * Also only the original member key is allowed to be changed + * + * @return boolean + */ + public function canChange(){ + if(empty($this->status) || !preg_match("/^Mitgliederschlüssel\./", $this->keyinfo->notes)){ + return false; + } + if(!empty($this->keyinfo->KeyChangedAt)){ + // "2021-03-09T09:19:44.000Z" + $keyChangedAt = Carbon::createFromTimeString($this->keyinfo->KeyChangedAt, 'Europe/London'); + if($keyChangedAt->diffInSeconds(Carbon::now()) > (2 * 24 * 60 * 60)){ + return true; + }else{ + return false; + } + } + return true; + } } diff --git a/composer.json b/composer.json index 1255c1b3e02d7dd9dd1159753a3419414ba9adb6..ac2b1300eb9bb125c18f359d44e7c397705931dc 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ "require-dev": { "beyondcode/laravel-dump-server": "^1.0", "browserstack/browserstack-local": "^1.1", - "filp/whoops": "^2.0", + "filp/whoops": "^2.9", "fzaninotto/faker": "^1.4", "laravel/dusk": "^5.0", "mockery/mockery": "^1.0", diff --git a/resources/lang/de/key.php b/resources/lang/de/key.php index f29f434b0c955872eb77b9fe56ae78593892bc20..9582222c4d7e7a3253cc2d5f0935722934725dd3 100644 --- a/resources/lang/de/key.php +++ b/resources/lang/de/key.php @@ -13,4 +13,7 @@ return [ 'removeKey' => 'aktuellen Schlüssel entfernen', 'invalidKey' => 'Der eingegebene Schlüssel ist ungültig', 'backLink' => 'Zurück zur letzten Seite', + 'custom.h3' => 'Wunsch-Schlüssel', + 'custom.p1' => 'Mitglieder des SUMA-EV haben die Möglichkeit, sich einen eigenen Schlüssel auszusuchen.', + 'custom.a1' => 'Wunsch-Schlüssel erstellen' ]; diff --git a/resources/views/key.blade.php b/resources/views/key.blade.php index eec467c0a73225d9dbf3054474f0059f1f8ec135..fb9c9322a4550cd079d25ef877cbee2a33e6a72e 100644 --- a/resources/views/key.blade.php +++ b/resources/views/key.blade.php @@ -38,6 +38,13 @@ </li> </ol> </div> + @if(app('App\Models\Key')->canChange()) + <div class="section"> + <h3>@lang('key.custom.h3')</h3> + <p>@lang('key.custom.p1')</p> + <a href="#">@lang('key.custom.a1')</a> + </div> + @endif <div class="section"> <div id="form-wrapper"> <form method="post">