Add: check player name, enterCode before add player
This commit is contained in:
@@ -57,14 +57,12 @@ class AccountValidator {
|
||||
}
|
||||
|
||||
messageForInvalidPlayerID(textID) {
|
||||
if(textID.length < AccountValidator.Player_ID_LENGTH_MINIMUM)
|
||||
return "마에스트로 계정명은 " + AccountValidator.Player_ID_LENGTH_MINIMUM + "글자 이상이어야 합니다.";
|
||||
else if(textID.length > AccountValidator.Player_ID_LENGTH_MAXIMUM)
|
||||
return "마에스트로 계정명은 " + AccountValidator.Player_ID_LENGTH_MAXIMUM + "글자 이하이어야 합니다.";
|
||||
else if(!(/^[A-Za-z]/.test(textID)))
|
||||
return "마에스트로 계정명은 알파벳으로 시작해야 합니다.";
|
||||
else if((/[^\w]/g).test(textID))
|
||||
return "마에스트로 계정명은 알파벳과 숫자로만 적어주세요.";
|
||||
if(textID.length < Number(AccountValidator.Player_ID_LENGTH_MINIMUM))
|
||||
return "학생 이름은 " + AccountValidator.Player_ID_LENGTH_MINIMUM + "글자 이상이어야 합니다.";
|
||||
else if(textID.length > Number(AccountValidator.PLAYER_ID_LENGTH_MAXIMUM))
|
||||
return "학생 이름은 " + AccountValidator.PLAYER_ID_LENGTH_MAXIMUM + "글자 이하이어야 합니다.";
|
||||
else // if((/[^A-Za-z0-9가-힣-_]/g).test(textID))
|
||||
return "학생 이름 입력 가능한 문자는 [ 한글, 알파벳, 숫자, -, _ ] 입니다.";
|
||||
}
|
||||
|
||||
|
||||
@@ -76,15 +74,12 @@ class AccountValidator {
|
||||
}
|
||||
|
||||
messageForInvalidPlayerPW(textPW) {
|
||||
console.log(textPW);
|
||||
if(textPW.length < AccountValidator.Player_PW_LENGTH_MINIMUM)
|
||||
return "마에스트로의 암호는 " + AccountValidator.Player_PW_LENGTH_MINIMUM + "글자 이상이어야 합니다.";
|
||||
else if(textPW.length > AccountValidator.Player_PW_LENGTH_MAXIMUM)
|
||||
return "마에스트로의 암호는 " + AccountValidator.Player_PW_LENGTH_MAXIMUM + "글자 이하이어야 합니다.";
|
||||
else if((/[^\w]/g).test(textPW))
|
||||
return "마에스트로의 암호는 알파벳과 숫자로만 적어주세요.";
|
||||
if(textPW.length < Number(AccountValidator.PLAYER_PW_LENGTH_MINIMUM))
|
||||
return "학생 입장 번호는 " + AccountValidator.PLAYER_PW_LENGTH_MINIMUM + "글자 이상의 숫자로 입력해 주세요.";
|
||||
else if(textPW.length > Number(AccountValidator.PLAYER_PW_LENGTH_MAXIMUM))
|
||||
return "학생 입장 번호는 " + AccountValidator.PLAYER_PW_LENGTH_MAXIMUM + "글자 이하의 숫자로 입력해 주세요.";
|
||||
else
|
||||
return "???";
|
||||
return "학생 입장 번호는 4~6자리 숫자로 입력해 주세요.";
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
<script type="text/javascript" src="./../../../resources/jquery/jquery-3.3.1.min.js"></script>
|
||||
<script type="text/javascript" src="./../js/main.js"></script>
|
||||
<script type="text/javascript" src="./../js/lib/account_validator.js"></script>
|
||||
<script type="text/javascript" src="./../js/request_server.js"></script>
|
||||
<script type="text/javascript" src="./../js/maestro_main.js"></script>
|
||||
<script type="text/javascript" src="./../js/player_list.js"></script>
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<script type="text/javascript">
|
||||
|
||||
let accountValidator = new AccountValidator();
|
||||
|
||||
$(document).ready(function() {
|
||||
addPlayerListManager = new PlayerListManager(
|
||||
$("#add_player_list"),
|
||||
@@ -13,6 +15,17 @@ function addPlayer() {
|
||||
let playerName = $("#add_player_name").val();
|
||||
let enterCode = $("#add_player_enter_code").val();
|
||||
|
||||
if(!accountValidator.isValidPlayerID(playerName)) {
|
||||
console.log("Error - playerName : " + playerName);
|
||||
onErrorPlayerID(accountValidator.messageForInvalidPlayerID(playerName));
|
||||
return;
|
||||
} else if(!accountValidator.isValidPlayerPW(enterCode)) {
|
||||
console.log("Error - enterCode : " + enterCode);
|
||||
onErrorPlayerPW(accountValidator.messageForInvalidPlayerPW(enterCode));
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
if(playerName.length === 0) {
|
||||
// $("#add_player_notice").val("학생 이름을 입력하세요.");
|
||||
$("#error_message").text("학생 이름을 입력하세요.");
|
||||
@@ -24,6 +37,7 @@ function addPlayer() {
|
||||
$("#add_player_enter_code").focus();
|
||||
return;
|
||||
}
|
||||
*/
|
||||
|
||||
sendRequestServer( //url, sendParams, onSuccess, onFail, isDebugMode);
|
||||
"./../server/player/add_player.php",
|
||||
@@ -42,6 +56,25 @@ function addPlayer() {
|
||||
);
|
||||
}
|
||||
|
||||
function onErrorPlayerID(message) {
|
||||
if($("#error_message").length) {
|
||||
$("#error_message").text(message);
|
||||
}
|
||||
|
||||
$("#maestro_name").val("");
|
||||
$("#maestro_name").focus();
|
||||
}
|
||||
|
||||
function onErrorPlayerPW(message) {
|
||||
if($("#error_message").length) {
|
||||
$("#error_message").text(message);
|
||||
}
|
||||
|
||||
$("#password").val("");
|
||||
$("#password").focus();
|
||||
}
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
let maestro_name = "";
|
||||
let maestroName = "";
|
||||
let isAvailableID = false;
|
||||
|
||||
let password = "";
|
||||
@@ -47,20 +47,20 @@ $(document).ready(function() {
|
||||
});
|
||||
|
||||
function checkMaestroID() {
|
||||
maestro_name = $("#maestro_name").val();
|
||||
maestroName = $("#maestro_name").val();
|
||||
|
||||
if(!accountValidator.isValidMaestroID(maestro_name)) {
|
||||
onErrorMaestroID(accountValidator.messageForInvalidMaestroID(maestro_name));
|
||||
if(!accountValidator.isValidMaestroID(maestroName)) {
|
||||
onErrorMaestroID(accountValidator.messageForInvalidMaestroID(maestroName));
|
||||
return;
|
||||
}
|
||||
|
||||
sendRequestServer( //url, sendParams, onSuccess, onFail, isDebugMode);
|
||||
"./../server/maestro/check_id.php",
|
||||
"maestro_name=" + maestro_name,
|
||||
"maestro_name=" + maestroName,
|
||||
|
||||
(jsonData) => {
|
||||
isAvailableID = true;
|
||||
$("#error_message").text(maestro_name + " : 생성 가능한 마에스트로 계정 이름입니다.");
|
||||
$("#error_message").text(maestroName + " : 생성 가능한 마에스트로 계정 이름입니다.");
|
||||
},
|
||||
|
||||
(errorMessage, errorCode) => {
|
||||
@@ -150,7 +150,7 @@ function register_account() {
|
||||
|
||||
sendRequestServer( //url, sendParams, onSuccess, onFail, isDebugMode);
|
||||
"./../server/maestro/add_maestro.php",
|
||||
"maestro_name=" + maestro_name + "&password=" + password + "&email=" + email + "&account_type=" + selectedAccountTypeValue,
|
||||
"maestro_name=" + maestroName + "&password=" + password + "&email=" + email + "&account_type=" + selectedAccountTypeValue,
|
||||
|
||||
(jsonData) => {
|
||||
isAvailableID = true;
|
||||
|
||||
@@ -5,18 +5,13 @@ $(document).ready(function() {
|
||||
$("#search_player_list"),
|
||||
$("#search_player_list_navigator > #page_no_area")
|
||||
);
|
||||
|
||||
// searchPlayerListManager.setupSearchPlayerList("");
|
||||
console.log("search - ready");
|
||||
});
|
||||
|
||||
|
||||
function searchPlayer() {
|
||||
// let maestroID = sessionStorage.getItem("maestroID");
|
||||
let playerName = $("#search_name").val();
|
||||
|
||||
if(playerName.length === 0) {
|
||||
// $("#search_name_notice").val("학생 이름을 입력하세요.");
|
||||
$("#search_name").focus();
|
||||
return;
|
||||
}
|
||||
@@ -34,15 +29,6 @@ function searchPlayer() {
|
||||
<input type="text" id="search_name"><input type="submit" name="찾기" onClick="searchPlayer()"><br/>
|
||||
<br/>
|
||||
|
||||
<!--
|
||||
<h3>검색 결과</h3>
|
||||
|
||||
학생 이름
|
||||
<input type="text" id="result_name"><button>삭제</button><br/>
|
||||
입장 코드
|
||||
<input type="text" id="result_entercode"><button>수정</button>
|
||||
-->
|
||||
|
||||
</span>
|
||||
|
||||
<span id="search_result">
|
||||
|
||||
@@ -18,30 +18,44 @@ if(!is_numeric($enterCode)) {
|
||||
*/
|
||||
|
||||
|
||||
$result = hasPlayerName($maestroID, $playerName, $enterCode);
|
||||
$result = has_player_name($maestroID, $playerName, $enterCode);
|
||||
if($result !== null) {
|
||||
set_error_message("이미 등록된 학생과 입장 코드 정보입니다.");
|
||||
send_result_fail();
|
||||
exit;
|
||||
}
|
||||
|
||||
addPlayer($maestroID, $playerName, $enterCode);
|
||||
$maestroAccountType = get_maestro_account_type($maestroID);
|
||||
$playerCount = get_player_count($maestroID);
|
||||
if($playerCount >= $maestroAccountType * 10) {
|
||||
set_error_message("학생을 더 이상 추가할 수 없습니다. (더 많은 학생수로 업그레이드 하세요)");
|
||||
send_result_fail();
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = hasPlayerName($maestroID, $playerName, $enterCode);
|
||||
add_player($maestroID, $playerName, $enterCode);
|
||||
|
||||
$result = has_player_name($maestroID, $playerName, $enterCode);
|
||||
if($result === null) {
|
||||
set_error_message("학생 등록에 실패했습니다.");
|
||||
send_result_fail();
|
||||
exit;
|
||||
}
|
||||
|
||||
increase_player_count($maestroID, 1);
|
||||
|
||||
send_result_success();
|
||||
exit;
|
||||
|
||||
|
||||
function hasPlayerName($maestroID, $playerName, $enterCode) {
|
||||
function has_player_name($maestroID, $playerName, $enterCode) {
|
||||
global $db_conn;
|
||||
|
||||
$query = "SELECT PlayerID FROM moty_player WHERE MaestroID=? AND Name=? AND EnterCode=?";
|
||||
$query = "
|
||||
SELECT PlayerID
|
||||
FROM moty_player
|
||||
WHERE MaestroID = ? AND Name = ? AND EnterCode = ?
|
||||
";
|
||||
$stmt = $db_conn->prepare($query);
|
||||
$stmt->bind_param("iss", $maestroID, $playerName, $enterCode);
|
||||
$stmt->execute();
|
||||
@@ -53,13 +67,67 @@ function hasPlayerName($maestroID, $playerName, $enterCode) {
|
||||
return $playerID;
|
||||
}
|
||||
|
||||
function addPlayer($maestroID, $playerName, $enterCode) {
|
||||
function get_maestro_account_type($maestroID) {
|
||||
global $db_conn;
|
||||
|
||||
$query = "INSERT INTO moty_player (MaestroID, Name, EnterCode) VALUES (?, ?, ?)";
|
||||
$query = "
|
||||
SELECT AccountType
|
||||
FROM moty_maestro
|
||||
WHERE MaestroID = ?
|
||||
";
|
||||
$stmt = $db_conn->prepare($query);
|
||||
$stmt->bind_param("i", $maestroID);
|
||||
$stmt->execute();
|
||||
$stmt->bind_result($accountType);
|
||||
// while($stmt->fetch())
|
||||
$stmt->fetch();
|
||||
$stmt->close();
|
||||
|
||||
return $accountType;
|
||||
}
|
||||
|
||||
function get_player_count($maestroID) {
|
||||
global $db_conn;
|
||||
|
||||
$query = "
|
||||
SELECT PlayerCount
|
||||
FROM moty_maestro
|
||||
WHERE MaestroID = ?
|
||||
";
|
||||
$stmt = $db_conn->prepare($query);
|
||||
$stmt->bind_param("i", $maestroID);
|
||||
$stmt->execute();
|
||||
$stmt->bind_result($playerCount);
|
||||
// while($stmt->fetch())
|
||||
$stmt->fetch();
|
||||
$stmt->close();
|
||||
|
||||
return $playerCount;
|
||||
}
|
||||
|
||||
function add_player($maestroID, $playerName, $enterCode) {
|
||||
global $db_conn;
|
||||
|
||||
$query = "
|
||||
INSERT INTO moty_player (MaestroID, Name, EnterCode)
|
||||
VALUES (?, ?, ?)
|
||||
";
|
||||
$stmt = $db_conn->prepare($query);
|
||||
$stmt->bind_param("iss", $maestroID, $playerName, $enterCode);
|
||||
$stmt->execute();
|
||||
}
|
||||
|
||||
function increase_player_count($maestroID, $count) {
|
||||
global $db_conn;
|
||||
|
||||
$query = "
|
||||
UPDATE moty_maestro
|
||||
SET PlayerCount = PlayerCount + ?
|
||||
WHERE MaestroID = ?
|
||||
";
|
||||
$stmt = $db_conn->prepare($query);
|
||||
$stmt->bind_param("ii", $count, $maestroID);
|
||||
$stmt->execute();
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -24,6 +24,8 @@ if($result === true) {
|
||||
exit;
|
||||
}
|
||||
|
||||
decrease_player_count($maestroID, 1);
|
||||
|
||||
send_result_success();
|
||||
exit;
|
||||
|
||||
@@ -31,7 +33,10 @@ exit;
|
||||
function deletePlayer($maestroID, $playerID) {
|
||||
global $db_conn;
|
||||
|
||||
$query = "DELETE FROM moty_best_record WHERE MaestroID = ? AND PlayerID = ?";
|
||||
$query = "
|
||||
DELETE FROM moty_best_record
|
||||
WHERE MaestroID = ? AND PlayerID = ?
|
||||
";
|
||||
$stmt = $db_conn->prepare($query);
|
||||
$stmt->bind_param("ii", $maestroID, $playerID);
|
||||
$result = $stmt->execute();
|
||||
@@ -41,7 +46,10 @@ function deletePlayer($maestroID, $playerID) {
|
||||
// echo "deleted row count : ".$stmt->affected_rows;
|
||||
// }
|
||||
|
||||
$query = "DELETE FROM moty_player WHERE MaestroID = ? AND PlayerID = ?";
|
||||
$query = "
|
||||
DELETE FROM moty_player
|
||||
WHERE MaestroID = ? AND PlayerID = ?
|
||||
";
|
||||
$stmt = $db_conn->prepare($query);
|
||||
$stmt->bind_param("ii", $maestroID, $playerID);
|
||||
$result = $stmt->execute();
|
||||
@@ -55,7 +63,11 @@ function deletePlayer($maestroID, $playerID) {
|
||||
function hasPlayerID($maestroID, $playerID) {
|
||||
global $db_conn;
|
||||
|
||||
$query = "SELECT PlayerID FROM moty_player WHERE MaestroID=? AND PlayerID=?";
|
||||
$query = "
|
||||
SELECT PlayerID
|
||||
FROM moty_player
|
||||
WHERE MaestroID=? AND PlayerID=?
|
||||
";
|
||||
$stmt = $db_conn->prepare($query);
|
||||
$stmt->bind_param("ii", $maestroID, $playerID);
|
||||
$stmt->execute();
|
||||
@@ -73,7 +85,11 @@ function hasPlayerID($maestroID, $playerID) {
|
||||
function hasPlayerRecord($maestroID, $playerID) {
|
||||
global $db_conn;
|
||||
|
||||
$query = "SELECT PlayerID FROM moty_best_record WHERE MaestroID=? AND PlayerID=?";
|
||||
$query = "
|
||||
SELECT PlayerID
|
||||
FROM moty_best_record
|
||||
WHERE MaestroID=? AND PlayerID=?
|
||||
";
|
||||
$stmt = $db_conn->prepare($query);
|
||||
$stmt->bind_param("ii", $maestroID, $playerID);
|
||||
$stmt->execute();
|
||||
@@ -88,4 +104,17 @@ function hasPlayerRecord($maestroID, $playerID) {
|
||||
return false;
|
||||
}
|
||||
|
||||
function decrease_player_count($maestroID, $count) {
|
||||
global $db_conn;
|
||||
|
||||
$query = "
|
||||
UPDATE moty_maestro
|
||||
SET PlayerCount = PlayerCount - ?
|
||||
WHERE MaestroID = ?
|
||||
";
|
||||
$stmt = $db_conn->prepare($query);
|
||||
$stmt->bind_param("ii", $count, $maestroID);
|
||||
$stmt->execute();
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -6,7 +6,7 @@ CREATE TABLE moty_maestro (
|
||||
AccountType INT UNSIGNED NOT NULL,
|
||||
ActivateStatus INT UNSIGNED NOT NULL,
|
||||
AvailableActivateDateTime DATETIME NOT NULL,
|
||||
UserCount INT UNSIGNED NOT NULL,
|
||||
PlayerCount INT UNSIGNED NOT NULL,
|
||||
AcceptClausesDateTime DATETIME NOT NULL,
|
||||
MaestroTestID INT UNSIGNED
|
||||
);
|
||||
@@ -52,7 +52,7 @@ CREATE TABLE moty_best_record (
|
||||
|
||||
FOREIGN KEY (MaestroID) REFERENCES moty_maestro(MaestroID),
|
||||
FOREIGN KEY (AppID) REFERENCES moty_app(AppID),
|
||||
FOREIGN KEY (UserID) REFERENCES moty_user(UserID)
|
||||
FOREIGN KEY (PlayerID) REFERENCES moty_player(PlayerID)
|
||||
);
|
||||
|
||||
CREATE TABLE moty_ranking (
|
||||
@@ -65,5 +65,5 @@ CREATE TABLE moty_ranking (
|
||||
|
||||
FOREIGN KEY (MaestroID) REFERENCES moty_maestro(MaestroID),
|
||||
FOREIGN KEY (AppID) REFERENCES moty_app(AppID),
|
||||
FOREIGN KEY (UserID) REFERENCES moty_user(UserID)
|
||||
FOREIGN KEY (PlayerID) REFERENCES moty_player(PlayerID)
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user