add MatrixConnection->register(username,passwort,registration_secret);

This commit is contained in:
2018-02-20 20:10:44 +01:00
parent b8f8fc1f69
commit c62bd21646

View File

@@ -4,12 +4,20 @@ class MatrixConnection
private $hs; private $hs;
private $at; private $at;
function __construct($homeserver) {
$this->hs = $homeserver;
}
function __construct($homeserver, $access_token) { function __construct($homeserver, $access_token) {
$this->hs = $homeserver; $this->hs = $homeserver;
$this->at = $access_token; $this->at = $access_token;
} }
function send($room_id, $message) { function send($room_id, $message) {
if (!$this->at) {
error_log("No access token defined");
return false;
}
$send_message = NULL; $send_message = NULL;
if (!$message) { if (!$message) {
error_log("no message to send"); error_log("no message to send");
@@ -41,6 +49,32 @@ class MatrixConnection
) )
); );
} }
function register($username, $password, $shared_secret) {
if (!$username) {
error_log("no username provided")
}
if (!$password) {
error_log("no message to send");
}
$mac = hash_hmac('sha1', $username, $registration_shared_secret);
$data = array(
"username" => $user,
"password" => $password,
"mac" => $mac,
}
$url="https://".$this->hs."/_matrix/client/v2_alpha/register";
$handle = curl_init($url);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($handle, CURLOPT_TIMEOUT, 60);
curl_setopt($handle, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
curl_setopt($handle, CURLOPT_POSTFIELDS, json_encode($data));
return exec_curl_request($handle);
}
} }
class MatrixMessage class MatrixMessage