From a0e070237077d9ea95d0309cbeb0aadce3d1cf02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=A2=E1=84=91=E1=85=B3=E1=86=AF=20=E1=84=82?= =?UTF-8?q?=E1=85=A9=E1=84=90=E1=85=B3=E1=84=87=E1=85=AE=E1=86=A8?= Date: Thu, 12 Jul 2018 11:27:17 +0900 Subject: [PATCH] Fix: revised php code to maestro register --- src/web/module/maestro_section_register.html | 75 ++++++++------------ src/web/server/maestro/add_maestro.php | 28 ++++---- src/web/server/maestro/check_id.php | 27 +++---- 3 files changed, 55 insertions(+), 75 deletions(-) diff --git a/src/web/module/maestro_section_register.html b/src/web/module/maestro_section_register.html index 125dba0..be46f0c 100644 --- a/src/web/module/maestro_section_register.html +++ b/src/web/module/maestro_section_register.html @@ -47,34 +47,26 @@ $(document).ready(function() { function check_id() { maestro_name = $("#maestro_name").val(); - let xhr = new XMLHttpRequest(); //new로 생성. - xhr.open('POST', './../server/maestro/check_id.php', true); - xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); - 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); + sendRequestServer( //url, sendParams, onSuccess, onFail, isDebugMode); + "./../server/maestro/check_id.php", + "maestro_name=" + maestro_name, - // if(replyJSON !== null) - // console.log(replyJSON); + (jsonData) => { + isAvailableID = true; + }, - // if(replyJSON["MaestroID"] !== undefined) - // console.log(replyJSON["MaestroID"]); + (errorMessage) => { + isAvailableID = false; - if(replyJSON !== null && replyJSON["Result"] !== undefined && replyJSON["Result"] === "ok") { - // sessionStorage.setItem("maestroID", replyJSON["MaestroID"]); - // location.href = './../maestro/main_menu.html'; - isAvailableID = true; - } else { - isAvailableID = false; - $("#error_message").val(replyJSON["ERROR"]); - $("#maestro_name").val(""); - $("#maestro_name").focus(); + if($("#error_message").length) { + $("#error_message").text(errorMessage); } - } - } + $("#maestro_name").val(""); + $("#maestro_name").focus(); + } + + ); } @@ -131,33 +123,26 @@ function register_account() { tab2.removeClass("activated"); tab3.addClass("activated"); - let xhr = new XMLHttpRequest(); //new로 생성. - xhr.open('POST', './../server/maestro/add_maestro.php', true); - xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); - 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); + sendRequestServer( //url, sendParams, onSuccess, onFail, isDebugMode); + "./../server/maestro/add_maestro.php", + "maestro_name=" + maestro_name + "&password=" + password + "&email=" + email + "&account_type=" + selectedAccountTypeValue, - // if(replyJSON !== null) - // console.log(replyJSON); + (jsonData) => { + isAvailableID = true; + }, - // if(replyJSON["MaestroID"] !== undefined) - // console.log(replyJSON["MaestroID"]); + (errorMessage) => { + isAvailableID = false; - if(replyJSON !== null && replyJSON["Result"] !== undefined && replyJSON["Result"] === "ok") { - // sessionStorage.setItem("maestroID", replyJSON["MaestroID"]); - // location.href = './../maestro/main_menu.html'; - isAvailableID = true; - } else { - isAvailableID = false; - $("#error_message").val(replyJSON["ERROR"]); - $("#maestro_name").val(""); - $("#maestro_name").focus(); + if($("#error_message").length) { + $("#error_message").text(errorMessage); } + + $("#maestro_name").val(""); + $("#maestro_name").focus(); } - } + + ); } diff --git a/src/web/server/maestro/add_maestro.php b/src/web/server/maestro/add_maestro.php index e88423f..20faabf 100644 --- a/src/web/server/maestro/add_maestro.php +++ b/src/web/server/maestro/add_maestro.php @@ -1,5 +1,8 @@ close(); + set_error_message($maestro_name." : 이미 등록된 마에스트로 계정입니다."); + send_result_fail(); exit; } @@ -28,13 +30,15 @@ addMaestro($maestro_name, $password, $email, $account_type); $maestroID = hasMaestroName($maestro_name); if($maestroID === null) { - send_error_message($replyJSON, $maestro_name." : 알 수 없는 이유로 마에스트로 계정 등록이 취소되었습니다."); + set_error_message($maestro_name." : 알 수 없는 이유로 마에스트로 계정 등록이 취소되었습니다."); + send_result_fail(); exit; } -$replyJSON["RESULT"] = "success"; -echo json_encode($replyJSON, JSON_UNESCAPED_UNICODE); -$db_conn->close(); +set_data("maestroList", $maestroList); +send_result_success(); +exit; + function hasMaestroName($maestroName) { @@ -42,7 +46,7 @@ function hasMaestroName($maestroName) { $query = "SELECT MaestroID FROM moty_maestro WHERE Name=?"; $stmt = $db_conn->prepare($query); - $stmt->bind_param('s', $maestroName); + $stmt->bind_param("s", $maestroName); $stmt->execute(); $stmt->bind_result($maestroID); // 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) VALUES (?, PASSWORD(?), ?, ?, 0, 0, NOW(), -1)"; $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(); } diff --git a/src/web/server/maestro/check_id.php b/src/web/server/maestro/check_id.php index a3bb472..a4ffc95 100644 --- a/src/web/server/maestro/check_id.php +++ b/src/web/server/maestro/check_id.php @@ -1,39 +1,30 @@ close(); + set_error_message($maestro_name." : 이미 등록된 마에스트로 계정입니다."); + send_result_fail(); exit; } -$replyJSON["Result"] = "ok"; -echo json_encode($replyJSON, JSON_UNESCAPED_UNICODE); -$db_conn->close(); +send_result_success(); exit; + function get_maestro_id($maestro_name) { global $db_conn; $query = "SELECT MaestroID FROM moty_maestro WHERE Name=?"; $stmt = $db_conn->prepare($query); - $stmt->bind_param('s', $maestro_name); + $stmt->bind_param("s", $maestro_name); $stmt->execute(); $stmt->bind_result($maestro_id); // while($stmt->fetch()) {