only register if admin was notified

main
lub 2 weeks ago
parent 21481ed8d4
commit 9f44dfc9bb

@ -18,8 +18,10 @@ if (isset($_GET['secret']) && $_GET['secret'] === REGISTRATION_PASSWORD) {
$response = curl_exec($ch); $response = curl_exec($ch);
if (curl_error($ch) || curl_getinfo($ch, CURLINFO_HTTP_CODE) !== 200) { if (curl_error($ch) || curl_getinfo($ch, CURLINFO_HTTP_CODE) !== 200) {
echo 'Error retrieving nonce. Please try again later.'; echo 'Error retrieving nonce. Please try again later.';
} else { exit;
$nonce = json_decode($response)->nonce; }
$nonce = json_decode($response)->nonce;
?> ?>
<form action="/" method="post"> <form action="/" method="post">
@ -36,10 +38,28 @@ if (isset($_GET['secret']) && $_GET['secret'] === REGISTRATION_PASSWORD) {
</form> </form>
<?php <?php
}
} elseif (isset($_POST['nonce']) && isset($_POST['secret']) && $_POST['secret'] === REGISTRATION_PASSWORD) { } elseif (isset($_POST['nonce']) && isset($_POST['secret']) && $_POST['secret'] === REGISTRATION_PASSWORD) {
$username = filter_var(strtolower($_POST['username']), FILTER_SANITIZE_FULL_SPECIAL_CHARS); $username = filter_var(strtolower($_POST['username']), FILTER_SANITIZE_FULL_SPECIAL_CHARS);
# send admin message
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, SYNAPSE_URL.'/_matrix/client/v3/rooms/'.ROOM_ID.'/send/m.room.message/'.filter_var($_POST['nonce'], FILTER_SANITIZE_FULL_SPECIAL_CHARS));
curl_setopt($ch, CURLOPT_PUT, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
'body' => $decoded_response->user_id.' just registered',
'msgtype' => 'm.text'
]));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'authorization: Bearer '.ACCESS_TOKEN,
'content-type: application/json'
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
if ($curl_error($ch) || curl_getinfo($ch, CURLINFO_HTTP_CODE) !== 200) {
echo 'Registration for "'.$username.'" unsuccessful. Please try again later.';
exit;
}
$content = [ $content = [
'nonce' => $_POST['nonce'], 'nonce' => $_POST['nonce'],
'username' => $username, 'username' => $username,
@ -58,16 +78,14 @@ if (isset($_GET['secret']) && $_GET['secret'] === REGISTRATION_PASSWORD) {
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch); $response = curl_exec($ch);
if (curl_error($ch) || curl_getinfo($ch, CURLINFO_HTTP_CODE) !== 200) { if (curl_error($ch) || curl_getinfo($ch, CURLINFO_HTTP_CODE) !== 200) {
echo 'Registration for "'.$username.'" unsuccessful. Please try again later.';
exit;
}
$decoded_response = json_decode($response);
?> ?>
Registration for "<?php echo $username ?>" unsuccessful. Please try again later. Registration successful. To start using your new account please install a Matrix client like <a href="https://element.io/download">Element</a><br>
<?php
} else {
$decoded_response = json_decode($response);
?>
Registration successful. To start using it please install a Matrix client like <a href="https://element.io/download">Element</a><br>
<br> <br>
Server: <strong>imninja.net</strong><br> Server: <strong>imninja.net</strong><br>
Username: <strong><?php echo $username ?></strong><br> Username: <strong><?php echo $username ?></strong><br>
@ -81,31 +99,15 @@ Also consider using a password manager.<br>
<?php <?php
# logout out of session that exists after registering # logout out of session that exists after registering
$ch = curl_init(); $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, SYNAPSE_URL.'/_matrix/client/v3/logout'); curl_setopt($ch, CURLOPT_URL, SYNAPSE_URL.'/_matrix/client/v3/logout');
curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [ curl_setopt($ch, CURLOPT_HTTPHEADER, [
'authorization: Bearer '.$decoded_response->access_token 'authorization: Bearer '.$decoded_response->access_token
]); ]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch); curl_exec($ch);
# send admin message
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, SYNAPSE_URL.'/_matrix/client/v3/rooms/'.ROOM_ID.'/send/m.room.message/'.filter_var($_POST['nonce'], FILTER_SANITIZE_FULL_SPECIAL_CHARS));
curl_setopt($ch, CURLOPT_PUT, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
'body' => $decoded_response->user_id.' just registered',
'msgtype' => 'm.text'
]));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'authorization: Bearer '.ACCESS_TOKEN,
'content-type: application/json'
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
}
} else { } else {
echo 'Invalid URL'; echo 'Invalid URL';
} }

Loading…
Cancel
Save