Second implementation with matrix_synapse_rest_auth #2

Merged
krombel merged 51 commits from second_implementation into master 2018-03-19 13:57:16 +01:00
Showing only changes of commit cd239847ed - Show all commits

View File

@@ -1,4 +1,4 @@
<?php <?php
require_once("config.php"); require_once("config.php");
if (!isset($config["databaseURI"])) { if (!isset($config["databaseURI"])) {
throw new Exception ("malformed configuration: databaseURI not defined"); throw new Exception ("malformed configuration: databaseURI not defined");
@@ -72,7 +72,7 @@ class mxDatabase
if (!$this->userRegistered("register_bot")) { if (!$this->userRegistered("register_bot")) {
$password = $this->addUser("Register", "Bot", "register_bot", $config["register_email"]); $password = $this->addUser("Register", "Bot", "register_bot", $config["register_email"]);
$config["register_password"] = $password; $config["register_password"] = $password;
$myfile = fopen("config.json", "w"); $myfile = fopen(dirname(__FILE__) . "/config.json", "w");
fwrite($myfile, json_encode($config, JSON_PRETTY_PRINT)); fwrite($myfile, json_encode($config, JSON_PRETTY_PRINT));
fclose($myfile); fclose($myfile);
} }
@@ -101,28 +101,28 @@ class mxDatabase
function setRegistrationStateVerify($state, $token) { function setRegistrationStateVerify($state, $token) {
$sql = "UPDATE registrations SET state = " . $state $sql = "UPDATE registrations SET state = " . $state
. ' WHERE verify_token = "' . $token . '";'; . ' WHERE verify_token = "' . $token . '";';
return $this->db->exec($sql); return $this->db->exec($sql);
} }
function setRegistrationStateById($state, $id) { function setRegistrationStateById($state, $id) {
$sql = "UPDATE registrations SET state = " . $state $sql = "UPDATE registrations SET state = " . $state
. ' WHERE id = "' . $id . '";'; . ' WHERE id = "' . $id . '";';
return $this->db->exec($sql); return $this->db->exec($sql);
} }
function setRegistrationStateAdmin($state, $token) { function setRegistrationStateAdmin($state, $token) {
$sql = "UPDATE registrations SET state = " . $state $sql = "UPDATE registrations SET state = " . $state
. ' WHERE admin_token = "' . $token . '";'; . ' WHERE admin_token = "' . $token . '";';
return $this->db->exec($sql); return $this->db->exec($sql);
} }
function setRegistrationState($state, $token) { function setRegistrationState($state, $token) {
$sql = "UPDATE registrations SET state = " . $state $sql = "UPDATE registrations SET state = " . $state
. " WHERE verify_token = \"" . $token . '" OR admin_token = "' . $token . '";'; . " WHERE verify_token = \"" . $token . '" OR admin_token = "' . $token . '";';
return $this->db->exec($sql); return $this->db->exec($sql);
} }
@@ -152,7 +152,7 @@ class mxDatabase
* @param note Note the user typed in to give a hint * @param note Note the user typed in to give a hint
* @param email E-Mail-Adress which will be stored into the database. * @param email E-Mail-Adress which will be stored into the database.
* This will be send to the server on first login * This will be send to the server on first login
* *
* @return ["verify_token"] * @return ["verify_token"]
*/ */
function addRegistration($first_name, $last_name, $username, $note, $email) { function addRegistration($first_name, $last_name, $username, $note, $email) {
@@ -164,7 +164,7 @@ class mxDatabase
require_once("language.php"); require_once("language.php");
throw new Exception($language["USERNAME_REGISTERED"] . " (registered)"); throw new Exception($language["USERNAME_REGISTERED"] . " (registered)");
} }
$verify_token = bin2hex(random_bytes(16)); $verify_token = bin2hex(random_bytes(16));
$admin_token = bin2hex(random_bytes(16)); $admin_token = bin2hex(random_bytes(16));
@@ -180,7 +180,7 @@ class mxDatabase
/** /**
* Gets the user for the verify_admin page. * Gets the user for the verify_admin page.
* *
* @return ArrayOfUser|NULL Array with "first_name, last_name, username, note and email" * @return ArrayOfUser|NULL Array with "first_name, last_name, username, note and email"
* as members * as members
*/ */
@@ -205,7 +205,7 @@ class mxDatabase
/** /**
* Gets the user when it opens the page to verify its mail * Gets the user when it opens the page to verify its mail
* *
* @return ArrayOfUser|NULL Array with "first_name, last_name, note, email and admin_token" * @return ArrayOfUser|NULL Array with "first_name, last_name, note, email and admin_token"
* as members * as members
*/ */
@@ -253,11 +253,11 @@ class mxDatabase
* @param username the future localpart of that user * @param username the future localpart of that user
* @param email E-Mail-Adress which will be stored into the database. * @param email E-Mail-Adress which will be stored into the database.
* This will be send to the server on first login * This will be send to the server on first login
* *
* @return password|NULL with member password as this method generates a * @return password|NULL with member password as this method generates a
* password and saves that into the database * password and saves that into the database
* NULL when failed * NULL when failed
* *
*/ */
function addUser($first_name, $last_name, $username, $email) { function addUser($first_name, $last_name, $username, $email) {
// check if user already exists and abort in that case // check if user already exists and abort in that case
@@ -272,7 +272,7 @@ class mxDatabase
$sql = "INSERT INTO logins (first_name, last_name, localpart, password_hash, email) VALUES " $sql = "INSERT INTO logins (first_name, last_name, localpart, password_hash, email) VALUES "
. '("' . $first_name.'","' . $last_name . '","' . $username . '","' . '("' . $first_name.'","' . $last_name . '","' . $username . '","'
. $password_hash . '","' . $email . '")'; . $password_hash . '","' . $email . '")';
if ($this->db->exec($sql)) { if ($this->db->exec($sql)) {
return $password; return $password;
} }