Webservices

This commit is contained in:
2026-01-31 18:01:24 +01:00
parent e1c752fcf8
commit 2d2fc24d71
35 changed files with 3531 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
<?php
class Token {
private $conn;
private $table_name = "token";
public $userId;
public $user;
public $token;
public $created;
public $expires;
// constructor with $db as database connection
public function __construct($db){
$this->conn = $db;
}
function create(){
$params = "user_id=:userId, token=:token, created=:created, expires=:expires";
$query = "INSERT INTO " . $this->table_name . "
SET " . $params;
// prepare query
$stmt = $this->conn->prepare($query);
$this->created=(new \DateTime())->format('Y-m-d H:i:s');
$this->expires=(new \DateTime())->add(new DateInterval('P1Y3M'))->format('Y-m-d H:i:s');
$this->token=md5(sprintf('%d-%s', $this->userId, $this->expires));
// bind values
$stmt->bindParam(":userId", $this->userId);
$stmt->bindParam(":token", $this->token);
$stmt->bindParam(":created", $this->created);
$stmt->bindParam(":expires", $this->expires);
// execute query
if($stmt->execute()){
return true;
}
return false;
}
}