2023-11-06 16:38:18 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
|
|
$DB_SERVER = DB_ADDRESS;
|
|
|
|
$DB_USER = DB_USERNAME;
|
|
|
|
$DB_PASSWD = DB_PASSWORD;
|
|
|
|
$DB_BASE = DB_DATABASE;
|
|
|
|
|
|
|
|
$email = $_POST['email'];
|
|
|
|
$password = password_hash($_POST['password'], PASSWORD_DEFAULT);
|
|
|
|
$BCID = generate_bcid();
|
|
|
|
if (!validate_bcid($BCID)) {
|
|
|
|
die("Server-side error with your BCID #. Try again.");
|
|
|
|
}
|
2023-11-11 16:16:04 +00:00
|
|
|
|
|
|
|
// First: check if restraints will be broken
|
|
|
|
$sql = "SELECT * FROM accounts WHERE email = ?";
|
|
|
|
try {
|
|
|
|
$stmt = $pdo->prepare($sql);
|
|
|
|
$stmt->execute([$email]);
|
|
|
|
$result = $stmt->fetch();
|
|
|
|
|
|
|
|
if (!empty($result)) {
|
|
|
|
die("Email is already registered. (923)");
|
|
|
|
}
|
|
|
|
} catch (PDOException $e) {
|
|
|
|
http_response_code(500);
|
|
|
|
die("An error occured: $e");
|
|
|
|
}
|
2023-11-06 16:38:18 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
$sql = "INSERT INTO `accounts` (`id`, `email`, `password`, `verified`) VALUES (?, ?, ?, ?)";
|
|
|
|
try{
|
|
|
|
$stmt = $pdo->prepare($sql);
|
|
|
|
$stmt->execute([$BCID, $email, $password, 0]);
|
|
|
|
$result = $stmt->fetch();
|
2023-11-11 16:16:04 +00:00
|
|
|
echo "You've signed up!";
|
2023-11-06 16:38:18 +00:00
|
|
|
} catch (PDOException $e) {
|
|
|
|
http_response_code(500);
|
|
|
|
die("An error occured: $e");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(PDOException $e) {
|
|
|
|
die ("Connection failed: " . $e->getMessage());
|
|
|
|
}
|
|
|
|
|
|
|
|
$_SESSION["auth"] = true;
|
|
|
|
$_SESSION["id"] = $BCID;
|
|
|
|
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|
|
|
|
|
|
|
|
<h2>Sign up for ByeCorps ID</h2>
|
|
|
|
<form method="post">
|
2024-03-02 12:41:57 +00:00
|
|
|
<input type="email" required name="email" id="email" placeholder="Email">
|
|
|
|
<input type="password" required name="password" id="password" placeholder="Password">
|
2023-11-06 16:38:18 +00:00
|
|
|
<button type="submit">Sign up</button>
|
|
|
|
</form>
|