implement hasUser(localpart), RegisterState add verify{_admin}.php
- fixes
This commit is contained in:
@@ -1,12 +1,10 @@
|
||||
<?php
|
||||
require_once("functions.php");
|
||||
class MatrixConnection
|
||||
{
|
||||
private $hs;
|
||||
private $at;
|
||||
|
||||
function __construct($homeserver) {
|
||||
$this->hs = $homeserver;
|
||||
}
|
||||
function __construct($homeserver, $access_token) {
|
||||
$this->hs = $homeserver;
|
||||
$this->at = $access_token;
|
||||
@@ -24,7 +22,7 @@ class MatrixConnection
|
||||
} elseif(is_array($message)) {
|
||||
$send_message = $message;
|
||||
} elseif ($message instanceof MatrixMessage) {
|
||||
$sendmessage = $message->get_object();
|
||||
$send_message = $message->get_object();
|
||||
} else {
|
||||
error_log("message is of not valid type\n");
|
||||
return false;
|
||||
@@ -36,7 +34,7 @@ class MatrixConnection
|
||||
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($handle, CURLOPT_CONNECTTIMEOUT, 5);
|
||||
curl_setopt($handle, CURLOPT_TIMEOUT, 60);
|
||||
curl_setopt($handle, CURLOPT_POSTFIELDS, json_encode($message));
|
||||
curl_setopt($handle, CURLOPT_POSTFIELDS, json_encode($send_message));
|
||||
curl_setopt($handle, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
|
||||
|
||||
return exec_curl_request($handle);
|
||||
@@ -50,9 +48,26 @@ class MatrixConnection
|
||||
);
|
||||
}
|
||||
|
||||
function hasUser($username) {
|
||||
if (!$username) {
|
||||
throw new Exception ("no user given to lookup");
|
||||
}
|
||||
|
||||
$url = "https://".$this->hs."/_matrix/client/r0/profile/%40" . $username . "%3A" . $this->hs;
|
||||
$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));
|
||||
|
||||
$res = exec_curl_request($handle);
|
||||
return ($res ? true: false);
|
||||
}
|
||||
|
||||
function register($username, $password, $shared_secret) {
|
||||
if (!$username) {
|
||||
error_log("no username provided")
|
||||
error_log("no username provided");
|
||||
}
|
||||
if (!$password) {
|
||||
error_log("no message to send");
|
||||
@@ -64,8 +79,8 @@ class MatrixConnection
|
||||
"username" => $user,
|
||||
"password" => $password,
|
||||
"mac" => $mac,
|
||||
}
|
||||
$url="https://".$this->hs."/_matrix/client/v2_alpha/register";
|
||||
);
|
||||
$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);
|
||||
@@ -88,7 +103,7 @@ class MatrixMessage
|
||||
}
|
||||
|
||||
function set_type($msgtype) {
|
||||
$this->$message["msgtype"] = $msgtype;
|
||||
$this->message["msgtype"] = $msgtype;
|
||||
}
|
||||
|
||||
function set_format($format) {
|
||||
|
||||
Reference in New Issue
Block a user