Last active
March 18, 2022 16:06
-
-
Save krasenslavov/b5b47482d67adfe71d615a508df52f77 to your computer and use it in GitHub Desktop.
Controllers for our license key API server. Visit blog post https://bit.ly/2Vwobsu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// 1. Return license key & sites after successful authentication. | |
function get_license($req, $res, $args) { | |
$params = $req->getParams(); | |
$header = $req->getHeaders(); | |
$license_key = get_license_key($header['PHP_AUTH_USER'][0]); | |
return $res->withJson([ | |
'license_key' => $license_key['unique_key'], | |
'sites' => $license_key['sites'] | |
]); | |
} | |
// 2. Activate license key for a site after a successful authentication. | |
function activate_license($req, $res, $args) { | |
$params = $req->getParams(); | |
$header = $req->getHeaders(); | |
$update = update_license_key($header['PHP_AUTH_USER'][0], $params['url'], 1); | |
if ($update) { | |
return $res->withJson(['status' => 'success']); | |
} else { | |
return $res->withJson(['status' => 'failure']); | |
} | |
} | |
// 3. Deactivate license key for a site after a successful authentication. | |
function deactivate_license($req, $res, $args) { | |
$params = $req->getParams(); | |
$header = $req->getHeaders(); | |
$update = update_license_key($header['PHP_AUTH_USER'][0], $params['url'], 0); | |
if ($update) { | |
return $res->withJson(['status' => 'success']); | |
} else { | |
return $res->withJson(['status' => 'failure']); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment