only register if admin was notified

main
lub 2 weeks ago
parent 21481ed8d4
commit 9f44dfc9bb

@ -18,7 +18,9 @@ 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;
?> ?>
@ -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;
}
Registration for "<?php echo $username ?>" unsuccessful. Please try again later.
<?php
} else {
$decoded_response = json_decode($response); $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> Registration successful. To start using your new account 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>
@ -90,22 +108,6 @@ Also consider using a password manager.<br>
]); ]);
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