Add: update maestro info, password php

This commit is contained in:
2018-08-02 17:27:18 +09:00
parent e2e6761c9b
commit fd87b6fe45
5 changed files with 338 additions and 20 deletions
+244 -15
View File
@@ -1,7 +1,193 @@
<script>
let isChangedIDName = false;
let isAvailableIDName = false;
let registeredMaestroIDName = "";
let registeredEmail = "";
let registeredPassword = "";
let newMaestroIDName = "";
let newEmail = "";
let newPassword = "";
let newPasswordVerify = "";
$(document).ready(function() {
loadMaestroInfo(maestroID);
$('#maestro_id').bind('input propertychange', function() {
onChangeMaestroIDName();
});
});
function loadMaestroInfo(maestroID) {
sendRequestServer( //url, sendParams, onSuccess, onFail, isDebugMode);
"./../server/maestro/maestro_info.php",
"maestro_id=" + maestroID,
(jsonData) => {
console.log(jsonData);
registeredMaestroIDName = jsonData.name;
$("#maestro_id").val(registeredMaestroIDName);
registeredEmail = jsonData.email;
$("#email").val(registeredEmail);
},
(errorMessage, errorCode) => {
showErrorMessage(errorMessage, "error");
}
);
}
function onChangeMaestroIDName() {
isChangedIDName = true;
isAvailableIDName = false;
$("#id_ckeck").prop("disabled", false)
$("#id_ckeck_help").removeClass("d-none");
}
function checkMaestroIDName() {
newMaestroIDName = $("#maestro_id").val();
if(!accountValidator.isValidMaestroID(newMaestroIDName)) {
showErrorMessage(accountValidator.messageForInvalidMaestroID(newMaestroIDName), "error");
$("#maestro_id").focus();
$("#maestro_id").select();
return;
}
sendRequestServer( //url, sendParams, onSuccess, onFail, isDebugMode);
"./../server/maestro/check_id.php",
"maestro_name=" + newMaestroIDName,
(jsonData) => {
isAvailableIDName = true;
isChangedIDName = false;
showErrorMessage(newMaestroIDName + " : 새로 등록할 수 있는 마에스트로 아이디입니다.", "success");
$("#id_ckeck").prop("disabled", true)
$("#id_ckeck_help").addClass("d-none");
},
(errorMessage, errorCode) => {
isAvailableIDName = false;
showErrorMessage(errorMessage, "error");
// $("#maestro_name").val("");
$("#maestro_id").focus();
$("#maestro_id").select();
}
);
}
function changeMaestroInfo() {
location.href="main_menu.html";
newMaestroIDName = $("#maestro_id").val();
if(newMaestroIDName.length === 0) {
showErrorMessage("변경할 아이디를 입력해 주세요.", "error");
$("#maestro_id").focus();
return;
} else if(isChangedIDName && !isAvailableIDName) {
showErrorMessage("아이디 중복 확인을 해 주세요.", "error");
$("#id_ckeck").focus();
return;
}
newEmail = $("#email").val();
if(newEmail.length === 0) {
showErrorMessage("이메일을 입력해 주세요.", "error");
$("#email").focus();
return;
}
if(registeredMaestroIDName === newMaestroIDName && registeredEmail === newEmail) {
showErrorMessage("변경된 정보가 없습니다.", "error");
return;
}
sendRequestServer( //url, sendParams, onSuccess, onFail, isDebugMode);
"./../server/maestro/update_maestro_info.php",
"maestro_id=" + maestroID + "&maestro_name=" + newMaestroIDName + "&email=" + newEmail,
(jsonData) => {
alert(
"마에스트로 계정 정보가 변경되었습니다.\n"
+ "아이디 : " + newMaestroIDName + "\n"
+ "이메일 : " + newEmail
);
location.href="main_menu.html";
},
(errorMessage, errorCode) => {
isAvailableIDName = false;
showErrorMessage(errorMessage);
}
);
}
function checkPassword() {
registeredPassword = $("#prev_password").val();
if(registeredPassword.length === 0) {
showErrorMessage("현재 암호를 입력해 주세요.", "error");
$("#prev_password").focus();
return false;
}
newPassword = $("#new_password").val();
if(newPassword.length === 0) {
showErrorMessage("새로운 암호를 입력해 주세요.", "error");
$("#new_password").focus();
return;
} else if(!accountValidator.isValidMaestroPW(newPassword)) {
showErrorMessage(accountValidator.messageForInvalidMaestroPW(newPassword), "error");
$("#new_password").focus();
$("#new_password").select();
return false;
}
newPasswordVerify = $("#new_password_verify").val();
if(newPassword !== newPasswordVerify) {
showErrorMessage(
"[새로운 암호]와 [새로운 암호 확인]의 내용이 일치하지 않습니다.<br/>둘 다 같은 내용으로 다시 한 번 입력해 주세요.",
"error"
);
$("#new_password_verify").focus();
return false;
}
if(registeredPassword === newPassword) {
showErrorMessage("[새로운 암호]가 현재 암호와 동일합니다.", "error");
$("#new_password").focus();
$("#new_password").select();
return false;
}
return true;
}
function changeMaestroPassword() {
if(!checkPassword())
return;
sendRequestServer( //url, sendParams, onSuccess, onFail, isDebugMode);
"./../server/maestro/update_maestro_password.php",
"maestro_id=" + maestroID + "&registered_pw=" + registeredPassword + "&new_pw=" + newPassword,
(jsonData) => {
alert("패스워드가 변경되었습니다.");
location.href="main_menu.html";
},
(errorMessage, errorCode) => {
showErrorMessage(errorMessage);
}
);
}
</script>
@@ -10,42 +196,85 @@ function changeMaestroInfo() {
<div class="container my-3">
<div id="message_box">
</div>
<div class="card border-primary">
<div class="card-header bg-light"><span class="h4">마에스트로 계정 정보 수정</span></div>
<div class="card-body">
<form class="mx-4">
<div class="form-group row">
<label for="maestro_name" class="col-sm-2 col-form-label">* 아이디 변경</label>
<label for="maestro_id" class="col-sm-2 col-form-label text-primary">* 변경할 아이디</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="maestro_name" placeholder="아이디 입력">
<input type="text" class="form-control" id="maestro_id" placeholder="아이디 입력">
<small class="form-text text-muted">4~20 글자. 영문, 숫자만 사용 가능합니다.</small>
</div>
<div class="col-sm-4">
<input type="button" id="id_ckeck" class="btn btn-info" value="중복 체크" onClick="checkMaestroID()" disabled>
<input type="button" id="id_ckeck" class="btn btn-warning" value="중복 체크" onClick="checkMaestroIDName()" disabled>
<small id="id_ckeck_help" class="form-text text-danger d-none">[중복 체크] 버튼을 눌러주세요.</small>
</div>
</div>
<div class="form-group row">
<label for="password" class="col-sm-2 col-form-label">* 암호</label>
<div class="col-sm-6">
<input type="password" class="form-control" id="password" placeholder="Password">
<small class="form-text text-muted">4~16 글자. 영문, 숫자만 사용 가능합니다.</small>
</div>
</div>
<div class="form-group row">
<label for="email" class="col-sm-2 col-form-label">* 이메일</label>
<label for="email" class="col-sm-2 col-form-label text-primary">* 변경할 이메일</label>
<div class="col-sm-6">
<input type="email" class="form-control" id="email" placeholder="name@example.com">
</div>
</div>
<div class="mt-5 mb-1 text-danger">위 내용으로 마에스트로 계정 정보를 변경합니다.</div>
<button type="button" class="btn btn-danger btn-block btn-lg" onClick="changeMaestroInfo()">변경</button>
<button type="button" class="btn btn-primary btn-block btn-lg" onClick="changeMaestroInfo()">변경</button>
</form>
</div> <!-- card body -->
</div>
</div> <!-- change maestro info -->
<div class="card border-primary my-3">
<div class="card-header bg-light"><span class="h4">마에스트로 암호 변경</span></div>
<div class="card-body">
<div id="message_box">
</div>
<form class="mx-4">
<div class="form-group row">
<label for="prev_password" class="col-sm-2 col-form-label">* 현재 암호</label>
<div class="col-sm-6">
<input type="password" class="form-control" id="prev_password" placeholder="Password">
<small class="form-text text-muted">기존에 사용하던 암호를 입력하세요.</small>
</div>
</div>
</form>
<hr class="mx-3 mb-4"/>
<form class="mx-4">
<div class="form-group row">
<label for="new_password" class="col-sm-2 col-form-label text-primary">* 새로운 암호</label>
<div class="col-sm-6">
<input type="password" class="form-control" id="new_password" placeholder="Password">
<small class="form-text text-muted">4~16 글자. 영문, 숫자만 사용 가능합니다.</small>
</div>
</div>
<div class="form-group row">
<label for="new_password_verify" class="col-sm-2 col-form-label text-primary">* 새로운 암호 확인</label>
<div class="col-sm-6">
<input type="password" class="form-control" id="new_password_verify" placeholder="Password">
<small class="form-text text-muted">위에 입력한 암호를 다시 한 번 정확히 입력하세요.</small>
</div>
</div>
<div class="mt-5 mb-1 text-danger">위 내용으로 마에스트로 암호를 변경합니다.</div>
<button type="button" class="btn btn-primary btn-block btn-lg" onClick="changeMaestroPassword()">변경</button>
</form>
</div> <!-- card body -->
</div> <!-- change password -->
</div> <!-- container -->