new database scheme

This commit is contained in:
vincent 2025-04-14 15:51:52 +02:00
parent 0add759fe1
commit fb24f71956
5 changed files with 59 additions and 5 deletions

View file

@ -18,7 +18,7 @@ if(!isset($_COOKIE[$cookie_name])) {
die("Connection failed: " . $conn->connect_error); die("Connection failed: " . $conn->connect_error);
} }
$sql = "SELECT * FROM smz_sessions WHERE sessionId='$sessionId' AND expiry > ".time()." "; $sql = "SELECT * FROM smz_auth_sessions WHERE sessionId='$sessionId' AND expiry > ".time()." ";
$result = $conn->query($sql); $result = $conn->query($sql);
if ($result->num_rows > 0) { if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) { while($row = $result->fetch_assoc()) {
@ -34,7 +34,7 @@ if(!isset($_COOKIE[$cookie_name])) {
if ($conn->connect_error) { if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error); die("Connection failed: " . $conn->connect_error);
} }
$sql = "SELECT email, username FROM smz_users WHERE id='$uid' AND active = 1"; $sql = "SELECT email, username FROM smz_auth_users WHERE id='$uid' AND active = 1";
$result = $conn->query($sql); $result = $conn->query($sql);
$conn->close(); $conn->close();
if ($result->num_rows > 0) { if ($result->num_rows > 0) {

View file

@ -13,7 +13,7 @@ $conn = new mysqli($dbservername, $dbusername, $dbpassword, $dbname);
if ($conn->connect_error) { if ($conn->connect_error) {
die("Server Error"); die("Server Error");
} }
$sql = "SELECT id, password_hash, active FROM smz_users WHERE id='$uid' OR email='$uid'"; $sql = "SELECT id, password_hash, active FROM smz_auth_users WHERE id='$uid' OR email='$uid'";
$result = $conn->query($sql); $result = $conn->query($sql);
$conn->close(); $conn->close();
if ($result->num_rows > 0) { if ($result->num_rows > 0) {
@ -52,7 +52,7 @@ function createSession($uid){
if ($conn->connect_error) { if ($conn->connect_error) {
die("Server Error"); die("Server Error");
} }
$sql = "INSERT INTO smz_sessions (sessionId, uid, creation, expiry, active) VALUES ('$sessionID', '$uid', '". time() ."', '$expiry', TRUE)"; $sql = "INSERT INTO smz_auth_sessions (sessionId, uid, creation, expiry, active) VALUES ('$sessionID', '$uid', '". time() ."', '$expiry', TRUE)";
if ($conn->query($sql) === TRUE) { if ($conn->query($sql) === TRUE) {
// echo "New record created successfully"; // echo "New record created successfully";

View file

@ -20,7 +20,7 @@ function cleanSessions(){
} }
// sql to delete a record // sql to delete a record
$sql = "DELETE FROM smz_sessions WHERE expiry < ".time()." OR active = 0"; $sql = "DELETE FROM smz_auth_sessions WHERE expiry < ".time()." OR active = 0";
if ($conn->query($sql) === TRUE) { if ($conn->query($sql) === TRUE) {
echo "Record deleted successfully"; echo "Record deleted successfully";

27
smz_auth_sessions.sql Normal file
View file

@ -0,0 +1,27 @@
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
CREATE TABLE `smz_auth_sessions` (
`sessionId` varchar(32) NOT NULL,
`uid` varchar(128) NOT NULL,
`creation` int(11) NOT NULL,
`expiry` int(11) NOT NULL,
`active` tinyint(1) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci;
ALTER TABLE `smz_auth_sessions`
ADD PRIMARY KEY (`sessionId`);
COMMIT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

27
smz_auth_users.sql Normal file
View file

@ -0,0 +1,27 @@
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
CREATE TABLE `smz_auth_users` (
`id` varchar(128) NOT NULL,
`email` varchar(255) NOT NULL,
`username` varchar(64) NOT NULL,
`password_hash` varchar(255) NOT NULL,
`active` tinyint(1) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci;
ALTER TABLE `smz_auth_users`
ADD PRIMARY KEY (`id`);
COMMIT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;