Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions javascript/login&signuppage/login.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
const emailInput = document.getElementById("emailInput");
const emailError = document.getElementById("emailError");
const passwordInput = document.getElementById("passwardinput");
const passwordError = document.getElementById("passwordError");
const loginButton = document.getElementById("loginButton");
const togglePassword = document.getElementById("togglePassword");

/* 이미지 파일 경로 설정 */
const eyeOpenSrc = "./images/anyicons/passwardeye.svg";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

대체로 변수, 함수명이 직관적이고 명확합니다 👍 👍

const eyeSlashSrc = "./images/anyicons/passwardcancel.svg";

/* 초기 상태 설정 */
let isPasswordVisible = false;

/* 이메일 정규표현식 */
const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

정규식을 써주셨군요~! 💯


/* 유효성 검사 상태 변수 */
let isEmailValid = false;
let isPasswordValid = false;

/* 📌 유효성 검사 후 버튼 활성화 체크 */
const updateButtonState = () => {
if (isEmailValid && isPasswordValid) {
loginButton.disabled = false;
} else {
loginButton.disabled = true;
}
};

/* 📌 이메일 Focus Out 체크 */
emailInput.addEventListener("focusout", () => {
const value = emailInput.value.trim();

if (!value) {
emailInput.classList.add("error");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

에러를 추가하고 제거하는 로직이 반복되고 있네요! 이런 경우 함수로 정의해 주시면 재사용도 쉽고 가독성도 높일 수 있습니다 :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

function addError(id, message) {
  const $emailInput = document.getElementById(`${id}Input`);
  const $emailError = document.getElementById(`${id}Error`);
  //..
}

emailError.textContent = "이메일을 입력해주세요.";
emailError.style.display = "block";
isEmailValid = false;
} else if (!emailPattern.test(value)) {
emailInput.classList.add("error");
emailError.textContent = "잘못된 이메일 형식입니다.";
emailError.style.display = "block";
isEmailValid = false;
} else {
emailInput.classList.remove("error");
emailError.style.display = "none";
isEmailValid = true;
}
updateButtonState();
});

/* 📌 비밀번호 Focus Out 체크 */
passwordInput.addEventListener("focusout", () => {
const value = passwordInput.value.trim();

if (!value) {
passwordInput.classList.add("error");
passwordError.textContent = "비밀번호를 입력해주세요.";
passwordError.style.display = "block";
isPasswordValid = false;
} else if (value.length < 8) {
passwordInput.classList.add("error");
passwordError.textContent = "비밀번호를 8자 이상 입력해주세요.";
passwordError.style.display = "block";
isPasswordValid = false;
} else {
passwordInput.classList.remove("error");
passwordError.style.display = "none";
isPasswordValid = true;
}
updateButtonState();
});

/* 📌 버튼 클릭 시 페이지 이동 */
loginButton.addEventListener("click", () => {
if (isEmailValid && isPasswordValid) {
window.location.href = "/items";
}
});

/* 클릭 이벤트 */
togglePassword.addEventListener("click", () => {
isPasswordVisible = !isPasswordVisible;
if (isPasswordVisible) {
passwordInput.type = "text";
togglePassword.src = eyeOpenSrc;
} else {
passwordInput.type = "password";
togglePassword.src = eyeSlashSrc;
}
});
158 changes: 158 additions & 0 deletions javascript/login&signuppage/signup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
const emailInput = document.getElementById("emailInput");
const nicknameInput = document.getElementById("nicknameInput");
const passwordInput = document.getElementById("passwordInput");
const passwordConfirmInput = document.getElementById("passwordConfirmInput");
const signupButton = document.getElementById("signup-button");

const emailError = document.getElementById("emailError");
const nicknameError = document.getElementById("nicknameError");
const passwordError = document.getElementById("passwordError");
const passwordConfirmError = document.getElementById("passwordConfirmError");

const togglePassword = document.getElementById("togglePassword");
const togglePasswordConfirm = document.getElementById("togglePasswordConfirm");

/* 이미지 파일 경로 설정 */
const eyeOpenSrc = "./images/anyicons/passwardeye.svg";
const eyeSlashSrc = "./images/anyicons/passwardcancel.svg";

/* 초기 상태 */
let isPasswordVisible = false;
let isPasswordConfirmVisible = false;

/* 이메일 정규표현식 */
const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

login 과 겹치는 부분이 많은데 이런 경우 공통 부분을 따로 정의하고 import 해서 쓰셔도 좋습니다 :)

https://developer.mozilla.org/ko/docs/Web/JavaScript/Guide/Modules#applying_the_module_to_your_html


/* 유효성 상태 */
let isEmailValid = false;
let isNicknameValid = false;
let isPasswordValid = false;
let isPasswordMatch = false;

/* 비밀번호 보이기/숨기기 토글 */
togglePassword.addEventListener("click", () => {
isPasswordVisible = !isPasswordVisible;
if (isPasswordVisible) {
passwordInput.type = "text";
togglePassword.src = eyeOpenSrc;
} else {
passwordInput.type = "password";
togglePassword.src = eyeSlashSrc;
}
});

/* 비밀번호 확인 보이기/숨기기 토글 */
togglePasswordConfirm.addEventListener("click", () => {
isPasswordConfirmVisible = !isPasswordConfirmVisible;
if (isPasswordConfirmVisible) {
passwordConfirmInput.type = "text";
togglePasswordConfirm.src = eyeOpenSrc;
} else {
passwordConfirmInput.type = "password";
togglePasswordConfirm.src = eyeSlashSrc;
}
});

/* 📌 유효성 검사 함수 */
const validateEmail = () => {
const value = emailInput.value.trim();
if (!value) {
emailInput.classList.add("error");
emailError.textContent = "이메일을 입력해주세요.";
emailError.style.display = "block";
isEmailValid = false;
} else if (!emailPattern.test(value)) {
emailInput.classList.add("error");
emailError.textContent = "잘못된 이메일 형식입니다.";
emailError.style.display = "block";
isEmailValid = false;
} else {
emailInput.classList.remove("error");
emailError.style.display = "none";
isEmailValid = true;
}
};

const validateNickname = () => {
const value = nicknameInput.value.trim();
if (!value) {
nicknameInput.classList.add("error");
nicknameError.textContent = "닉네임을 입력해주세요.";
nicknameError.style.display = "block";
isNicknameValid = false;
} else {
nicknameInput.classList.remove("error");
nicknameError.style.display = "none";
isNicknameValid = true;
}
};

const validatePassword = () => {
const value = passwordInput.value.trim();
if (!value) {
passwordInput.classList.add("error");
passwordError.textContent = "비밀번호를 입력해주세요.";
passwordError.style.display = "block";
isPasswordValid = false;
} else if (value.length < 8) {
passwordInput.classList.add("error");
passwordError.textContent = "비밀번호를 8자 이상 입력해주세요.";
passwordError.style.display = "block";
isPasswordValid = false;
} else {
passwordInput.classList.remove("error");
passwordError.style.display = "none";
isPasswordValid = true;
}
};

const validatePasswordConfirm = () => {
const value = passwordConfirmInput.value.trim();
if (value !== passwordInput.value.trim()) {
passwordConfirmInput.classList.add("error");
passwordConfirmError.textContent = "비밀번호가 일치하지 않습니다.";
passwordConfirmError.style.display = "block";
isPasswordMatch = false;
} else {
passwordConfirmInput.classList.remove("error");
passwordConfirmError.style.display = "none";
isPasswordMatch = true;
}
};

/* 📌 입력 변경 시 실시간 검증 */
emailInput.addEventListener("focusout", () => {
validateEmail();
updateButtonState();
});

nicknameInput.addEventListener("focusout", () => {
validateNickname();
updateButtonState();
});

passwordInput.addEventListener("focusout", () => {
validatePassword();
updateButtonState();
});

passwordConfirmInput.addEventListener("focusout", () => {
validatePasswordConfirm();
updateButtonState();
});

/* 📌 유효성 검사 후 버튼 활성화 체크 */
const updateButtonState = () => {
if (isEmailValid && isNicknameValid && isPasswordValid && isPasswordMatch) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

크게 상관 없지만.. 이렇게 나타낼 수도 있겠네요!

signupButton.disabled = !(isEmailValid && isNicknameValid && isPasswordValid && isPasswordMatch);

signupButton.disabled = false;
} else {
signupButton.disabled = true;
}
};

/* 📌 회원가입 버튼 클릭 시 페이지 이동 */
signupButton.addEventListener("click", () => {
if (isEmailValid && isNicknameValid && isPasswordValid && isPasswordMatch) {
window.location.href = "./login.html";
}
});
23 changes: 21 additions & 2 deletions login.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,23 @@
<section class="loginsection">
<div id="emailbox">
<label class="loginlabel"> 이메일 </label>
<input class="logininput" alt="email" />
<input
id="emailInput"
class="logininput"
alt="email"
placeholder="이메일을 입력해주세요"
/>
<div
id="emailError"
class="error-message"
style="display: none"
></div>
</div>
<div id="passwardbox">
<label class="loginlabel"> 비밀번호 </label>
<div class="password-wrapper">
<input
placeholder="비밀번호를 입력해주세요"
class="logininput"
id="passwardinput"
type="password"
Expand All @@ -44,8 +55,15 @@
id="togglePassword"
/>
</div>
<div
id="passwordError"
class="error-message"
style="display: none"
></div>
</div>
<button id="loginbutton" class="button pill-button">로그인</button>
<button id="loginButton" class="button pill-button" disabled>
로그인
</button>
<section class="socialloginsection">
<div id="sociallogintext">간편 로그인하기</div>
<div id="socialloginicon">
Expand All @@ -63,5 +81,6 @@
</div>
</section>
</div>
<script src="/javascript/login&signuppage/login.js"></script>
</body>
</html>
44 changes: 35 additions & 9 deletions signup.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,31 @@
<div class="signup-box">
<label class="signup-label"> 이메일 </label>
<input
id="emailInput"
class="login-input"
alt="email"
placeholder="이메일을 입력해주세요"
/>
<div
id="emailError"
class="error-message"
style="display: none"
></div>
</div>

<div class="signup-box">
<label class="signup-label"> 닉네임 </label>
<input
id="nicknameInput"
class="login-input"
alt="nickname"
placeholder="닉네임을 입력해주세요"
/>
<div
id="nicknameError"
class="error-message"
style="display: none"
></div>
</div>

<div class="signup-box">
Expand All @@ -50,16 +62,21 @@
<input
placeholder="비밀번호를 입력해주세요"
class="login-input"
id="passward-input"
id="passwordInput"
type="password"
alt="passward"
alt="password"
/>
<img
src="./images/anyicons/passwardcancel.svg"
alt="비밀번호 보기 토글"
id="toggle-Password"
alt="passwardtoggle"
id="togglePassword"
/>
</div>
<div
id="passwordError"
class="error-message"
style="display: none"
></div>
</div>

<div class="signup-box">
Expand All @@ -68,19 +85,27 @@
<input
placeholder="비밀번호를 다시 한 번 입력해주세요"
class="login-input"
id="passward-input"
id="passwordConfirmInput"
type="password"
alt="passward"
alt="password-confirm"
/>

<img
src="./images/anyicons/passwardcancel.svg"
alt="비밀번호 보기 토글"
id="toggle-Password"
alt="passwardtoggle"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

기능을 가진 아이콘이라면 버튼을 감싸주시거나 aria-label등을 활용해 주시는 것이 접근성에 좋습니다 :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

네 확인했습니다!

id="togglePasswordConfirm"
/>
</div>
<div
id="passwordConfirmError"
class="error-message"
style="display: none"
></div>
</div>

<button id="signup-button" class="button pill-button">회원가입</button>
<button id="signup-button" class="button pill-button" disabled>
회원가입
</button>

<section class="social-login-section">
<div id="social-login-text">간편 로그인하기</div>
Expand All @@ -100,6 +125,7 @@
</div>
</section>
</div>
<script src="./javascript/login&signuppage/signup.js"></script>
</body>
<!-- 바디부분 -->
</html>
Loading
Loading