Added authentication functionality and simple role based model
This commit is contained in:
@@ -1,15 +1,22 @@
|
||||
<?php
|
||||
require 'db.php';
|
||||
require 'auth.php';
|
||||
|
||||
header('Content-Type: application/json');
|
||||
require_login();
|
||||
|
||||
$user_id = current_user_id();
|
||||
|
||||
$data = json_decode(file_get_contents('php://input'), true);
|
||||
if (!isset($data['name']) || empty(trim($data['name']))) {
|
||||
$name = trim($data['name'] ?? '');
|
||||
|
||||
if ($name === '') {
|
||||
http_response_code(400);
|
||||
echo json_encode(['error' => 'Project name is required']);
|
||||
echo json_encode(['success' => false, 'error' => 'Project name is required']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$stmt = $pdo->prepare("INSERT INTO projects (name) VALUES (?)");
|
||||
$stmt->execute([trim($data['name'])]);
|
||||
$stmt = $pdo->prepare("INSERT INTO projects (user_id, name) VALUES (?, ?)");
|
||||
$stmt->execute([$user_id, $name]);
|
||||
|
||||
echo json_encode(['success' => true, 'id' => $pdo->lastInsertId()]);
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user