62 lines
1.4 KiB
PHP
62 lines
1.4 KiB
PHP
<?php
|
|
require_once "../include.php";
|
|
|
|
// /home/cradle2careertxxyz/portal/dashboard/core/api/php/init.php
|
|
|
|
// if (empty($_POST["name"])) {
|
|
// die("Name is required");
|
|
// }
|
|
|
|
if ( ! filter_var($_POST["email"], FILTER_VALIDATE_EMAIL)) {
|
|
die("Valid email is required");
|
|
}
|
|
|
|
if (strlen($_POST["password"]) < 8) {
|
|
die("Password must be at least 8 characters");
|
|
}
|
|
|
|
if ( ! preg_match("/[a-z]/i", $_POST["password"])) {
|
|
die("Password must contain at least one letter");
|
|
}
|
|
|
|
if ( ! preg_match("/[0-9]/", $_POST["password"])) {
|
|
die("Password must contain at least one number");
|
|
}
|
|
|
|
if ($_POST["password"] !== $_POST["password_confirmation"]) {
|
|
die("Passwords must match");
|
|
}
|
|
|
|
$password_hash = password_hash($_POST["password"], PASSWORD_DEFAULT);
|
|
$mysqli = func_get_database();
|
|
$sql = "INSERT INTO " . $GLOBALS["AUTH_USER_TABLE"] . " (name, email, username, password_hash) VALUES (?, ?, ?, ?)";
|
|
$stmt = $mysqli->stmt_init();
|
|
if ( ! $stmt->prepare($sql)) {
|
|
die("SQL error: " . $mysqli->error);
|
|
}
|
|
|
|
$stmt->bind_param("ssss",
|
|
$_POST["name"],
|
|
$_POST["email"],
|
|
$_POST["username"],
|
|
$password_hash);
|
|
|
|
if ($stmt->execute()) {
|
|
header("Location: signup-success.html");
|
|
exit;
|
|
} else {
|
|
if ($mysqli->errno === 1062) {
|
|
die("email already taken");
|
|
} else {
|
|
die($mysqli->error . " " . $mysqli->errno);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|