<!-- Script -->
<script layout:fragment="script" th:inline="javascript" type="text/javascript">
//์์ด๋ ์ค๋ณต์ฒดํฌ ์ฌ๋ถ
let idCheckYn = false;
$(document).ready(function () {
//ํ์๊ฐ์
์ฒ๋ฆฌ
$("#regUserBtn").on("click", function () {
if (validation()) {
const params = {
userId: $("#userId").val(),
userPassword: $("#userPassword").val(),
userName: $("#userName").val(),
userEmail: $("#userEmail").val()
};
$.ajax({
type : "post",
url : "/user/api/reg",
dataType: "json",
data : JSON.stringify(params),
contentType: 'application/json; charset=utf-8',
success: function (data){
console.log(data);
if(data.code === "1") {
alert("ํ์๊ฐ์
์ ์ฑ๊ณตํ์ต๋๋ค.");
location.href = "/user/login";
} else {
alert("ํ์๊ฐ์
์ ์คํจํ์ต๋๋ค.");
$("#registerFrm")[0].reset();
return false;
}
},
error:function(e){
console.log(e);
alert("ํ์๊ฐ์
์ ์คํจํ์ต๋๋ค.");
return false;
}
});
}
});
//์์ด๋ ์ค๋ณต์ฒดํฌ
$("#idCheck").on("click", function () {
if ($("#userId").val() === "" || $("#userId").val() === undefined || $("#userId").val() === " ") {
alert("์์ด๋๋ ํ์๊ฐ์
๋๋ค.");
$("#userId").focus();
return false;
}
$.ajax({
type : "post",
url : "/user/api/checkDuplicateId/" + $("#userId").val(),
success: function (data){
console.log(data);
if(data.code === "3") {
alert("์ค๋ณต๋๋ ์์ด๋์
๋๋ค.");
$("#userId").val("").focus();
return false;
} else {
alert("๊ฐ์
๊ฐ๋ฅํ ์์ด๋์
๋๋ค.");
$("#userName").focus();
idCheckYn = true;
}
},
error:function(e){
console.log(e);
alert("์์คํ
์๋ฌ์
๋๋ค.");
return false;
}
});
});
});
//์ ํจ์ฑ ๊ฒ์ฆ
function validation() {
//์ ํจ์ฑ ๊ฒ์ฆ ํต๊ณผ์ฌ๋ถ
let validationPassYn = false;
if ($("#userId").val() === "" || $("#userId").val() === undefined || $("#userId").val() === " ") {
alert("์์ด๋๋ฅผ ์
๋ ฅํด์ฃผ์ธ์.");
$("#userId").focus();
return false;
}
//์์ด๋ ์ฒดํฌ ์๋ฃ
if (!idCheckYn) {
alert("์์ด๋ ์ค๋ณต์ฒดํฌ๋ฅผ ํด์ฃผ์ธ์.");
return false;
}
if ($("#userName").val() === "" || $("#userName").val() === undefined || $("#userName").val() === " ") {
alert("์ด๋ฆ์ ์
๋ ฅํด์ฃผ์ธ์.");
$("#userName").focus();
return false;
}
if ($("#userEmail").val() === "" || $("#userEmail").val() === undefined || $("#userEmail").val() === " ") {
alert("์ด๋ฉ์ผ์ ์
๋ ฅํด์ฃผ์ธ์.");
$("#userEmail").focus();
return false;
}
if ($("#userPassword").val() === "" || $("#userPassword").val() === undefined || $("#userPassword").val() === " ") {
alert("๋น๋ฐ๋ฒํธ๋ฅผ ์
๋ ฅํด์ฃผ์ธ์.");
$("#userPassword").focus();
return false;
}
if ($("#userPasswordConfirm").val() === "" || $("#userPasswordConfirm").val() === undefined || $("#userPasswordConfirm").val() === " ") {
alert("๋น๋ฐ๋ฒํธ ํ์ธ์ ์
๋ ฅํด์ฃผ์ธ์.");
$("#userPasswordConfirm").focus();
return false;
}
//๋น๋ฐ๋ฒํธ ์ผ์น์ฌ๋ถ
let passwordPassYn = false;
passwordPassYn = ($("#userPassword").val() === $("#userPasswordConfirm").val()) ? true : false;
if (!passwordPassYn) {
alert("๋น๋ฐ๋ฒํธ๊ฐ ์ผ์นํ์ง ์์ต๋๋ค.");
$("#userPassword").val("").focus();
return false;
}
return validationPassYn = true;
}
</script>
๋๊ธ