๋ณธ๋ฌธ์œผ๋กœ ๊ฑด๋„ˆ๋›ฐ๊ธฐ

25-03-11

๐Ÿ“Œ Daily Reportโ€‹

https://github.com/ssginc-be/DOKI/issues/70


๐Ÿ“Œ ํ”„๋กœ์ ํŠธ ์ƒํ™ฉโ€‹

์ปจ๋””์…˜์ด ์•ˆ์ข‹์•„์ง€๊ณ  ์žˆ๋‹ค. ๋งˆ๊ฐ์ด 2์ฃผ๋„ ์•ˆ๋‚จ์•˜๋Š”๋ฐ ์ข‹์€ ์‹ ํ˜ธ๋Š” ์•„๋‹ˆ๋‹ค.

์ด๊ฒƒ์€_rebase๋„_reset๋„_์•„๋‹Œ

git ๋ช…๋ น์–ด๋ฅผ ์ด๋”ฐ๊ตฌ๋กœ ์น  ์ •๋„๋กœ ์•ฝ๊ฐ„ ๋ฉํ•˜๋‹ค. ใ…‹ใ…‹ใ…‹ใ…Œใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹

๊ทธ๋ž˜๋„ ๊ฐ์ข… ์ŠคํŒ€ํŒฉ ๊ฝ‚์œผ๋‹ˆ๊นŒ ๋กœ์ง ์ž‘์„ฑ์€ ๋˜๊ณ  ์žˆ์Œ! ๐Ÿ˜Š


๐Ÿ“Œ ํšŒ์›๊ฐ€์ž… ์œ ํšจ์„ฑ ๊ฒ€์‚ฌโ€‹

๊ฐ€์ž… ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ ์ง„์งœ ๋ณดํ†ต์ด ์•„๋‹ˆ๋”๋ผ.

DOM ์ปจํŠธ๋กค๊นŒ์ง€ ํ•ด์„œ ๊ทธ๋Ÿฐ๊ฐ€? ์ •๋ง ์‹œ๊ฐ„ ์žก์•„๋จน๋Š”๊ฒŒ

๋Œ€๋‹จํ•˜์ง€ ์•Š์€ ์ž์ž˜ํ•œ ๋กœ์ง์˜ ๋ญ‰ํƒฑ์ด(?)์ธ๋ฐ, JS๋กœ view์—์„œ ๊ฒ€์‚ฌํ•œ๋‹ค๊ณ  ๋์ด ์•„๋‹ˆ๋ผ

์ง„์งœ ์‹ ๊ฒฝ์„ ์ผ๋‹ค๋ฉด ๋ฐฑ ๋‹จ๊นŒ์ง€ ๊ฒ€์‚ฌํ•ด์•ผ ํ•˜๋Š”๊ฑฐ๋ผ

์ง„์‹ฌ ํ˜„์žฌ ์ƒํ™ฉ์—์„œ ๋ณดํ†ต ๊ท€์ฐฎ์€ ์ž‘์—…์ด ์•„๋‹ ์ˆ˜๊ฐ€ ์—†๋‹ค;


...ํ•˜๋‹จ์€ ์˜ค๋Š˜๊นŒ์ง€ ์ง  ์ฝ”๋“œ์ธ๋ฐ ์ด๊ฑฐ 60ํผ๋ฐ–์— ๊ตฌํ˜„ ์•ˆ๋œ ์ƒํƒœ์ด๋‹ค.

const API_GATEWAY_HOST = "http://localhost:9093";

/* ๊ฐ€์ž… request ๊ฐ€๋Šฅํ•œ ์ƒํƒœ์ธ์ง€ check */
let CHECK_EMAIL = false;
let CHECK_PW = false;
let CHECK_PHONE = false;
let CHECK_NAME = false;
let CHECK_GENDER = false;
let CHECK_BIRTH = false;


/* ๋’ค๋กœ ๊ฐ€๊ธฐ, ์ž‘์„ฑ ์ทจ์†Œ ๋ฒ„ํŠผ ํด๋ฆญ์‹œ ์ž‘๋™ํ•˜๋Š” ํ•จ์ˆ˜ */
function goBack() {
const ok = confirm("๊ฐ€์ž…์„ ์ทจ์†Œํ•˜๊ณ  ๋’ค๋กœ ๊ฐ€์‹œ๊ฒ ์Šต๋‹ˆ๊นŒ?");
if (ok) history.back();
}

/* ๊ฐ€์ž…ํ•˜๊ธฐ ๋ฒ„ํŠผ ํด๋ฆญ์‹œ ์ž‘๋™ํ•˜๋Š” ํ•จ์ˆ˜ */
function SignUp() {
let requestBody = {
member_id: memberId,
member_pw: memberPw
};

}


/*****************************************************************
[๋ฒ„ํŠผ ์ด๋ฒคํŠธ ํ•จ์ˆ˜]
์ด๋ฉ”์ผ ์ธ์ฆ ๋ฒ„ํŠผ ํด๋ฆญ ์‹œ ์ž‘๋™
*/
async function handleEmailCodeButtonClicked() {
const email = document.getElementById('email-input').value;
console.log('email input:', email);

// ์ด๋ฉ”์ผ ํฌ๋งท ๊ฒ€์‚ฌ
if (checkEmailInput(email) === false) {
alert("์ด๋ฉ”์ผ ํ˜•์‹์ด ์˜ฌ๋ฐ”๋ฅด์ง€ ์•Š์Šต๋‹ˆ๋‹ค.");
return;
}

// ์ธ์ฆ์ฝ”๋“œ ๋ฐœ์†ก (์—ฌ๊ธฐ์„  await ํ•˜์ง€ ์•Š...๋Š”๊ฒŒ ์ข‹์€๋ฐ ๋ฐ”์˜๋‹ˆ ์ผ๋‹จ ํ•ด๋†“์ž)
await sendEmailCode();

// ์ด๋ฉ”์ผ input readonly ์ฒ˜๋ฆฌ + ์ด๋ฉ”์ผ ์ธ์ฆ ๋ฒ„ํŠผ ๋น„ํ™œ์„ฑํ™”
let emailInput = document.getElementById('email-input');
let emailCheckButton = document.getElementById('email-check-button');
emailInput.readOnly = true;
emailCheckButton.innerText = "์ธ์ฆ ์ดˆ๊ธฐํ™”";
emailCheckButton.classList.add('active');
emailCheckButton.onclick = resetEmailVerification; // onclick ํ•จ์ˆ˜๋ฅผ ์ธ์ฆ ์ดˆ๊ธฐํ™” ํ•จ์ˆ˜๋กœ ๋ณ€๊ฒฝ

// global check ๋ณ€์ˆ˜
CHECK_EMAIL = true;

// ์ด๋ฉ”์ผ input ํ•˜๋‹จ์— ์ธ์ฆ์ฝ”๋“œ ์ž…๋ ฅ input๊ณผ [์ธ์ฆ ํ™•์ธ] ๋ฒ„ํŠผ ํ‘œ์‹œ
if (!document.getElementById('email-verification-box')) { // ํ˜„์žฌ DOM์— ์—†์œผ๋ฉด
let newChildDiv = document.createElement('div');
newChildDiv.classList.add("group-content-box");
newChildDiv.id = 'email-verification-box';
let childInnerHtml = `
<div class="group-content-label"></div>
<input id="email-code-input" type="text" placeholder="5๋ถ„ ๋‚ด์— ๋ฐœ์†ก๋œ ์ฝ”๋“œ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”." />
<button class="signup-check-button" id="email-code-check-button" onclick="validateEmailCode()">์ธ์ฆ ํ™•์ธ</button>
`;
newChildDiv.innerHTML = childInnerHtml;

let signupGroup = document.getElementById('signup-group-top');
signupGroup.insertBefore(newChildDiv, signupGroup.children[2]);
}
}

// API ํ˜ธ์ถœํ•ด์„œ ์ธ์ฆ ์ฝ”๋“œ ๋ณด๋‚ด๋ณด๊ณ , ์‹คํŒจํ•˜๋ฉด view ๋˜๋Œ๋ฆฌ๋Š” ํ•จ์ˆ˜
async function sendEmailCode() {
try {
await getRequest(API_GATEWAY_HOST + "/v2/auth/email/code?to=" + email);
} catch (error) {
// error๋Š” getRequest ์•ˆ์—์„œ logging ๋˜์—ˆ์Œ.
// ์ธ์ฆ ์ฝ”๋“œ ๋ฐœ์†ก ์‹คํŒจํ–ˆ์œผ๋ฏ€๋กœ view ๋Œ๋ ค๋†“๊ธฐ
resetEmailVerification();
}
}

// ์ด๋ฉ”์ผ ํฌ๋งท ๊ฒ€์‚ฌ ํ•จ์ˆ˜
function checkEmailInput(email) {
const emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
return emailPattern.test(email);
}

// ์ด๋ฉ”์ผ input readonly ํ’€๊ณ  + check button ๋Œ๋ ค๋†“๋Š” ํ•จ์ˆ˜
function resetEmailVerification() {
let emailInput = document.getElementById('email-input');
let emailCheckButton = document.getElementById('email-check-button');
let boxDiv = document.getElementById('email-verification-box');

// global check ๋ณ€์ˆ˜
CHECK_EMAIL = false;

emailInput.readOnly = false;
emailCheckButton.innerText = "์ด๋ฉ”์ผ ์ธ์ฆ";
emailCheckButton.classList.remove('active');
emailCheckButton.onclick = handleEmailCodeButtonClicked;
boxDiv.remove(); // ์ธ์ฆ ์ฝ”๋“œ ์˜์—ญ ์ œ๊ฑฐ
}


/*****************************************************************
[๋ฒ„ํŠผ ์ด๋ฒคํŠธ ํ•จ์ˆ˜]
์ด๋ฉ”์ผ ์ธ์ฆ ํ™•์ธ ๋ฒ„ํŠผ ํด๋ฆญ ์‹œ ์ž‘๋™
*/
async function validateEmailCode() {
// ์ž…๋ ฅ๋œ ์ฝ”๋“œ ๊ฐ’ ๊ฐ€์ ธ์˜ค๊ธฐ
const input = document.getElementById('email-code-input');
const code = input.value;

// ์ธ์ฆ ํ™•์ธ
try {
await getRequest(API_GATEWAY_HOST + "/v2/auth/email/code?to=" + code);
let button = document.getElementById('email-code-check-button');
button.innerText = "์ธ์ฆ ์™„๋ฃŒ";
button.classList.add("disable");
button.onclick = null;
} catch (error) {
console.error(error);
alert(error.message);
// readonly ํ’€๊ณ  ์ธ์ฆ๋ฒ„ํŠผ ๋Œ๋ ค๋†“๊ธฐ
resetEmailVerification();
}
}



/*****************************************************************
[๋ฒ„ํŠผ ์ด๋ฒคํŠธ ํ•จ์ˆ˜]
ํœด๋Œ€ํฐ ์ธ์ฆ ๋ฒ„ํŠผ ํด๋ฆญ ์‹œ ์ž‘๋™
*/
async function handlePhoneCodeButtonClicked() {
const phonePrefix = document.getElementById('phone-prefix')
const phoneInput = document.getElementById('phone-input')
const phone = phonePrefix.value + phoneInput.value;
console.log('phone prefix + input:', phone);

// ์ธ์ฆ์ฝ”๋“œ ๋ฐœ์†ก (์—ฌ๊ธฐ๋„ await ํ•˜์ง€ ์•Š๋Š”๊ฒŒ ์ข‹์€๋ฐ ๋ฐ”์˜๋‹ˆ ์ผ๋‹จ ํ•ด๋†“์ž)
await sendPhoneCode();

// prefix disable & input readonly ์ฒ˜๋ฆฌ + ํœด๋Œ€ํฐ ์ธ์ฆ ๋ฒ„ํŠผ ๋น„ํ™œ์„ฑํ™”
let phoneCheckButton = document.getElementById('phone-check-button');
phonePrefix.disabled = true;
phoneInput.readOnly = true;
phoneCheckButton.innerText = "์ธ์ฆ ์ดˆ๊ธฐํ™”";
phoneCheckButton.classList.add('active');
phoneCheckButton.onclick = resetPhoneVerification; // onclick ํ•จ์ˆ˜๋ฅผ ์ธ์ฆ ์ดˆ๊ธฐํ™” ํ•จ์ˆ˜๋กœ ๋ณ€๊ฒฝ

// global check ๋ณ€์ˆ˜
CHECK_PHONE = true;

// ํœด๋Œ€ํฐ ๋ฒˆํ˜ธ input ํ•˜๋‹จ์— ์ธ์ฆ์ฝ”๋“œ ์ž…๋ ฅ input๊ณผ [์ธ์ฆ ํ™•์ธ] ๋ฒ„ํŠผ ํ‘œ์‹œ
if (!document.getElementById('phone-verification-box')) { // ํ˜„์žฌ DOM์— ์—†์œผ๋ฉด
let newChildDiv = document.createElement('div');
newChildDiv.classList.add("group-content-box");
newChildDiv.id = 'phone-verification-box';
let childInnerHtml = `
<div class="group-content-label"></div>
<input id="phone-code-input" type="text" placeholder="30๋ถ„ ๋‚ด์— ๋ฐœ์†ก๋œ ์ฝ”๋“œ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”." />
<button class="signup-check-button" id="phone-code-check-button" onclick="validatePhoneCode()">์ธ์ฆ ํ™•์ธ</button>
`;
newChildDiv.innerHTML = childInnerHtml;

let signupGroup = document.getElementById('signup-group-bottom');
signupGroup.insertBefore(newChildDiv, signupGroup.children[2]);
}
}

// API ํ˜ธ์ถœํ•ด์„œ ์ธ์ฆ ์ฝ”๋“œ ๋ณด๋‚ด๋ณด๊ณ , ์‹คํŒจํ•˜๋ฉด view ๋˜๋Œ๋ฆฌ๋Š” ํ•จ์ˆ˜
async function sendPhoneCode(phone) {
try {
await getRequest(API_GATEWAY_HOST + "/v2/auth/phone/code?to=" + phone);
} catch (error) {
// error๋Š” getRequest ์•ˆ์—์„œ logging ๋˜์—ˆ์Œ.
// ์ธ์ฆ ์ฝ”๋“œ ๋ฐœ์†ก ์‹คํŒจํ–ˆ์œผ๋ฏ€๋กœ view ๋Œ๋ ค๋†“๊ธฐ
resetPhoneVerification();
}
}


/*****************************************************************
[๋ฒ„ํŠผ ์ด๋ฒคํŠธ ํ•จ์ˆ˜]
ํœด๋Œ€ํฐ ์ธ์ฆ ํ™•์ธ ๋ฒ„ํŠผ ํด๋ฆญ ์‹œ ์ž‘๋™
*/
async function validatePhoneCode() {
// ์ž…๋ ฅ๋œ ์ฝ”๋“œ ๊ฐ’ ๊ฐ€์ ธ์˜ค๊ธฐ
const code = document.getElementById('phone-code-input').value;

// ์ธ์ฆ ํ™•์ธ
await getRequest(API_GATEWAY_HOST + "/v2/auth/phone/code?to=" + code);
}



function resetPhoneVerification() {
let phonePrefix = document.getElementById('phone-prefix');
let phoneInput = document.getElementById('phone-input');
let phonelCheckButton = document.getElementById('phone-check-button');
let boxDiv = document.getElementById('phone-verification-box');

// global check ๋ณ€์ˆ˜
CHECK_PHONE = false;

phonePrefix.disabled = false;
phoneInput.readOnly = false;
phonelCheckButton.innerText = "ํœด๋Œ€ํฐ ์ธ์ฆ";
phonelCheckButton.classList.remove('active');
phonelCheckButton.onclick = handlePhoneCodeButtonClicked;
boxDiv.remove(); // ์ธ์ฆ ์ฝ”๋“œ ์˜์—ญ ์ œ๊ฑฐ
}



/*****************************************************************
[์ž…๋ ฅ ์ด๋ฒคํŠธ ํ•จ์ˆ˜]
input ํƒ€์ดํ•‘ ์‹œ ์ž‘๋™
*/
function checkEmailInputEmpty(event) {
// ์ด๋ฉ”์ผ input ๊ณต๋ž€ ์—ฌ๋ถ€ ๊ฒ€์‚ฌ
let button = document.getElementById('email-check-button');

if (event.value.length < 1) {
button.classList.add('disable');
button.onclick = null;
}
else {
button.classList.remove('disable');
button.onclick = sendEmailCode;
}
}

function checkPasswordValid(event) {
// 8์ž ์ด์ƒ ์ˆซ์ž/๋Œ€์†Œ๋ฌธ์ž/ํŠน์ˆ˜๋ฌธ์ž ๋ชจ๋‘ ํฌํ•จ ์กฐ๊ฑด์— ๋ถ€ํ•ฉํ•˜๋Š”์ง€ ๊ฒ€์‚ฌ
let pwInput = event.value;
const passwordPattern = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[!@#$%^&*()_+={}\[\]:;"'<>,.?/-]).{8,}$/;

let pwReInput = document.getElementById('pw-re-input');
let pwCheckDiv = document.getElementById('pw-check');
if (passwordPattern.test(pwInput)) {
pwReInput.placeholder = '๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žฌ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”.';
pwReInput.readOnly = false;
pwReInput.oninput = checkPasswordMatch;
pwCheckDiv.style.visibility = 'unset';
}
else {
pwReInput.placeholder = '8์ž ์ด์ƒ ์ˆซ์ž/๋Œ€์†Œ๋ฌธ์ž/ํŠน์ˆ˜๋ฌธ์ž๋ฅผ ๋ชจ๋‘ ํฌํ•จํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.';
pwReInput.readOnly = true;
pwReInput.oninput = null;
pwCheckDiv.style.visibility = 'hidden';
}
}

function checkPasswordMatch(event) {
// ๋น„๋ฐ€๋ฒˆํ˜ธ ์žฌ์ž…๋ ฅ ๊ฐ’์ด ๊ธฐ์กด๊ณผ ๋™์ผํ•œ์ง€ ๊ฒ€์‚ฌ
let pwInput = document.getElementById('pw-input').value;
let pwReInput = event.target.value;
let pwCheckDiv = document.getElementById('pw-check');
console.log(pwInput, pwReInput)

if (pwInput === pwReInput) {
pwCheckDiv.classList.add('ok');
pwCheckDiv.innerText = '๋น„๋ฐ€๋ฒˆํ˜ธ ์ผ์น˜';
// global check ๋ณ€์ˆ˜
CHECK_PW = true;
}
else {
pwCheckDiv.classList.remove('ok');
pwCheckDiv.innerText = '๋น„๋ฐ€๋ฒˆํ˜ธ ๋ถˆ์ผ์น˜';
// global check ๋ณ€์ˆ˜
CHECK_PW = false;
}
}

function checkPhoneValid(event) {
// 8์ž๋ฆฌ ์ˆซ์ž ์—ฌ๋ถ€ ๊ฒ€์‚ฌ
const digitPattern = /^\d{8}$/;
const button = document.getElementById('phone-check-button');

if (digitPattern.test(event.value)) {
button.classList.remove('disable');
button.onclick = handlePhoneCodeButtonClicked;
}
else {
button.classList.add('disable');
button.onclick = null;
}
}



/* axios request */
async function getRequest(endpoint) {
try {
const response = await axios.get(endpoint);
console.log(response);
return response;
} catch (error) {
console.error(error);
alert("์„œ๋ฒ„์™€์˜ ํ†ต์‹ ์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค.");
throw error;
}
}

async function postRequest(endpoint, requestBody) {
try {
const response = await axios.post(endpoint, requestBody);
console.log(response);
return response;
} catch (error) {
console.error(error);
alert("์„œ๋ฒ„์™€์˜ ํ†ต์‹ ์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค.");
}
}