added class mxDatabase; store credentials; implement login.php
This commit is contained in:
@@ -40,47 +40,33 @@ try {
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "SELECT COUNT(*) FROM registrations WHERE admin_token = '" . $token
|
||||
. "' AND state = " . RegisterState::PendingAdminVerify . " LIMIT 1;";
|
||||
$res = $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, username, note, email FROM registrations WHERE admin_token = '" . $token
|
||||
. "' AND state = " . RegisterState::PendingAdminVerify . " LIMIT 1;";
|
||||
foreach ($db->query($sql) as $row) {
|
||||
// will only be executed once
|
||||
$first_name = $row["first_name"];
|
||||
$last_name = $row["last_name"];
|
||||
$username = $row["username"];
|
||||
$note = $row["note"];
|
||||
$email = $row["email"];
|
||||
}
|
||||
} else {
|
||||
$user = $mx_db->getUserForApproval($token);
|
||||
if ($user == NULL) {
|
||||
throw new Exception($language["UNKNOWN_TOKEN"]);
|
||||
}
|
||||
|
||||
$first_name = $user["first_name"];
|
||||
$last_name = $user["last_name"];
|
||||
$username = $user["username"];
|
||||
$note = $user["note"];
|
||||
$email = $user["email"];
|
||||
|
||||
if ($action == RegisterState::RegistrationAccepted) {
|
||||
$db->exec("UPDATE registrations SET state = " . RegisterState::PendingRegistration
|
||||
. " WHERE admin_token = '" . $token. "';");
|
||||
$mx_db->setRegistrationStateAdmin(RegisterState::PendingRegistration, $token);
|
||||
|
||||
// register user
|
||||
require_once("../MatrixConnection.php");
|
||||
$mxConn = new MatrixConnection($homeserver, $access_token);
|
||||
|
||||
// generate a password with 8 characters
|
||||
$password = bin2hex(openssl_random_pseudo_bytes(4));
|
||||
|
||||
$res = $mxConn->register($username, $password, $registration_shared_secret);
|
||||
if ($res) {
|
||||
$password = addUser($first_name, $last_name, $username, $email);
|
||||
if ($password != NULL) {
|
||||
// send registration_success
|
||||
$res = send_mail_registration_success($homeserver, $first_name . " " . $last_name, $email, $username, $password, $howToURL);
|
||||
if ($res) {
|
||||
$db->exec("UPDATE registrations SET state = " . RegisterState::AllDone
|
||||
. " WHERE admin_token = '" . $token. "';");
|
||||
$mx_db->setRegistrationStateAdmin(RegisterState::AllDone, $token);
|
||||
} else {
|
||||
$db->exec("UPDATE registrations SET state = " . RegisterState::PendingSendRegistrationMail
|
||||
. " WHERE admin_token = '" . $token. "';");
|
||||
$mx_db->setRegistrationStateAdmin(RegisterState::PendingSendRegistrationMail, $token);
|
||||
}
|
||||
} else {
|
||||
send_mail_registration_allowed_but_failed($homeserver, $first_name . " " . $last_name, $email);
|
||||
@@ -96,8 +82,7 @@ try {
|
||||
print("<h1>" . $language["ADMIN_VERIFY_SITE_TITLE"] . "</h1>");
|
||||
print("<p>" . $language["ADMIN_REGISTER_ACCEPTED_BODY"] . "</p>");
|
||||
} elseif ($action == RegisterState::RegistrationDeclined) {
|
||||
$db->exec("UPDATE registrations SET state = " . RegisterState::RegistrationDeclined
|
||||
. " WHERE admin_token = '" . $token. "';");
|
||||
$mx_db->setRegistrationStateAdmin(RegisterState::RegistrationDeclined, $token);
|
||||
send_mail_registration_decline($homeserver, $first_name . " " . $last_name, $email, $decline_reason);
|
||||
print("<title>" . $language["ADMIN_VERIFY_SITE_TITLE"] . "</title>");
|
||||
print("</head><body>");
|
||||
|
||||
Reference in New Issue
Block a user