mirror of
https://github.com/samsonjs/mit-license.git
synced 2026-04-27 15:07:42 +00:00
support curl based user creation - let users do it entirely themselves
This commit is contained in:
parent
3c974ae00e
commit
c5ecbbee05
1 changed files with 23 additions and 1 deletions
24
index.php
24
index.php
|
|
@ -5,12 +5,34 @@
|
||||||
$format = 'html';
|
$format = 'html';
|
||||||
$theme = 'default';
|
$theme = 'default';
|
||||||
$user_file = preg_replace('/\.mit-license\..*$/', '', $_SERVER["HTTP_HOST"]);
|
$user_file = preg_replace('/\.mit-license\..*$/', '', $_SERVER["HTTP_HOST"]);
|
||||||
|
|
||||||
// sanitise user (not for DNS, but for file reading, I don't know
|
// sanitise user (not for DNS, but for file reading, I don't know
|
||||||
// just in case it's hacked about with or something bananas.
|
// just in case it's hacked about with or something bananas.
|
||||||
$user_file = preg_replace('/[^a-z0-9\-]/', '', $user_file);
|
$user_file = preg_replace('/[^a-z0-9\-]/', '', $user_file);
|
||||||
$user_file = 'users/'.$user_file.'.json';
|
$user_file = 'users/'.$user_file.'.json';
|
||||||
|
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
|
try {
|
||||||
|
$data = json_decode(file_get_contents('php://input'));
|
||||||
|
if (!property_exists($data, 'copyright')) {
|
||||||
|
Throw new Exception('>>> JSON requires "copyright" property and value');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (file_exists($user_file)) {
|
||||||
|
Throw new Exception(wordwrap('>>> User already exists - to update values, please send a pull request on https://github.com/remy/mit-license'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!file_put_contents($user_file, json_encode($data))) {
|
||||||
|
Throw new Exception(wordwrap('>>> Unable to create new user - please send a pull request on https://github.com/remy/mit-license'));
|
||||||
|
}
|
||||||
|
|
||||||
|
echo '>>> MIT license page created: http://' . $_SERVER['HTTP_HOST'] . "\n\n";
|
||||||
|
|
||||||
|
} catch (Exception $e) {
|
||||||
|
echo $e->getMessage() . "\n\n";
|
||||||
|
}
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
if (file_exists($user_file)) {
|
if (file_exists($user_file)) {
|
||||||
$user = json_decode(file_get_contents($user_file));
|
$user = json_decode(file_get_contents($user_file));
|
||||||
$holder = htmlentities($user->copyright, ENT_COMPAT | ENT_HTML5, 'UTF-8');
|
$holder = htmlentities($user->copyright, ENT_COMPAT | ENT_HTML5, 'UTF-8');
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue