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

Merge branch '1040-switch-adgoal-api' into 1049-switch-server-endpoint-for-key-api

parents f9e98c78 ef1aefba
No related branches found
No related tags found
3 merge requests!1895Development,!1754Development,!1753Resolve "Switch Server Endpoint for Key Api"
<?php <?php
namespace App\Models; namespace App\Models;
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/";
public function __construct($key, $status = null)
public function __construct($key, $status = null){ {
$this->key = $key; $this->key = $key;
$this->status = $status; $this->status = $status;
if (getenv("APP_ENV") !== "production") {
$this->keyserver = "https://dev.key.metager.de/";
}
} }
# always returns true or false # always returns true or false
public function getStatus() { public function getStatus()
if($this->key !== '' && $this->status === null) { {
if ($this->key !== '' && $this->status === null) {
$this->updateStatus(); $this->updateStatus();
} }
if($this->status === null || $this->status === false) { if ($this->status === null || $this->status === false) {
return false; return false;
} else { } else {
return true; return true;
...@@ -25,10 +31,10 @@ class Key{ ...@@ -25,10 +31,10 @@ class Key{
} }
public function updateStatus() { public function updateStatus()
{
try { try {
$link = "https://key.metager3.de/" . urlencode($this->key) . "/request-permission/api-access"; $link = $this->keyserver . urlencode($this->key) . "/request-permission/api-access";
$result = json_decode(file_get_contents($link)); $result = json_decode(file_get_contents($link));
if ($result->{'api-access'} == true) { if ($result->{'api-access'} == true) {
$this->status = true; $this->status = true;
...@@ -42,8 +48,8 @@ class Key{ ...@@ -42,8 +48,8 @@ class Key{
} }
} }
public function requestPermission() { public function requestPermission()
{
$postdata = http_build_query(array( $postdata = http_build_query(array(
'dummy' => 0, 'dummy' => 0,
)); ));
...@@ -58,16 +64,16 @@ class Key{ ...@@ -58,16 +64,16 @@ class Key{
$context = stream_context_create($opts); $context = stream_context_create($opts);
try { try {
$link = "https://key.metager3.de/" . urlencode($this->key) . "/request-permission/api-access"; $link = $this->keyserver . urlencode($this->key) . "/request-permission/api-access";
$result = json_decode(file_get_contents($link, false, $context)); $result = json_decode(file_get_contents($link, false, $context));
if ($result->{'api-access'} == true) { if ($result->{'api-access'} == true) {
return true; return true;
} else { } else {
$this->status = false; $this->status = false;
return false; return false;
} }
} catch (\ErrorException $e) { } catch (\ErrorException $e) {
return false; return false;
} }
} }
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment