Implemented Register
This commit is contained in:
+38
-30
@@ -3,42 +3,50 @@ include 'connection.php';
|
||||
$conn = connectMysql();
|
||||
$userName = $_POST['username'];
|
||||
$passWord = $_POST['password'];
|
||||
$passWord_hashed = password_hash($passWord, PASSWORD_DEFAULT);
|
||||
|
||||
function query_addUser($conn, $uid, $upass) {
|
||||
$sql = "INSERT INTO account(C_ID,C_Password) VALUES( ? , ? )";
|
||||
$stmt = mysqli_stmt_init($conn);
|
||||
if (!mysqli_stmt_prepare($stmt, $sql)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
mysqli_stmt_bind_param($stmt, "ss", $uid, $upass);
|
||||
mysqli_stmt_execute($stmt);
|
||||
|
||||
$error = mysqli_stmt_errno($stmt);
|
||||
mysqli_stmt_close($stmt);
|
||||
return $error;
|
||||
}
|
||||
|
||||
|
||||
$query = "INSERT INTO account(C_ID,C_Password) VALUES('$userName','$passWord')";
|
||||
// if (isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])) {
|
||||
// $query = "INSERT INTO account(C_ID,C_Password) VALUES('$userName','$passWord')";
|
||||
if (isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])) {
|
||||
|
||||
// $secretKey = "6LdDrc8bAAAAAGhP99aDPJ2_6O7yrwIUc8yJLaQU";
|
||||
// $responseKey = $_POST['g-recaptcha-response'];
|
||||
// $userIP = $_SERVER['REMOTE_ADDR'];
|
||||
// $url = "https://www.google.com/recaptcha/api/siteverify?secret=$secretKey&response=$responseKey&remoteip=$userIP";
|
||||
// $response = file_get_contents($url);
|
||||
// $response = json_decode($response);
|
||||
$secretKey = "6LdDrc8bAAAAAGhP99aDPJ2_6O7yrwIUc8yJLaQU";
|
||||
$responseKey = $_POST['g-recaptcha-response'];
|
||||
$userIP = $_SERVER['REMOTE_ADDR'];
|
||||
$url = "https://www.google.com/recaptcha/api/siteverify?secret=$secretKey&response=$responseKey&remoteip=$userIP";
|
||||
$response = file_get_contents($url);
|
||||
$response = json_decode($response);
|
||||
|
||||
// if($response->success){
|
||||
// echo "Verification success.";
|
||||
// if ($conn->query($query) === TRUE) {
|
||||
// echo "<script> alert('New account created successfully!');location.href='register.php'; </script>";
|
||||
// } else {
|
||||
|
||||
// echo "<script> alert('Username already exists.');location.href='register.php'; </script>";
|
||||
// }
|
||||
// } else {
|
||||
// echo "<script> alert('reCAPTHCA verification failed, please try again.');location.href='register.php'; </script>";
|
||||
// return;
|
||||
// }
|
||||
if($response->success){
|
||||
echo "Verification success.";
|
||||
$error = query_addUser($conn, $userName, $passWord_hashed);
|
||||
if ($error === 0) {
|
||||
echo "<script> alert('New account created successfully!');location.href='../index.php'; </script>";
|
||||
} else {
|
||||
echo "<script> alert('Username already exists.');location.href='../index.php'; </script>";
|
||||
}
|
||||
} else {
|
||||
echo "<script> alert('reCAPTHCA verification failed, please try again.');location.href='../index.php'; </script>";
|
||||
return;
|
||||
}
|
||||
|
||||
// } else {
|
||||
// echo "<script> alert('Please click reCAPTHCA to verify.');location.href='register.php'; </script>";
|
||||
// return;
|
||||
// }
|
||||
|
||||
// TODO delete later
|
||||
if ($conn->query($query) === TRUE) {
|
||||
echo "<script> alert('New account created successfully!');location.href='register.php'; </script>";
|
||||
} else {
|
||||
|
||||
echo "<script> alert('Username already exists.');location.href='register.php'; </script>";
|
||||
echo "<script> alert('Please click reCAPTHCA to verify.');location.href='../index.php'; </script>";
|
||||
return;
|
||||
}
|
||||
|
||||
$conn->close();
|
||||
|
||||
Reference in New Issue
Block a user