Add: account_validator
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
class AccountValidator {
|
||||
|
||||
constructor() {
|
||||
this.patternMaestroID = /^[A-Za-z]{1}[A-Za-z0-9]{3,19}$/;
|
||||
this.patternMaestroPW = /^[A-Za-z0-9]{4,16}$/;
|
||||
}
|
||||
|
||||
isValidMaestroID(textID) {
|
||||
if(!this.patternMaestroID.test(textID))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
messageForInvalidMaestroID(textID) {
|
||||
if(textID.length < AccountValidator.MAESTRO_ID_LENGTH_MINIMUM)
|
||||
return "마에스트로 계정명은 " + AccountValidator.MAESTRO_ID_LENGTH_MINIMUM + "글자 이상이어야 합니다.";
|
||||
else if(textID.length > AccountValidator.MAESTRO_ID_LENGTH_MAXIMUM)
|
||||
return "마에스트로 계정명은 " + AccountValidator.MAESTRO_ID_LENGTH_MAXIMUM + "글자 이하이어야 합니다.";
|
||||
else if(!(/^[A-Za-z]/.test(textID)))
|
||||
return "마에스트로 계정명은 알파벳으로 시작해야 합니다.";
|
||||
else if((/[^\w]/g).test(textID))
|
||||
return "마에스트로 계정명은 알파벳과 숫자로만 적어주세요.";
|
||||
}
|
||||
|
||||
|
||||
isValidMaestroPW(textPW) {
|
||||
if(!this.patternMaestroPW.test(textPW))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
messageForInvalidMaestroPW(textPW) {
|
||||
console.log(textPW);
|
||||
if(textPW.length < AccountValidator.MAESTRO_PW_LENGTH_MINIMUM)
|
||||
return "마에스트로의 암호는 " + AccountValidator.MAESTRO_PW_LENGTH_MINIMUM + "글자 이상이어야 합니다.";
|
||||
else if(textPW.length > AccountValidator.MAESTRO_PW_LENGTH_MAXIMUM)
|
||||
return "마에스트로의 암호는 " + AccountValidator.MAESTRO_PW_LENGTH_MAXIMUM + "글자 이하이어야 합니다.";
|
||||
else if((/[^\w]/g).test(textPW))
|
||||
return "마에스트로의 암호는 알파벳과 숫자로만 적어주세요.";
|
||||
else
|
||||
return "???";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
AccountValidator.MAESTRO_ID_LENGTH_MINIMUM = 4;
|
||||
AccountValidator.MAESTRO_ID_LENGTH_MAXIMUM = 20;
|
||||
|
||||
AccountValidator.MAESTRO_PW_LENGTH_MINIMUM = 4;
|
||||
AccountValidator.MAESTRO_PW_LENGTH_MAXIMUM = 16;
|
||||
@@ -10,6 +10,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">
|
||||
$(document).ready(function() {
|
||||
|
||||
@@ -38,15 +38,22 @@ let selectedAccountTypeText = "";
|
||||
|
||||
let tab1, tab2, tab3;
|
||||
|
||||
let accountValidator = new AccountValidator();
|
||||
|
||||
$(document).ready(function() {
|
||||
tab1 = $("#page-tabs li").filter(":eq(0)");
|
||||
tab2 = $("#page-tabs li").filter(":eq(1)");
|
||||
tab3 = $("#page-tabs li").filter(":eq(2)");
|
||||
});
|
||||
|
||||
function check_id() {
|
||||
function checkMaestroID() {
|
||||
maestro_name = $("#maestro_name").val();
|
||||
|
||||
if(!accountValidator.isValidMaestroID(maestro_name)) {
|
||||
onErrorMaestroID(accountValidator.messageForInvalidMaestroID(maestro_name));
|
||||
return;
|
||||
}
|
||||
|
||||
sendRequestServer( //url, sendParams, onSuccess, onFail, isDebugMode);
|
||||
"./../server/maestro/check_id.php",
|
||||
"maestro_name=" + maestro_name,
|
||||
@@ -58,20 +65,31 @@ function check_id() {
|
||||
|
||||
(errorMessage, errorCode) => {
|
||||
isAvailableID = false;
|
||||
|
||||
if($("#error_message").length) {
|
||||
$("#error_message").text(errorMessage);
|
||||
}
|
||||
|
||||
$("#maestro_name").val("");
|
||||
$("#maestro_name").focus();
|
||||
onErrorMaestroID(errorMessage);
|
||||
}
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
function onErrorMaestroID(message) {
|
||||
if($("#error_message").length) {
|
||||
$("#error_message").text(message);
|
||||
}
|
||||
|
||||
function check_data() {
|
||||
$("#maestro_name").val("");
|
||||
$("#maestro_name").focus();
|
||||
}
|
||||
|
||||
function onErrorMaestroPW(message) {
|
||||
if($("#error_message").length) {
|
||||
$("#error_message").text(message);
|
||||
}
|
||||
|
||||
$("#password").val("");
|
||||
$("#password").focus();
|
||||
}
|
||||
|
||||
function checkData() {
|
||||
if(!isAvailableID) {
|
||||
$("#error_message").text("아이디 중복 확인을 해 주세요.");
|
||||
$("#check_id").focus();
|
||||
@@ -79,11 +97,15 @@ function check_data() {
|
||||
}
|
||||
|
||||
password = $("#password").val();
|
||||
if(password.length === 0) {
|
||||
$("#error_message").text("패스워드를 입력해 주세요.");
|
||||
$("#password").focus();
|
||||
if(!accountValidator.isValidMaestroPW(password)) {
|
||||
onErrorMaestroPW(accountValidator.messageForInvalidMaestroPW(password));
|
||||
return;
|
||||
}
|
||||
// if(password.length === 0) {
|
||||
// $("#error_message").text("패스워드를 입력해 주세요.");
|
||||
// $("#password").focus();
|
||||
// return;
|
||||
// }
|
||||
|
||||
email = $("#email").val();
|
||||
if(email.length === 0) {
|
||||
@@ -110,6 +132,8 @@ function check_data() {
|
||||
$(".account_type").append(selectedAccountTypeText);
|
||||
$(".price_account").append(selectedAccountTypeText);
|
||||
|
||||
$("#error_message").text("");
|
||||
|
||||
$("#input_data").css("display", "none");
|
||||
$("#register_account").css("display", "block");
|
||||
|
||||
@@ -170,7 +194,7 @@ function register_account() {
|
||||
<div id="input_data">
|
||||
|
||||
(필수) 마에스트로 아이디 : <input type="text" id="maestro_name" value="test" >
|
||||
<button id="check_id" onClick="check_id()">중복 확인</button><br/>
|
||||
<button id="check_id" onClick="checkMaestroID()">중복 확인</button><br/>
|
||||
(필수) 암호 : <input id="password" value="test" type="password" name="password"><br/>
|
||||
(필수) 이메일 : <input id="email" value="test@test.com" name="email"><br/>
|
||||
(필수) 학생 수 :
|
||||
@@ -211,7 +235,7 @@ function register_account() {
|
||||
</ul>
|
||||
|
||||
<div class="col alignCenter">
|
||||
<a id="maestro_register" class="btn btn-sea width400" onClick="check_data()">등록 신청</a>
|
||||
<a id="maestro_register" class="btn btn-sea width400" onClick="checkData()">등록 신청</a>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
@@ -55,7 +55,7 @@ function get_maestro_list_by_name($maestroName) {
|
||||
|
||||
$query = "
|
||||
SELECT MaestroID, Name, AccountType FROM moty_maestro
|
||||
WHERE Name=? AND ActivateStatus=0
|
||||
WHERE Name LIKE CONCAT('%', ?, '%') AND ActivateStatus=0
|
||||
ORDER BY MaestroID DESC
|
||||
";
|
||||
$stmt = $db_conn->prepare($query);
|
||||
|
||||
Reference in New Issue
Block a user