Commit 84c3b6db authored by Dominik Hebeler's avatar Dominik Hebeler
Browse files

added countdown to next change

parent 8ac8ff15
......@@ -17,10 +17,16 @@ class KeyController extends Controller
public function index(\App\Models\Key $key, Request $request)
{
$cookieLink = LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale(), route('loadSettings', Cookie::get()));
$key->canChange();
$changedAt = $key->keyinfo->KeyChangedAt;
if(!empty($changedAt)){
$changedAt = new Carbon($changedAt);
}
return view('key')
->with('title', trans('titles.key'))
->with('keystatus', $key->getStatus())
->with('cookie', $key->key)
->with('changedAt', $changedAt)
->with('cookieLink', $cookieLink);
}
......
......@@ -11,7 +11,8 @@ class Key
public $key;
public $status; # Null If Key invalid | false if valid but has no adFreeSearches | true if valid and has adFreeSearches
private $keyserver = "https://key.metager.de/";
private $keyinfo;
public $keyinfo;
const CHANGE_EVERY = 1 * 24 * 60 * 60;
public function __construct($key, $status = null)
{
......@@ -200,7 +201,7 @@ class Key
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)){
if($keyChangedAt->diffInSeconds(Carbon::now()) > self::CHANGE_EVERY){
return true;
}else{
return false;
......
......@@ -16,5 +16,6 @@ return [
'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.p2' => 'Der nächste Wechsel Ihres Schlüssels ist in :nextchange möglich.',
'custom.a1' => 'Wunsch Schlüssel einrichten'
];
......@@ -16,5 +16,6 @@ return [
"backLink" => "Back to the last page",
"custom.h3" => "Favorite Key",
"custom.p1" => "Members of the SUMA-EV have the opportunity to choose their own key.",
'custom.p2' => 'The next change of your key is possible in :nextchange.',
"custom.a1" => "Set up the favorite key"
];
......@@ -40,13 +40,19 @@
</ol>
@endif
</div>
@if(app('App\Models\Key')->canChange())
<div class="section">
<h3>@lang('key.custom.h3')</h3>
<p>@lang('key.custom.p1')</p>
@if(app('App\Models\Key')->canChange())
<a class="btn btn-default" href="{{ LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale(), route('changeKeyOne')) }}">@lang('key.custom.a1')</a>
@elseif(!empty($changedAt))
<p>@lang('key.custom.p2', [
'nextchange' => trim(str_replace(" später", "", $changedAt->addSeconds(\App\Models\Key::CHANGE_EVERY)->longRelativeDiffForHumans(Carbon::now("Europe/London"), 2)))
])</p>
@endif
</div>
@endif
<div class="section">
@if(isset($keystatus) && $keystatus === false)
<p class="error">@lang('key.empty')</p>
......
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