move API calls to correct place

main
lub 2 weeks ago
parent 8635dd1c7c
commit 4c48543331

@ -7,6 +7,7 @@
define('ACCESS_TOKEN', 'at_bsef');
define('REGISTRATION_PASSWORD', 'asef');
define('REGISTRATION_API_URL', 'http://synapse:8008/_synapse/admin/v1/register');
define('EVENT_API_URL', 'http://synapse:8008/_matrix/client/v3/rooms/{roomId}/send/{eventType}/{txnId}')
if ($_GET['secret'] === REGISTRATION_PASSWORD) {
?>
@ -28,11 +29,20 @@ if ($_GET['secret'] === REGISTRATION_PASSWORD) {
$username = filter_var($_POST['username'], FILTER_SANITIZE_FULL_SPECIAL_CHARS);
var_dump($_POST);
$content = [
nonce => $_POST['nonce'],
username => $_POST['username'],
password => $_POST['password']
admin = false
];
$content->mac = hash_hmac('sha1', $content->nonce."\s".$content->username."\s".$content->password."\s".$content->admin
$options = [
'http' => [
'method' => 'POST',
'header' => 'authorization: Bearer '.ACCESS_TOKEN,
'content-type: application/json'
'content-type: application/json',
'content' => json_encode($content);
]
];
$context = stream_context_create($options);
@ -59,14 +69,6 @@ Also consider using a password manager.<br>
<?php
}
$content = [
nonce => $_POST['nonce'],
username => $_POST['username'],
password => $_POST['password']
admin = false
];
$content->mac = hash_hmac('sha1', $content->nonce."\s".$content->username."\s".$content->password."\s".$content->admin
$options = [
'http' => [
'method' => 'POST',
@ -76,8 +78,8 @@ Also consider using a password manager.<br>
]
];
$context = stream_context_create($options);
$result = file_get_contents(REGISTRATION_API_URL, false, $context);
if ($result === FALSE) {
$message = file_get_contents(EVENT_API_URL, false, $context);
if ($message === FALSE) {
# something with errors
} else {
# success

Loading…
Cancel
Save