From ef2218bfa6bca3359301d5763d8174f902dac492 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: Sun, 27 May 2018 22:16:57 +0900 Subject: [PATCH] Add: MaestroID for login --- src/game/lib/db_connect_manager.js | 4 +- src/game/login/login.js | 74 ++++++++++++++++-------------- src/web/server/user/login.php | 20 +++++++- 3 files changed, 60 insertions(+), 38 deletions(-) diff --git a/src/game/lib/db_connect_manager.js b/src/game/lib/db_connect_manager.js index d0b0943..03b1ade 100644 --- a/src/game/lib/db_connect_manager.js +++ b/src/game/lib/db_connect_manager.js @@ -47,7 +47,7 @@ class DBConnectManager { return "../"; } - requestCheckUserLogin(userName, enterCode, onSucceededListener, onFailedListener) { + requestCheckUserLogin(maestroName, userName, enterCode, onSucceededListener, onFailedListener) { let xhr = new XMLHttpRequest(); xhr.open("POST", this.phpPath + "server/user/login.php", true); xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); @@ -61,7 +61,7 @@ class DBConnectManager { onFailedListener(jsonData); } }; - xhr.send("name=" + userName + "&enter_code=" + enterCode); + xhr.send("maestro_name=" + maestroName + "&name=" + userName + "&enter_code=" + enterCode); } requestPlayerHistory(date, listener) { diff --git a/src/game/login/login.js b/src/game/login/login.js index 3f1ffe1..51d1ef4 100644 --- a/src/game/login/login.js +++ b/src/game/login/login.js @@ -8,7 +8,7 @@ class Login { } create() { - self = this; + this.textStyle = { font: "bold 32px Arial", fill: "#fff", align: "right", boundsAlignH: "right", boundsAlignV: "middle" }; sessionStorageManager.clear(); @@ -21,53 +21,56 @@ class Login { let fullscreenButton = new FullscreenButton(this.game); - this.makeInputTypeTexts(); + let textX = this.game.world.centerX - 360; + if(sessionStorageManager.maestroID === null) + this.makeMaestroNameText(textX, 240); + this.makeNameText(textX, 340); + this.makeEnterCodeText(textX, 400); + + + this.inputTextName.canvasInput.focus(); + this.makeButton(); } - makeInputTypeTexts() { - // name - let textX = this.game.world.centerX - 360; - let inputX = this.game.world.centerX + 60; - let nameTextY = 340; - game.add.text(textX, nameTextY, "이름 :", textStyleBasic) + makeMaestroNameText(x, y) { + this.makeTextField(x, y, "마에스트로 계정 :"); + this.inputTextMaestroName = this.makeInputTypeText(x, y, "jisangs"); + } + + makeNameText(x, y) { + this.makeTextField(x, y, "이름 :"); + this.inputTextName = this.makeInputTypeText(x, y, "박지상"); + } + + makeEnterCodeText(x, y) { + this.makeTextField(x, y, "생년월일 :"); + this.inputTextEnterCode = this.makeInputTypeText(x, y, "760621"); + } + + makeTextField(x, y, text) { + return game.add.text(x, y, text, this.textStyle) .setTextBounds(0, 0, 200, 0) .setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2) .boundsAlignH = 'right'; + } - this.inputTextName = new InputTypeText(inputX, nameTextY); - this.inputTextName.anchor.set(0.5); - this.inputTextName.canvasInput.value(''); + makeInputTypeText(x, y, text) { + self = this; + + let inputText = new InputTypeText(x + 420, y); + inputText.anchor.set(0.5); + inputText.canvasInput.value(''); if(isDebugMode()) { - this.inputTextName.canvasInput.value('박지상'); + inputText.canvasInput.value(text); } - this.inputTextName.canvasInput._onkeyup = function() { + inputText.canvasInput._onkeyup = function() { if(event.keyCode == Phaser.Keyboard.ENTER) { self.startMenu(); } } - // birthday - const birthdayTextY = 400; - game.add.text(textX, birthdayTextY, "생년월일 :", textStyleBasic) - .setTextBounds(0, 0, 200, 0) - .setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2) - .boundsAlignH = 'right'; - - this.inputTextEnterCode = new InputTypeText(inputX, birthdayTextY); - this.inputTextEnterCode.anchor.set(0.5); - this.inputTextEnterCode.canvasInput.value(''); - if(isDebugMode()) { - this.inputTextEnterCode.canvasInput.value('760621'); - } - this.inputTextEnterCode.canvasInput._onkeyup = function() { - if(event.keyCode == Phaser.Keyboard.ENTER) { - self.startMenu(); - } - } - - this.inputTextName.canvasInput.focus(); - // this.inputTextEnterCode.canvasInput.focus(); + return inputText; } makeButton() { @@ -79,11 +82,13 @@ class Login { } startMenu() { + let maestroName = self.inputTextMaestroName.canvasInput._value; sessionStorageManager.playerName = self.inputTextName.canvasInput._value; let enterCode = self.inputTextEnterCode.canvasInput._value; let dbConnectManager = new DBConnectManager(); dbConnectManager.requestCheckUserLogin( + maestroName, sessionStorageManager.playerName, enterCode, self.loginSucceeded, @@ -92,6 +97,7 @@ class Login { } loginSucceeded(jsonData) { + sessionStorageManager.maestroID = jsonData['MaestroID']; sessionStorageManager.playerUserID = jsonData['UserID']; sessionStorageManager.playingAppName = "menu"; diff --git a/src/web/server/user/login.php b/src/web/server/user/login.php index 11b0842..3cdf2b3 100644 --- a/src/web/server/user/login.php +++ b/src/web/server/user/login.php @@ -3,6 +3,7 @@ header('Content-Type: application/json'); include "./../send_error_code.php"; +$maestro_name = $_POST["maestro_name"]; $name = $_POST["name"]; $enterCode = $_POST["enter_code"]; /* @@ -19,14 +20,29 @@ include "./../setup/connect_db.php"; $return_array = array(); -$query = "SELECT UserID FROM moty_user WHERE Name=? AND enterCode=?"; +$query = "SELECT MaestroID FROM moty_maestro WHERE Name=?"; $stmt = $db_conn->prepare($query); -$stmt->bind_param('ss', $name, $enterCode); +$stmt->bind_param('s', $maestro_name); +$stmt->execute(); +$stmt->bind_result($maestro_id); +// while($stmt->fetch()) { +// ; +// } +$stmt->fetch(); +$stmt->close(); + +// $maestro_id = 1; +$query = "SELECT UserID FROM moty_user WHERE MaestroID=? AND Name=? AND enterCode=?"; +$stmt = $db_conn->prepare($query); +$stmt->bind_param('iss', $maestro_id, $name, $enterCode); $stmt->execute(); $stmt->bind_result($user_id); // while($stmt->fetch()) $stmt->fetch(); +$stmt->close(); +$db_conn->close(); +$jsonUserData["MaestroID"] = $maestro_id; $jsonUserData["UserID"] = $user_id; echo json_encode($jsonUserData, JSON_UNESCAPED_UNICODE);