Basis Implementierung der Formulare

Bisher kein Design, nur '@chaospott.de' Adresse, Model WIP entworfen
This commit is contained in:
m0veax
2023-04-14 23:35:18 +02:00
parent 81f612c7d0
commit f29c895afd
14 changed files with 1049 additions and 1 deletions

View File

@ -0,0 +1,62 @@
<?php
namespace App\Model;
use App\Entity\WireguardRequest;
class RequestsSqlite
{
private $db;
public function __construct()
{
$db_existed = false;
if(file_exists( 'Requests.db')) $db_existed = true;
$this->db = new \SQLite3('Requests.db');
if(!$db_existed) $this->initializeDatabase();
return $this;
}
private function initializeDatabase() {
$query = '
CREATE TABLE requests
(
ID INT PRIMARY KEY NOT NULL,
Email TEXT NOT NULL,
AuthToken TEXT NOT NULL,
ValidUntil TEXT NOT NULL,
PublicKey TEXT
)
';
return $this->query($query);
}
private function query($query) {
$ret = $this->db->exec($query);
if(!$ret) {
throw new \Exception($this->db->lastErrorMsg());
} else {
return true;
}
}
public function addRequest(WireguardRequest $wireguardRequest) {
$query = '
INSERT INTO requests (AuthToken, ValidUntil, Email) VALUES
(
'.$wireguardRequest->getAuthToken().',
'.$wireguardRequest->getValidUntil().',
'.$wireguardRequest->getEmail().'
);
';
return $this->query($query);
}
// TODO implement update validate ect
}