Files
Travel-tracker/api/auth/register.php
Bram Prieshof e88269224c Added backend and refactored frond-end to support it.
* Removed unecesery home page
* Added PHP Api that provides auth and replaces the json-server for data storage
* Added support for alternate geocode-api
* Added registration  page
2025-05-27 00:42:00 +02:00

35 lines
1.0 KiB
PHP

<?php
require_once 'config/auth.php';
if (!$AllowUserRegistration){
echo json_encode(['message' => 'Endpoint not found']);
http_response_code(404);
die;
}
require_once 'config/db.php';
$data = json_decode(file_get_contents("php://input"));
if (isset($data->username) && isset($data->password) && isset($data->name)) {
$username = $data->username;
$password = password_hash($data->password, PASSWORD_BCRYPT);
$name = $data->name;
$query = "INSERT INTO users (username, password, name) VALUES (:username, :password, :name)";
$stmt = $pdo->prepare($query);
$stmt->bindParam(':username', $username);
$stmt->bindParam(':password', $password);
$stmt->bindParam(':name', $name);
if ($stmt->execute()) {
echo json_encode(['message' => 'User registered successfully']);
} else {
echo json_encode(['message' => 'User registration failed']);
}
} else {
http_response_code(400);
echo json_encode(['message' => 'Missing name, username or password']);
}
?>