From c62bd216467e12992c5fa4eb2bac97fb63c404ae Mon Sep 17 00:00:00 2001 From: Krombel Date: Tue, 20 Feb 2018 20:10:44 +0100 Subject: [PATCH] add MatrixConnection->register(username,passwort,registration_secret); --- MatrixConnection.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/MatrixConnection.php b/MatrixConnection.php index 55c2ee3..36b6d4d 100644 --- a/MatrixConnection.php +++ b/MatrixConnection.php @@ -4,12 +4,20 @@ class MatrixConnection private $hs; private $at; + function __construct($homeserver) { + $this->hs = $homeserver; + } function __construct($homeserver, $access_token) { $this->hs = $homeserver; $this->at = $access_token; } function send($room_id, $message) { + if (!$this->at) { + error_log("No access token defined"); + return false; + } + $send_message = NULL; if (!$message) { 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