Merge branch 'second_implementation' of gitea.krombel.de:krombel/matrix-register-bot into second_implementation
This commit is contained in:
4
cron.php
4
cron.php
@@ -25,7 +25,7 @@ foreach ($mx_db->query($sql) as $row) {
|
|||||||
$config["homeserver"],
|
$config["homeserver"],
|
||||||
$row["first_name"] . " " . $row["last_name"],
|
$row["first_name"] . " " . $row["last_name"],
|
||||||
$row["email"],
|
$row["email"],
|
||||||
$row["verify_url"]);
|
$verify_url);
|
||||||
|
|
||||||
if ($success) {
|
if ($success) {
|
||||||
$mx_db->setRegistrationStateById(RegisterState::PendingEmailVerify, $row["id"]);
|
$mx_db->setRegistrationStateById(RegisterState::PendingEmailVerify, $row["id"]);
|
||||||
@@ -58,7 +58,7 @@ foreach ($mx_db->query($sql) as $row) {
|
|||||||
case RegisterState::PendingRegistration:
|
case RegisterState::PendingRegistration:
|
||||||
// Registration got accepted but registration failed
|
// Registration got accepted but registration failed
|
||||||
|
|
||||||
$password = addUser($row["first_name"], $row["last_name"], $row["username"], $row["email"]);
|
$password = $mx_db->addUser($row["first_name"], $row["last_name"], $row["username"], $row["email"]);
|
||||||
if ($password != NULL) {
|
if ($password != NULL) {
|
||||||
// send registration_success
|
// send registration_success
|
||||||
$res = send_mail_registration_success($config["homeserver"], $first_name . " " . $last_name, $email, $username, $password, $config["howToURL"]);
|
$res = send_mail_registration_success($config["homeserver"], $first_name . " " . $last_name, $email, $username, $password, $config["howToURL"]);
|
||||||
|
|||||||
16
database.php
16
database.php
@@ -123,7 +123,7 @@ class mxDatabase
|
|||||||
function userPendingRegistrations($username) {
|
function userPendingRegistrations($username) {
|
||||||
$sql = "SELECT COUNT(*) FROM registrations WHERE username = '" . $username . "' AND NOT state = "
|
$sql = "SELECT COUNT(*) FROM registrations WHERE username = '" . $username . "' AND NOT state = "
|
||||||
. RegisterState::RegistrationDeclined . " LIMIT 1;";
|
. RegisterState::RegistrationDeclined . " LIMIT 1;";
|
||||||
$res = $db->query($sql);
|
$res = $this->db->query($sql);
|
||||||
if ($res->fetchColumn() > 0) {
|
if ($res->fetchColumn() > 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -150,7 +150,7 @@ class mxDatabase
|
|||||||
* @return ["verify_token"]
|
* @return ["verify_token"]
|
||||||
*/
|
*/
|
||||||
function addRegistration($first_name, $last_name, $username, $note, $email) {
|
function addRegistration($first_name, $last_name, $username, $note, $email) {
|
||||||
if ($this->userPendingRegistrations()) {
|
if ($this->userPendingRegistrations($username)) {
|
||||||
require_once "language.php";
|
require_once "language.php";
|
||||||
throw new Exception($language["USERNAME_PENDING_REGISTRATION"]);
|
throw new Exception($language["USERNAME_PENDING_REGISTRATION"]);
|
||||||
}
|
}
|
||||||
@@ -162,7 +162,7 @@ class mxDatabase
|
|||||||
$verify_token = bin2hex(random_bytes(16));
|
$verify_token = bin2hex(random_bytes(16));
|
||||||
$admin_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)
|
(first_name, last_name, username, note, email, verify_token, admin_token)
|
||||||
VALUES ("' . $first_name.'","' . $last_name . '","' . $username . '","' . $note . '","'
|
VALUES ("' . $first_name.'","' . $last_name . '","' . $username . '","' . $note . '","'
|
||||||
. $email.'","' .$verify_token.'","' .$admin_token.'")');
|
. $email.'","' .$verify_token.'","' .$admin_token.'")');
|
||||||
@@ -181,7 +181,7 @@ class mxDatabase
|
|||||||
function getUserForApproval($admin_token) {
|
function getUserForApproval($admin_token) {
|
||||||
$sql = "SELECT COUNT(*) FROM registrations WHERE admin_token = '" . $admin_token . "'"
|
$sql = "SELECT COUNT(*) FROM registrations WHERE admin_token = '" . $admin_token . "'"
|
||||||
. " AND state = " . RegisterState::PendingAdminVerify . " LIMIT 1;";
|
. " 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;
|
$first_name = NULL; $last_name = NULL; $username = NULL; $note = NULL; $email = NULL;
|
||||||
|
|
||||||
if ($res->fetchColumn() > 0) {
|
if ($res->fetchColumn() > 0) {
|
||||||
@@ -206,14 +206,14 @@ class mxDatabase
|
|||||||
function getUserForVerify($verify_token) {
|
function getUserForVerify($verify_token) {
|
||||||
$sql = "SELECT COUNT(*) FROM registrations WHERE verify_token = '" . $verify_token . "'"
|
$sql = "SELECT COUNT(*) FROM registrations WHERE verify_token = '" . $verify_token . "'"
|
||||||
. " AND state = " . RegisterState::PendingEmailVerify . " LIMIT 1;";
|
. " 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;
|
$first_name = NULL; $last_name = NULL; $username = NULL; $note = NULL; $email = NULL;
|
||||||
|
|
||||||
if ($res->fetchColumn() > 0) {
|
if ($res->fetchColumn() > 0) {
|
||||||
$sql = "SELECT first_name, last_name, note, email, admin_token FROM registrations "
|
$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;";
|
. " AND state = " . RegisterState::PendingEmailVerify . " LIMIT 1;";
|
||||||
foreach ($db->query($sql) as $row) {
|
foreach ($this->db->query($sql) as $row) {
|
||||||
// will only be executed once
|
// will only be executed once
|
||||||
return $row;
|
return $row;
|
||||||
}
|
}
|
||||||
@@ -256,7 +256,7 @@ class mxDatabase
|
|||||||
function addUser($first_name, $last_name, $username, $email) {
|
function addUser($first_name, $last_name, $username, $email) {
|
||||||
// generate a password with 10 characters
|
// generate a password with 10 characters
|
||||||
$password = bin2hex(openssl_random_pseudo_bytes(5));
|
$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 "
|
$sql = "INSERT INTO logins (firstname, lastname, localpart, password_hash, email) VALUES "
|
||||||
. '("' . $first_name.'","' . $last_name . '","' . $username . '","'
|
. '("' . $first_name.'","' . $last_name . '","' . $username . '","'
|
||||||
|
|||||||
@@ -76,13 +76,13 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|||||||
print("</head><body>");
|
print("</head><body>");
|
||||||
print("<h1>Erfolgreich</h1>");
|
print("<h1>Erfolgreich</h1>");
|
||||||
print("<p>Bitte überprüfe deine E-Mails um deine E-Mail-Adresse zu bestätigen.</p>");
|
print("<p>Bitte überprüfe deine E-Mails um deine E-Mail-Adresse zu bestätigen.</p>");
|
||||||
print("<a href=\"" . "/register.php" . "\">Zur Registrierungsseite</a>");
|
print("<a href=\"" . "/index.php" . "\">Zur Registrierungsseite</a>");
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
print("<title>" . $language["REGISTRATION_REQUEST_FAILED"] . "</title>");
|
print("<title>" . $language["REGISTRATION_REQUEST_FAILED"] . "</title>");
|
||||||
print("</head><body>");
|
print("</head><body>");
|
||||||
print("<h1>" . $language["REGISTRATION_REQUEST_FAILED"] . "</h1>");
|
print("<h1>" . $language["REGISTRATION_REQUEST_FAILED"] . "</h1>");
|
||||||
print("<p>" . $e->getMessage() . "</p>");
|
print("<p>" . $e->getMessage() . "</p>");
|
||||||
print("<a href=\"" . $config["webroot"] . "/register.php" . "\">Zur Registrierungsseite</a>");
|
print("<a href=\"" . $config["webroot"] . "/index.php" . "\">Zur Registrierungsseite</a>");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$_SESSION["token"] = bin2hex(random_bytes(16));
|
$_SESSION["token"] = bin2hex(random_bytes(16));
|
||||||
@@ -114,7 +114,7 @@ body{
|
|||||||
<h3 class="panel-title">Bitte für <?php echo $config["homeserver"]; ?> registrieren<small>2-Schritt-Registrierung</small></h3>
|
<h3 class="panel-title">Bitte für <?php echo $config["homeserver"]; ?> registrieren<small>2-Schritt-Registrierung</small></h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
<form name="regForm" role="form" action="register.php" method="post">
|
<form name="regForm" role="form" action="index.php" method="post">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-xs-6 col-sm-6 col-md-6">
|
<div class="col-xs-6 col-sm-6 col-md-6">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
|
|||||||
@@ -64,13 +64,13 @@ try {
|
|||||||
print("</head><body>");
|
print("</head><body>");
|
||||||
print("<h1>" . $language["VERIFICATION_SUCEEDED"] . "</h1>");
|
print("<h1>" . $language["VERIFICATION_SUCEEDED"] . "</h1>");
|
||||||
print("<p>" . $language["VERIFICATION_SUCCESS_BODY"] . "</p>");
|
print("<p>" . $language["VERIFICATION_SUCCESS_BODY"] . "</p>");
|
||||||
print("<a href=\"" . $config["webroot"] . "/register.php" . "\">Zur Registrierungsseite</a>");
|
print("<a href=\"" . $config["webroot"] . "/index.php" . "\">Zur Registrierungsseite</a>");
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
print("<title>" . $language["VERIFICATION_FAILED"] . "</title>");
|
print("<title>" . $language["VERIFICATION_FAILED"] . "</title>");
|
||||||
print("</head><body>");
|
print("</head><body>");
|
||||||
print("<h1>" . $language["VERIFICATION_FAILED"] . "</h1>");
|
print("<h1>" . $language["VERIFICATION_FAILED"] . "</h1>");
|
||||||
print("<p>" . $e->getMessage() . "</p>");
|
print("<p>" . $e->getMessage() . "</p>");
|
||||||
print("<a href=\"" . $config["webroot"] . "/register.php" . "\">Zur Registrierungsseite</a>");
|
print("<a href=\"" . $config["webroot"] . "/index.php" . "\">Zur Registrierungsseite</a>");
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ try {
|
|||||||
$mxConn = new MatrixConnection($config["homeserver"], $config["access_token"]);
|
$mxConn = new MatrixConnection($config["homeserver"], $config["access_token"]);
|
||||||
|
|
||||||
// generate a password with 8 characters
|
// generate a password with 8 characters
|
||||||
$password = addUser($first_name, $last_name, $username, $email);
|
$password = $mx_db->addUser($first_name, $last_name, $username, $email);
|
||||||
if ($password != NULL) {
|
if ($password != NULL) {
|
||||||
// send registration_success
|
// send registration_success
|
||||||
$res = send_mail_registration_success($config["homeserver"], $first_name . " " . $last_name, $email, $username, $password, $config["howToURL"]);
|
$res = send_mail_registration_success($config["homeserver"], $first_name . " " . $last_name, $email, $username, $password, $config["howToURL"]);
|
||||||
@@ -161,7 +161,7 @@ background: rgba(255, 255, 255, 0.8);
|
|||||||
print("</head><body>");
|
print("</head><body>");
|
||||||
print("<h1>" . $language["REGISTRATION_FAILED"] . "</h1>");
|
print("<h1>" . $language["REGISTRATION_FAILED"] . "</h1>");
|
||||||
print("<p>" . $e->getMessage() . "</p>");
|
print("<p>" . $e->getMessage() . "</p>");
|
||||||
print("<a href=\"" . $config["webroot"] . "/register.php" . "\">Zur Registrierungsseite</a>");
|
print("<a href=\"" . $config["webroot"] . "/index.php" . "\">Zur Registrierungsseite</a>");
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
Reference in New Issue
Block a user