Fix: revised php code to maestro register

This commit is contained in:
2018-07-12 11:27:17 +09:00
parent 07b65f004b
commit a0e0702370
3 changed files with 55 additions and 75 deletions
+30 -45
View File
@@ -47,34 +47,26 @@ $(document).ready(function() {
function check_id() { function check_id() {
maestro_name = $("#maestro_name").val(); maestro_name = $("#maestro_name").val();
let xhr = new XMLHttpRequest(); //new로 생성. sendRequestServer( //url, sendParams, onSuccess, onFail, isDebugMode);
xhr.open('POST', './../server/maestro/check_id.php', true); "./../server/maestro/check_id.php",
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); "maestro_name=" + maestro_name,
xhr.send("maestro_name=" + maestro_name);
xhr.onload = function() {
if(xhr.readyState === 4 && xhr.status === 200) {
let replyJSON = JSON.parse(xhr.responseText);
// console.log(replyJSON);
// if(replyJSON !== null) (jsonData) => {
// console.log(replyJSON); isAvailableID = true;
},
// if(replyJSON["MaestroID"] !== undefined) (errorMessage) => {
// console.log(replyJSON["MaestroID"]); isAvailableID = false;
if(replyJSON !== null && replyJSON["Result"] !== undefined && replyJSON["Result"] === "ok") { if($("#error_message").length) {
// sessionStorage.setItem("maestroID", replyJSON["MaestroID"]); $("#error_message").text(errorMessage);
// location.href = './../maestro/main_menu.html';
isAvailableID = true;
} else {
isAvailableID = false;
$("#error_message").val(replyJSON["ERROR"]);
$("#maestro_name").val("");
$("#maestro_name").focus();
} }
}
}
$("#maestro_name").val("");
$("#maestro_name").focus();
}
);
} }
@@ -131,33 +123,26 @@ function register_account() {
tab2.removeClass("activated"); tab2.removeClass("activated");
tab3.addClass("activated"); tab3.addClass("activated");
let xhr = new XMLHttpRequest(); //new로 생성. sendRequestServer( //url, sendParams, onSuccess, onFail, isDebugMode);
xhr.open('POST', './../server/maestro/add_maestro.php', true); "./../server/maestro/add_maestro.php",
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); "maestro_name=" + maestro_name + "&password=" + password + "&email=" + email + "&account_type=" + selectedAccountTypeValue,
xhr.send("maestro_name=" + maestro_name + "&password=" + password + "&email=" + email + "&account_type=" + selectedAccountTypeValue);
xhr.onload = function() {
if(xhr.readyState === 4 && xhr.status === 200) {
let replyJSON = JSON.parse(xhr.responseText);
// console.log(replyJSON);
// if(replyJSON !== null) (jsonData) => {
// console.log(replyJSON); isAvailableID = true;
},
// if(replyJSON["MaestroID"] !== undefined) (errorMessage) => {
// console.log(replyJSON["MaestroID"]); isAvailableID = false;
if(replyJSON !== null && replyJSON["Result"] !== undefined && replyJSON["Result"] === "ok") { if($("#error_message").length) {
// sessionStorage.setItem("maestroID", replyJSON["MaestroID"]); $("#error_message").text(errorMessage);
// location.href = './../maestro/main_menu.html';
isAvailableID = true;
} else {
isAvailableID = false;
$("#error_message").val(replyJSON["ERROR"]);
$("#maestro_name").val("");
$("#maestro_name").focus();
} }
$("#maestro_name").val("");
$("#maestro_name").focus();
} }
}
);
} }
</script> </script>
+16 -12
View File
@@ -1,5 +1,8 @@
<?php <?php
header('Content-Type: application/json'); header("Content-Type: application/json");
include "./../lib/send_reply_json.php";
include "./../setup/connect_db.php";
$maestro_name = $_POST["maestro_name"]; $maestro_name = $_POST["maestro_name"];
$password = $_POST["password"]; $password = $_POST["password"];
@@ -7,20 +10,19 @@ $email = $_POST["email"];
$account_type = $_POST["account_type"]; $account_type = $_POST["account_type"];
/* /*
if(!is_numeric($enterCode)) { if(!is_numeric($enterCode)) {
send_error_code('생년월일이 숫자가 아닙니다. : '.$enterCode); send_error_code("생년월일이 숫자가 아닙니다. : ".$enterCode);
exit; exit;
} else if(strlen($enterCode) != 6) { } else if(strlen($enterCode) != 6) {
send_error_code('6자리 숫자값을 정확히 입력하세요 : YYMMDD (예 : 120131) : '.$enterCode); send_error_code("6자리 숫자값을 정확히 입력하세요 : YYMMDD (예 : 120131) : ".$enterCode);
exit; exit;
} }
*/ */
include "./../setup/connect_db.php";
$maestroID = hasMaestroName($maestro_name); $maestroID = hasMaestroName($maestro_name);
if($maestroID !== null) { if($maestroID !== null) {
send_error_message($replyJSON, $maestro_name." : 이미 등록된 마에스트로 계정입니다."); set_error_message($maestro_name." : 이미 등록된 마에스트로 계정입니다.");
// $db_conn->close(); send_result_fail();
exit; exit;
} }
@@ -28,13 +30,15 @@ addMaestro($maestro_name, $password, $email, $account_type);
$maestroID = hasMaestroName($maestro_name); $maestroID = hasMaestroName($maestro_name);
if($maestroID === null) { if($maestroID === null) {
send_error_message($replyJSON, $maestro_name." : 알 수 없는 이유로 마에스트로 계정 등록이 취소되었습니다."); set_error_message($maestro_name." : 알 수 없는 이유로 마에스트로 계정 등록이 취소되었습니다.");
send_result_fail();
exit; exit;
} }
$replyJSON["RESULT"] = "success"; set_data("maestroList", $maestroList);
echo json_encode($replyJSON, JSON_UNESCAPED_UNICODE); send_result_success();
$db_conn->close(); exit;
function hasMaestroName($maestroName) { function hasMaestroName($maestroName) {
@@ -42,7 +46,7 @@ function hasMaestroName($maestroName) {
$query = "SELECT MaestroID FROM moty_maestro WHERE Name=?"; $query = "SELECT MaestroID FROM moty_maestro WHERE Name=?";
$stmt = $db_conn->prepare($query); $stmt = $db_conn->prepare($query);
$stmt->bind_param('s', $maestroName); $stmt->bind_param("s", $maestroName);
$stmt->execute(); $stmt->execute();
$stmt->bind_result($maestroID); $stmt->bind_result($maestroID);
// while($stmt->fetch()) // while($stmt->fetch())
@@ -59,7 +63,7 @@ function addMaestro($maestro_name, $password, $email, $account_type) {
INSERT INTO moty_Maestro (Name, Password, Email, AccountType, ActivateStatus, UserCount, AcceptClausesDateTime, MaestroTestID) INSERT INTO moty_Maestro (Name, Password, Email, AccountType, ActivateStatus, UserCount, AcceptClausesDateTime, MaestroTestID)
VALUES (?, PASSWORD(?), ?, ?, 0, 0, NOW(), -1)"; VALUES (?, PASSWORD(?), ?, ?, 0, 0, NOW(), -1)";
$stmt = $db_conn->prepare($query); $stmt = $db_conn->prepare($query);
$stmt->bind_param('sssi', $maestro_name, $password, $email, $account_type); $stmt->bind_param("sssi", $maestro_name, $password, $email, $account_type);
$stmt->execute(); $stmt->execute();
} }
+9 -18
View File
@@ -1,39 +1,30 @@
<?php <?php
header('Content-Type: application/json'); header("Content-Type: application/json");
include "./../lib/send_reply_json.php";
include "./../setup/connect_db.php";
$maestro_name = $_POST["maestro_name"]; $maestro_name = $_POST["maestro_name"];
/*
if(!is_numeric($enterCode)) {
send_error_code('생년월일이 숫자가 아닙니다. : '.$enterCode);
exit;
} else if(strlen($enterCode) != 6) {
send_error_code('6자리 숫자값을 정확히 입력하세요 : YYMMDD (예 : 120131) : '.$enterCode);
exit;
}
*/
include "./../setup/connect_db.php";
$maestro_id = get_maestro_id($maestro_name); $maestro_id = get_maestro_id($maestro_name);
if($maestro_id !== null) { if($maestro_id !== null) {
$replyJSON["ERROR"] = "등록된 마에스트로 아이디가 있습니다"; set_error_message($maestro_name." : 이미 등록된 마에스트로 계정입니다.");
echo json_encode($replyJSON, JSON_UNESCAPED_UNICODE); send_result_fail();
$db_conn->close();
exit; exit;
} }
$replyJSON["Result"] = "ok"; send_result_success();
echo json_encode($replyJSON, JSON_UNESCAPED_UNICODE);
$db_conn->close();
exit; exit;
function get_maestro_id($maestro_name) { function get_maestro_id($maestro_name) {
global $db_conn; global $db_conn;
$query = "SELECT MaestroID FROM moty_maestro WHERE Name=?"; $query = "SELECT MaestroID FROM moty_maestro WHERE Name=?";
$stmt = $db_conn->prepare($query); $stmt = $db_conn->prepare($query);
$stmt->bind_param('s', $maestro_name); $stmt->bind_param("s", $maestro_name);
$stmt->execute(); $stmt->execute();
$stmt->bind_result($maestro_id); $stmt->bind_result($maestro_id);
// while($stmt->fetch()) { // while($stmt->fetch()) {