add saving registrations to sqlite

This commit is contained in:
2018-02-11 20:22:40 +01:00
parent f306dda4f9
commit bd06342ccf
3 changed files with 41 additions and 5 deletions

View File

@@ -1,6 +1,6 @@
<?php <?php
$homeserver = "example.com"; $homeserver = "example.com";
$access_token = "To be used for sending the registration notification"; $access_token = "To be used for sending the registration notification";
$register_room = "$registerRoomID:example.com"; $register_room = '"$registerRoomID:example.com';
$registration_shared_secret = "To be used for actually register the user"; $registration_shared_secret = "To be used for actually register the user";
?> ?>

29
database.php Normal file
View File

@@ -0,0 +1,29 @@
<?php
$db_file = "db_file.sqlite";
// create database file when not existent yet
if (!file_exists($db_file)) {
$db = new PDO('sqlite:' . $db_file);
$db->exec("CREATE TABLE registrations(
id INTEGER PRIMARY KEY AUTOINCREMENT,
first_name TEXT,
last_name TEXT,
username TEXT,
note TEXT,
email TEXT,
verify_token TEXT,
request_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP)");
}
else {
// establish connection
$db = new PDO('sqlite:' . $db_file);
$ins_stmt = $db->prepare("INSERT INTO registrations
(first_name, last_name, note, email, username, verify_token)
VALUES (:first_name, :last_name, :note, :email, :username, :verify_token);
}
// set writeable when not set already
if (!is_writable($db_file)) {
chmod($db_file, 0777);
}
?>

View File

@@ -41,15 +41,22 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {
} }
else { else {
// check valid password // check valid password
require_once("../database.php");
$ins_stmt->bindParam(':first_name', $first);
$ins_stmt->bindParam(':last_name', $last);
$ins_stmt->bindParam(':username', $user);
$ins_stmt->bindParam(':note', $note);
$ins_stmt->bindParam(':email', $email);
$ins_stmt->bindParam(':verify_token ', $vToken);
$first = filter_var($_POST["first_name"], FILTER_SANITIZE_STRING); $first = filter_var($_POST["first_name"], FILTER_SANITIZE_STRING);
$last = filter_var($_POST["last_name"], FILTER_SANITIZE_STRING); $last = filter_var($_POST["last_name"], FILTER_SANITIZE_STRING);
$user = filter_var($_POST["username"], FILTER_SANITIZE_STRING); $user = filter_var($_POST["username"], FILTER_SANITIZE_STRING);
$pass = filter_var($_POST["password"], FILTER_SANITIZE_STRING);
$email = filter_var($_POST["email"], FILTER_VALIDATE_EMAIL);
$note = filter_var($_POST["note"], FILTER_SANITIZE_STRING); $note = filter_var($_POST["note"], FILTER_SANITIZE_STRING);
$email = filter_var($_POST["email"], FILTER_VALIDATE_EMAIL);
$vToken= bin2hex(random_bytes(16));
$ins_stmt->execute();
$success = true; $success = true;
} }
if ($success) { if ($success) {
@@ -67,7 +74,7 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {
} else { } else {
$_SESSION["token"] = bin2hex(random_bytes(16)); $_SESSION["token"] = bin2hex(random_bytes(16));
?> ?>
<title>Registriere dich für cg-s.tk</title> <title>Registriere dich für <?php echo $homeserver; ?></title>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css" rel="stylesheet"> <link href="//netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css" rel="stylesheet">
<style> <style>
body{ body{