Commit c1f71151 authored by Dominik Hebeler's avatar Dominik Hebeler

added ui to start changing the key

parent 3208384c
......@@ -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;
}
}
......@@ -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'
];
......@@ -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">
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment