Merge branch 'second_implementation' of gitea.krombel.de:krombel/matrix-register-bot into second_implementation

This commit is contained in:
2018-03-03 14:27:17 +01:00
5 changed files with 17 additions and 17 deletions

View File

@@ -123,7 +123,7 @@ class mxDatabase
function userPendingRegistrations($username) {
$sql = "SELECT COUNT(*) FROM registrations WHERE username = '" . $username . "' AND NOT state = "
. RegisterState::RegistrationDeclined . " LIMIT 1;";
$res = $db->query($sql);
$res = $this->db->query($sql);
if ($res->fetchColumn() > 0) {
return true;
}
@@ -150,7 +150,7 @@ class mxDatabase
* @return ["verify_token"]
*/
function addRegistration($first_name, $last_name, $username, $note, $email) {
if ($this->userPendingRegistrations()) {
if ($this->userPendingRegistrations($username)) {
require_once "language.php";
throw new Exception($language["USERNAME_PENDING_REGISTRATION"]);
}
@@ -162,7 +162,7 @@ class mxDatabase
$verify_token = bin2hex(random_bytes(16));
$admin_token = bin2hex(random_bytes(16));
$db->exec('INSERT INTO registrations
$this->db->exec('INSERT INTO registrations
(first_name, last_name, username, note, email, verify_token, admin_token)
VALUES ("' . $first_name.'","' . $last_name . '","' . $username . '","' . $note . '","'
. $email.'","' .$verify_token.'","' .$admin_token.'")');
@@ -181,7 +181,7 @@ class mxDatabase
function getUserForApproval($admin_token) {
$sql = "SELECT COUNT(*) FROM registrations WHERE admin_token = '" . $admin_token . "'"
. " AND state = " . RegisterState::PendingAdminVerify . " LIMIT 1;";
$res = $db->query($sql);
$res = $this->db->query($sql);
$first_name = NULL; $last_name = NULL; $username = NULL; $note = NULL; $email = NULL;
if ($res->fetchColumn() > 0) {
@@ -206,14 +206,14 @@ class mxDatabase
function getUserForVerify($verify_token) {
$sql = "SELECT COUNT(*) FROM registrations WHERE verify_token = '" . $verify_token . "'"
. " AND state = " . RegisterState::PendingEmailVerify . " LIMIT 1;";
$res = $db->query($sql);
$res = $this->db->query($sql);
$first_name = NULL; $last_name = NULL; $username = NULL; $note = NULL; $email = NULL;
if ($res->fetchColumn() > 0) {
$sql = "SELECT first_name, last_name, note, email, admin_token FROM registrations "
. " WHERE verify_token = '" . $token . "'"
. " WHERE verify_token = '" . $verify_token . "'"
. " AND state = " . RegisterState::PendingEmailVerify . " LIMIT 1;";
foreach ($db->query($sql) as $row) {
foreach ($this->db->query($sql) as $row) {
// will only be executed once
return $row;
}
@@ -256,7 +256,7 @@ class mxDatabase
function addUser($first_name, $last_name, $username, $email) {
// generate a password with 10 characters
$password = bin2hex(openssl_random_pseudo_bytes(5));
$password_hash = password_hash($passwort, PASSWORD_BCRYPT, ["cost"=>12]);
$password_hash = password_hash($password, PASSWORD_BCRYPT, ["cost"=>12]);
$sql = "INSERT INTO logins (firstname, lastname, localpart, password_hash, email) VALUES "
. '("' . $first_name.'","' . $last_name . '","' . $username . '","'