implement hasUser(localpart), RegisterState add verify{_admin}.php
- fixes
This commit is contained in:
86
public/verify.php
Normal file
86
public/verify.php
Normal file
@@ -0,0 +1,86 @@
|
||||
<html>
|
||||
<head>
|
||||
<?php
|
||||
require_once "../language.php";
|
||||
if (!file_exists("../config.php")) {
|
||||
print($language["NO_CONFIGURATION"]);
|
||||
exit();
|
||||
}
|
||||
require_once "../config.php";
|
||||
require_once "../mail_templates.php";
|
||||
|
||||
// enforce admin via https
|
||||
if (!isset($_SERVER['HTTPS'])) {
|
||||
header('Location: https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'], true, 301);
|
||||
exit();
|
||||
}
|
||||
|
||||
session_start();
|
||||
|
||||
try {
|
||||
if ($_SERVER["REQUEST_METHOD"] != "GET") {
|
||||
throw new Exception("Method not allowed");
|
||||
}
|
||||
if (!isset($_GET["t"])) {
|
||||
throw new Exception($language["UNKNOWN_TOKEN"]);
|
||||
}
|
||||
$token = filter_var($_GET["t"], FILTER_SANITIZE_STRING);
|
||||
|
||||
require_once("../database.php");
|
||||
|
||||
$sql = "SELECT COUNT(*) FROM registrations WHERE verify_token = '" . $token . "' LIMIT 1;";
|
||||
$res = $db->query($sql);
|
||||
|
||||
$first_name = NULL; $last_name = NULL; $note = NULL; $email = NULL; $admin_token = NULL;
|
||||
|
||||
if ($res->fetchColumn() > 0) {
|
||||
$sql = "SELECT first_name, last_name, note, email, admin_token FROM registrations WHERE verify_token = '" . $token . "' LIMIT 1;";
|
||||
foreach ($db->query($sql) as $row) {
|
||||
// will only be executed once
|
||||
$first_name = $row["first_name"];
|
||||
$last_name = $row["last_name"];
|
||||
$note = $row["note"];
|
||||
$email = $row["email"];
|
||||
$admin_token = $row["admin_token"];
|
||||
}
|
||||
} else {
|
||||
throw new Exception($language["UNKNOWN_TOKEN"]);
|
||||
}
|
||||
|
||||
require_once("../MatrixConnection.php");
|
||||
$adminUrl = $webroot . "/admin_verify.php?t=" . $admin_token;
|
||||
$mxConn = new MatrixConnection($homeserver, $access_token);
|
||||
$mxMsg = new MatrixMessage();
|
||||
$mxMsg->set_body($first_name . ' ' . $last_name . "möchte sich registrieren und hat folgende Notiz hinterlassen:\r\n"
|
||||
. $note . "\r\n"
|
||||
. "Zum Bearbeiten hier klicken:\r\n" . $adminUrl);
|
||||
$mxMsg->set_formatted_body($first_name . ' ' . $last_name . " möchte sich registrieren und hat folgende Notiz hinterlassen:<br />"
|
||||
. $note . "<br />"
|
||||
. "Zum Bearbeiten <a href=\"". $adminUrl . "\">hier</a> klicken");
|
||||
$mxMsg->set_type("m.text");
|
||||
$response = $mxConn->send($register_room, $mxMsg);
|
||||
|
||||
if ($response) {
|
||||
$message = $language["SEND_MATRIX_FAIL"];
|
||||
}
|
||||
$db->exec("UPDATE registrations SET state = " .
|
||||
($response ? RegisterState::PendingAdminVerify : RegisterState::PendingAdminSend)
|
||||
. " WHERE verify_token = \"" . $verify_token. "\";");
|
||||
|
||||
send_mail_pending_approval($homeserver, $first_name . " " . $last_name, $email);
|
||||
|
||||
print("<title>" . $language["VERIFICATION_SUCEEDED"] . "</title>");
|
||||
print("</head><body>");
|
||||
print("<h1>" . $language["VERIFICATION_SUCEEDED"] . "</h1>");
|
||||
print("<p>" . $language["VERIFICATION_SUCCESS_BODY"] . "</p>");
|
||||
print("<a href=\"" . $webroot . "/register.php" . "\">Zur Registrierungsseite</a>");
|
||||
} catch (Exception $e) {
|
||||
print("<title>" . $language["VERIFICATION_FAILED"] . "</title>");
|
||||
print("</head><body>");
|
||||
print("<h1>" . $language["VERIFICATION_FAILED"] . "</h1>");
|
||||
print("<p>" . $e->getMessage() . "</p>");
|
||||
print("<a href=\"" . $webroot . "/register.php" . "\">Zur Registrierungsseite</a>");
|
||||
}
|
||||
?>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user