Skip to content
Snippets Groups Projects
Commit c1f71151 authored by Dominik Hebeler's avatar Dominik Hebeler
Browse files

added ui to start changing the key

parent 3208384c
No related branches found
No related tags found
3 merge requests!1895Development,!1857Development,!1856Resolve "Implement Method for Changing the member key"
...@@ -4,12 +4,14 @@ namespace App\Models; ...@@ -4,12 +4,14 @@ namespace App\Models;
use Illuminate\Support\Facades\Redis; use Illuminate\Support\Facades\Redis;
use Request; use Request;
use \Carbon\Carbon;
class Key class Key
{ {
public $key; public $key;
public $status; # valid key = true, invalid key = false, unidentified key = null public $status; # valid key = true, invalid key = false, unidentified key = null
private $keyserver = "https://key.metager.de/"; private $keyserver = "https://key.metager.de/";
private $keyinfo;
public function __construct($key, $status = null) public function __construct($key, $status = null)
{ {
...@@ -71,6 +73,7 @@ class Key ...@@ -71,6 +73,7 @@ class Key
try { try {
$link = $this->keyserver . "v2/key/". urlencode($this->key); $link = $this->keyserver . "v2/key/". urlencode($this->key);
$result = json_decode(file_get_contents($link, false, $context)); $result = json_decode(file_get_contents($link, false, $context));
$this->keyinfo = $result;
if ($result->{'apiAccess'} == 'unlimited') { if ($result->{'apiAccess'} == 'unlimited') {
$this->status = true; $this->status = true;
return true; return true;
...@@ -149,4 +152,27 @@ class Key ...@@ -149,4 +152,27 @@ class Key
return false; 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 [ ...@@ -13,4 +13,7 @@ return [
'removeKey' => 'aktuellen Schlüssel entfernen', 'removeKey' => 'aktuellen Schlüssel entfernen',
'invalidKey' => 'Der eingegebene Schlüssel ist ungültig', 'invalidKey' => 'Der eingegebene Schlüssel ist ungültig',
'backLink' => 'Zurück zur letzten Seite', '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 @@ ...@@ -38,6 +38,13 @@
</li> </li>
</ol> </ol>
</div> </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 class="section">
<div id="form-wrapper"> <div id="form-wrapper">
<form method="post"> <form method="post">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment