From 766cacd40f1118b41db4240452a2818d71b9de48 Mon Sep 17 00:00:00 2001 From: Yasen Pramatarov Date: Thu, 27 Jun 2024 14:03:30 +0300 Subject: [PATCH] Initial version of jilo-web, web interface to Jilo. --- .gitignore | 1 + jilo-web/config.apache | 0 jilo-web/config.nginx | 0 jilo-web/install.sh | 3 ++ jilo-web/jilo-web.conf | 0 jilo-web/jilo-web.schema | 5 +++ jilo-web/public_html/classes/database.php | 25 +++++++++++++ jilo-web/public_html/classes/user.php | 37 +++++++++++++++++++ jilo-web/public_html/index.php | 8 ++++ jilo-web/public_html/login.php | 30 +++++++++++++++ jilo-web/public_html/logout.php | 14 +++++++ jilo-web/public_html/register.php | 29 +++++++++++++++ jilo-web/public_html/templates/all.css | 25 +++++++++++++ jilo-web/public_html/templates/body.php | 1 + jilo-web/public_html/templates/footer.php | 5 +++ jilo-web/public_html/templates/form-login.php | 7 ++++ .../public_html/templates/form-register.php | 7 ++++ jilo-web/public_html/templates/header.php | 35 ++++++++++++++++++ 18 files changed, 232 insertions(+) create mode 100644 jilo-web/config.apache create mode 100644 jilo-web/config.nginx create mode 100755 jilo-web/install.sh create mode 100644 jilo-web/jilo-web.conf create mode 100644 jilo-web/jilo-web.schema create mode 100644 jilo-web/public_html/classes/database.php create mode 100644 jilo-web/public_html/classes/user.php create mode 100644 jilo-web/public_html/index.php create mode 100644 jilo-web/public_html/login.php create mode 100644 jilo-web/public_html/logout.php create mode 100644 jilo-web/public_html/register.php create mode 100644 jilo-web/public_html/templates/all.css create mode 100644 jilo-web/public_html/templates/body.php create mode 100644 jilo-web/public_html/templates/footer.php create mode 100644 jilo-web/public_html/templates/form-login.php create mode 100644 jilo-web/public_html/templates/form-register.php create mode 100644 jilo-web/public_html/templates/header.php diff --git a/.gitignore b/.gitignore index c09d55f..4c2e4d1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ *.log *.log.* jilo.db +jilo-web.db packaging/deb-package/ packaging/rpm-package/ diff --git a/jilo-web/config.apache b/jilo-web/config.apache new file mode 100644 index 0000000..e69de29 diff --git a/jilo-web/config.nginx b/jilo-web/config.nginx new file mode 100644 index 0000000..e69de29 diff --git a/jilo-web/install.sh b/jilo-web/install.sh new file mode 100755 index 0000000..e0389f5 --- /dev/null +++ b/jilo-web/install.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +echo 'todo install script' diff --git a/jilo-web/jilo-web.conf b/jilo-web/jilo-web.conf new file mode 100644 index 0000000..e69de29 diff --git a/jilo-web/jilo-web.schema b/jilo-web/jilo-web.schema new file mode 100644 index 0000000..d932839 --- /dev/null +++ b/jilo-web/jilo-web.schema @@ -0,0 +1,5 @@ +CREATE TABLE users ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + username TEXT NOT NULL UNIQUE, + password TEXT NOT NULL +); diff --git a/jilo-web/public_html/classes/database.php b/jilo-web/public_html/classes/database.php new file mode 100644 index 0000000..f83b589 --- /dev/null +++ b/jilo-web/public_html/classes/database.php @@ -0,0 +1,25 @@ +pdo = new PDO("sqlite:" . $dbFile); + $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + } catch (PDOException $e) { + throw new Exception('DB connection failed: ' . $e->getMessage()); + } + } + + public function getConnection() { + return $this-pdo; + } + +} + +?> diff --git a/jilo-web/public_html/classes/user.php b/jilo-web/public_html/classes/user.php new file mode 100644 index 0000000..3305202 --- /dev/null +++ b/jilo-web/public_html/classes/user.php @@ -0,0 +1,37 @@ +db = $database->getConnection(); + } + + public function register($username, $password) { + $hashedPassword = password_hash($password, PASSWORD_DEFAULT); + $query = $this->db->prepare("INSERT INTO users (username, password) VALUES (:username, :password)"); + $query->bindParam(':username', $username); + $query->bindParam(':password', $username); + + return $query->execute(); + } + + public function login($username, $password) { + $query = $this->db->prepare("SELECT * FROM users WHERE username = :username"); + $query->bindParam(':username', $username); + $query->execute(); + + $user = $query->fetch(PDO::FETCH_ASSOC); + if ( $user && password_verify($password, $user['password'])) { + session_start(); + $_SESSION['user_id'] = $user['id']; + $_SESSION['username'] = $user['username']; + return true; + } else { + return false; + } + } + +} + +?> diff --git a/jilo-web/public_html/index.php b/jilo-web/public_html/index.php new file mode 100644 index 0000000..295a788 --- /dev/null +++ b/jilo-web/public_html/index.php @@ -0,0 +1,8 @@ + diff --git a/jilo-web/public_html/login.php b/jilo-web/public_html/login.php new file mode 100644 index 0000000..410769a --- /dev/null +++ b/jilo-web/public_html/login.php @@ -0,0 +1,30 @@ +login($username, $password) ) { + echo "Login successful."; + } else { + echo "Login failed."; + } + } +} catch (Exception $e) { + $error = $e->getMessage(); +} + +include 'templates/header.php'; +include 'templates/form-login.php'; +include 'templates/footer.php'; + +?> + diff --git a/jilo-web/public_html/logout.php b/jilo-web/public_html/logout.php new file mode 100644 index 0000000..9bde4b1 --- /dev/null +++ b/jilo-web/public_html/logout.php @@ -0,0 +1,14 @@ + \ No newline at end of file diff --git a/jilo-web/public_html/register.php b/jilo-web/public_html/register.php new file mode 100644 index 0000000..54a8fab --- /dev/null +++ b/jilo-web/public_html/register.php @@ -0,0 +1,29 @@ +register($username, $password) ) { + echo "Registration successful."; + } else { + echo "Registration failed."; + } + } +} catch (Exception $e) { + $error = $e->getMessage(); +} + +include 'templates/header.php'; +include 'templates/form-register.php'; +include 'templates/footer.php'; + +?> diff --git a/jilo-web/public_html/templates/all.css b/jilo-web/public_html/templates/all.css new file mode 100644 index 0000000..e1565bf --- /dev/null +++ b/jilo-web/public_html/templates/all.css @@ -0,0 +1,25 @@ + +ul.menu { + list-style-type: none; + margin: 0; + margin-bottom: 10px; + padding: 0; + overflow: hidden; + background-color: #333; +} + +ul.menu li { + float: right; +} + +ul.menu li a { + display: block; + color: white; + text-align: center; + padding: 14px 16px; + text-decoration: none; +} + +ul.menu li a:hover { + background-color: #111; +} diff --git a/jilo-web/public_html/templates/body.php b/jilo-web/public_html/templates/body.php new file mode 100644 index 0000000..7ccbe49 --- /dev/null +++ b/jilo-web/public_html/templates/body.php @@ -0,0 +1 @@ + diff --git a/jilo-web/public_html/templates/footer.php b/jilo-web/public_html/templates/footer.php new file mode 100644 index 0000000..1f7ef79 --- /dev/null +++ b/jilo-web/public_html/templates/footer.php @@ -0,0 +1,5 @@ + + + + + diff --git a/jilo-web/public_html/templates/form-login.php b/jilo-web/public_html/templates/form-login.php new file mode 100644 index 0000000..5e5cbe3 --- /dev/null +++ b/jilo-web/public_html/templates/form-login.php @@ -0,0 +1,7 @@ + + +
+ + + +
diff --git a/jilo-web/public_html/templates/form-register.php b/jilo-web/public_html/templates/form-register.php new file mode 100644 index 0000000..3a2a4b6 --- /dev/null +++ b/jilo-web/public_html/templates/form-register.php @@ -0,0 +1,7 @@ + + +
+ + + +
diff --git a/jilo-web/public_html/templates/header.php b/jilo-web/public_html/templates/header.php new file mode 100644 index 0000000..f2342f7 --- /dev/null +++ b/jilo-web/public_html/templates/header.php @@ -0,0 +1,35 @@ +Error: $error

"; +} + +?> + + + + + + Jilo Web + + + + +