diff --git a/api/user_add.php b/api/user_add.php index cfd7f7b..55706bc 100644 --- a/api/user_add.php +++ b/api/user_add.php @@ -15,21 +15,37 @@ $conn = $databaseService->getConnection(); $data = json_decode(file_get_contents("php://input")); -$query = "INSERT INTO `users` +$query = "SELECT * FROM `users` WHERE email = '".trim($data->email)."'"; +$stmt = $conn->prepare($query); + +if($stmt->execute()) { + + if($stmt->rowCount()) { + http_response_code(400); + echo json_encode( + array( + "status" => 400, + "message" => "User exists" + )); + } else { + + $query = "INSERT INTO `users` (`id`, `first_name`, `last_name`, `email`, `phone`, `address`, `city`, `zip_code`, `province`, `password`) VALUES (NULL, '".trim($data->first_name)."', '".trim($data->last_name)."', '".trim($data->email)."', '".trim($data->phone)."', '".trim($data->address)."', '".trim($data->city)."', '".trim($data->zip_code)."', '".trim($data->province)."', '".md5(trim($data->password))."')"; -$stmt = $conn->prepare($query); - -if($stmt->execute()) { - http_response_code(200); - echo json_encode( - array( - "status" => 200, - "id" => $conn->lastInsertId() - )); + $stmt = $conn->prepare($query); + + if($stmt->execute()) { + http_response_code(200); + echo json_encode( + array( + "status" => 200, + "id" => $conn->lastInsertId() + )); + } + } } else { http_response_code(400); echo json_encode( diff --git a/components/account/account.html b/components/account/account.html index c90dc2d..0783f67 100644 --- a/components/account/account.html +++ b/components/account/account.html @@ -50,28 +50,96 @@ } ?> -