Commit 336ad12f authored by Davide Aprea's avatar Davide Aprea
Browse files

replaced old key verification

parent 78db8739
......@@ -22,7 +22,7 @@ class KeyController extends Controller
$redirUrl = $request->input('redirUrl', "");
$key = $request->input('key', '');
if ($this->authorizeKey($key)) {
if (app('App\Models\Key')->getStatus()) {
# Valid Key
$host = $request->header("X_Forwarded_Host", "");
if (empty($host)) {
......@@ -45,32 +45,4 @@ class KeyController extends Controller
$url = LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale(), action('KeyController@index', ['redirUrl' => $redirUrl]));
return redirect($url);
}
private function authorizeKey($key)
{
$postdata = http_build_query(array(
'dummy' => rand(),
));
$opts = array('http' => array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $postdata,
),
);
$context = stream_context_create($opts);
try {
$link = "https://key.metager3.de/" . urlencode($key) . "/request-permission/api-access";
$result = json_decode(file_get_contents($link, false, $context));
if ($result->{'api-access'} == true) {
return true;
} else {
return false;
}
} catch (\ErrorException $e) {
return false;
}
}
}
Supports Markdown
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