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
8 changes: 5 additions & 3 deletions login.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@
placeholder="비밀번호를 입력해 주세요"
required
>
<img
class="toggle-password"
<button type="button" class="password-toggle-button">
<img
class="password-toggle-icon"
src="/images/icons/eye-invisible.svg"
alt="비밀번호 숨김"
alt="비밀번호 숨김 상태 아이콘"
>
</button>
</div>
<span class="password-empty-error error-message">비밀번호를 입력해 주세요</span>
<span class="password-invalid-error error-message">비밀번호를 8자 이상 입력해 주세요</span>
Expand Down
66 changes: 55 additions & 11 deletions scripts/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ document.addEventListener("DOMContentLoaded", () => {
let isNicknameValid = false;
let isPasswordValid = false;
let isPasswordConfirmationValid = false;

const emailRegex = /^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/;

const loginForm = document.querySelector('.login-form');
const signupForm = document.querySelector('.signup-form');
const emailInput = document.querySelector('#email');
const nicknameInput = document.querySelector('#nickname');
const passwordInput = document.querySelector('#password');
const passwordConfirmationInput = document.querySelector('#passwordConfirmation');
const submitButton = document.querySelector('button[type="submit"]');
const loginForm = document.querySelector(".login-form");
const signupForm = document.querySelector(".signup-form");
const emailInput = document.querySelector("#email");
const nicknameInput = document.querySelector("#nickname");
const passwordInput = document.querySelector("#password");
const passwordConfirmationInput = document.querySelector("#passwordConfirmation");
const submitButton = document.querySelector("button[type='submit']");
Comment on lines -7 to +15
Copy link
Collaborator

Choose a reason for hiding this comment

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

이런 부분은 커밋 이름인 feat(auth): 비밀번호 표시/숨기기 아이콘 토글 기능 추가 과 연관성이 없고 사전에 self-review를 진행했다면 나오지 않을 불필요한 변경점 인 것 같아요 ㅎ

뭐 크리티컬하게 문제가 있는 부분은 아니긴한데 커밋을 잘 통제할 수 있도록 git 다루는 연습을 미리 해두시면 좋을것 같아요!


// 오류 메세지 노출 함수
function showError(input, errorClass) {
Expand All @@ -27,14 +29,12 @@ document.addEventListener("DOMContentLoaded", () => {
}

// 이메일 형식 유효성 검사
function validateEmailString(email) {
const emailRegex = /^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/;
function isEmailValidFormat(email) {
return emailRegex.test(email);
}

// 이메일 필드 유효성 검사
function checkEmailValidity() {
// 입력 필드 선택 후 아무것도 입력 안 하고 필드 focus out하는 경우 걸러내기 위함
const emailValue = emailInput.value.trim();

// 오류 메세지 및 입력 필드 상태 초기화
Expand All @@ -44,7 +44,7 @@ document.addEventListener("DOMContentLoaded", () => {

if (!emailValue) {
showError(emailInput, "email-empty-error");
} else if (!validateEmailString(emailValue)) {
} else if (!isEmailValidFormat(emailValue)) {
showError(emailInput, "email-invalid-error");
} else {
isEmailValid = true;
Expand Down Expand Up @@ -127,6 +127,25 @@ document.addEventListener("DOMContentLoaded", () => {
submitButton.disabled = !isFormValid;
}

// 비밀번호 토글 버튼 동작
function togglePasswordVisibility(event) {
const button = event.currentTarget;
const inputField = button.parentElement.querySelector("input");
const toggleIcon = button.querySelector(".password-toggle-icon");

// 비밀번호가 표시된 상태인지 확인
const isPasswordVisible = inputField.type === "text";

inputField.type = isPasswordVisible ? "password" : "text";
toggleIcon.src = isPasswordVisible ? "/images/icons/eye-invisible.svg" : "/images/icons/eye-visible.svg"
toggleIcon.alt = isPasswordVisible ? "비밀번호 숨김 상태 아이콘" : "비밀번호 표시 상태 아이콘";
Comment on lines +140 to +141
Copy link
Collaborator

Choose a reason for hiding this comment

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

HTML에서 이렇게 data- 속성을 지정하면 js에서 이렇게 간편하게 쓸 수 있어요~

<button class="password-toggle-button"
  data-visible-icon="/images/icons/eye-visible.svg"
  data-invisible-icon="/images/icons/eye-invisible.svg"
  data-visible-alt="비밀번호 표시 상태 아이콘"
  data-invisible-alt="비밀번호 숨김 상태 아이콘">
  <img class="password-toggle-icon" src="/images/icons/eye-invisible.svg" alt="비밀번호 숨김 상태 아이콘">
</button>

JS

 // 데이터 속성에서 아이콘 및 대체 텍스트 가져오기
  const visibleIcon = button.dataset.visibleIcon;
  const invisibleIcon = button.dataset.invisibleIcon;
  const visibleAlt = button.dataset.visibleAlt;
  const invisibleAlt = button.dataset.invisibleAlt;

}

// 비밀번호 토글 버튼에 이벤트 리스너 추가
const toggleButtons = document.querySelectorAll(".password-toggle-button");
toggleButtons.forEach((button) =>
button.addEventListener("click", togglePasswordVisibility)
);

// 입력 필드에 이벤트 리스너 추가
if (emailInput) {
Expand All @@ -144,18 +163,43 @@ document.addEventListener("DOMContentLoaded", () => {
passwordConfirmationInput.addEventListener("input", checkPasswordConfirmationValidity);
}

// 폼 제출 전 이벤트 리스너 제거
function removeEventListeners() {
if (emailInput) {
emailInput.removeEventListener("focusout", checkEmailValidity);
}
if (nicknameInput) {
nicknameInput.removeEventListener("focusout", checkNicknameValidity);
}
if (passwordInput) {
passwordInput.removeEventListener("focusout", checkPasswordValidity);
passwordInput.removeEventListener("input", checkPasswordValidity);
}
if (passwordConfirmationInput) {
passwordConfirmationInput.removeEventListener("focusout", checkPasswordConfirmationValidity);
passwordConfirmationInput.removeEventListener("input", checkPasswordConfirmationValidity);
}

// 비밀번호 토글 버튼의 이벤트 리스너 제거
toggleButtons.forEach((button) =>
button.removeEventListener("click", togglePasswordVisibility)
);
}

// 이후 기능 추가 후 수정 (현재는 단순히 특정 페이지로 이동)
// 로그인 폼 처리
if (loginForm) {
loginForm.addEventListener("submit", (event) => {
event.preventDefault();
removeEventListeners(); // 폼 제출 시 이벤트 제거
window.location.href = "/index.html";
Comment on lines +194 to 195
Copy link
Collaborator

Choose a reason for hiding this comment

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

window.location.href = "/index.html" 를 사용하면 어차피 새로운 페이지로 넘어가면서 기존 페이지의 스크립트와 이벤트 리스너는 자동으로 해제됩니다. 때문에 removeEventListeners()를 굳이 할 필요가 있을까? 싶긴 하네요 ㅎㅎ

하지만 연습이라는 의미에서는 좋습니다~

});
}
// 회원가입 폼 처리
if (signupForm) {
signupForm.addEventListener("submit", (event) => {
event.preventDefault();
removeEventListeners(); // 폼 제출 시 이벤트 제거
window.location.href = "/login.html";
});
}
Expand Down
20 changes: 12 additions & 8 deletions signup.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@
placeholder="비밀번호를 입력해 주세요"
required
>
<img
class="toggle-password"
<button type="button" class="password-toggle-button">
<img
class="password-toggle-icon"
src="/images/icons/eye-invisible.svg"
alt="비밀번호 숨김"
alt="비밀번호 숨김 상태 아이콘"
>
</button>
</div>
<span class="password-empty-error error-message">비밀번호를 입력해 주세요</span>
<span class="password-invalid-error error-message">비밀번호를 8자 이상 입력해 주세요</span>
Expand All @@ -69,11 +71,13 @@
placeholder="비밀번호를 다시 한 번 입력해 주세요"
required
/>
<img
src="images/icons/eye-invisible.svg"
alt="비밀번호 숨김"
class="toggle-password"
/>
<button type="button" class="password-toggle-button">
<img
class="password-toggle-icon"
src="/images/icons/eye-invisible.svg"
alt="비밀번호 숨김 상태 아이콘"
>
</button>
</div>
<span class="password-confirmation-error error-message">비밀번호가 일치하지 않습니다.</span>
</div>
Expand Down
24 changes: 3 additions & 21 deletions styles/auth.css
Original file line number Diff line number Diff line change
@@ -1,34 +1,16 @@
.auth-container {
max-width: 64rem;
margin: 0 auto;

@media (max-width: 767px) {
max-width: 40rem;
padding: 0 1.6rem;
}
}

.auth-container.login {
margin-top: 15rem;

@media (max-width: 1199px) {
margin-top: 12rem;
}

@media (max-width: 767px) {
margin-top: 8rem;
}
}

.auth-container.signup {
margin-top: 6rem;

@media (max-width: 1199px) {
margin-top: 4.8rem;
}

@media (max-width: 767px) {
max-width: 40rem;
margin-top: 2.4rem;
padding: 0 1.6rem;
}
}

Expand Down Expand Up @@ -109,7 +91,7 @@ input:focus {
display: none;
}

.toggle-password {
.password-toggle-button {
position: absolute;
right: 2.4rem;
cursor: pointer;
Expand Down
20 changes: 9 additions & 11 deletions styles/home.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ nav {
border-bottom: 0.1rem solid var(--color-grey);

@media (max-width: 1199px) {
max-width: 70rem;
padding: 0 5rem;
margin: 0;
}

@media (max-width: 767px) {
max-width: 40rem;
padding: 0 2rem;
}
}

Expand Down Expand Up @@ -62,11 +63,11 @@ main {
width: 100%;

@media (max-width: 1199px) {
max-width: 70rem;
max-width: 100rem;
}

@media (max-width: 767px) {
max-width: 40rem;
max-width: 70rem;
}
}

Expand Down Expand Up @@ -156,12 +157,11 @@ main {
width: 100%;

@media (max-width: 1199px) {
max-width: 69.6rem;
padding: 0 2.5rem;
padding: 0 3rem;
}

@media (max-width: 767px) {
max-width: 344rem;
padding: 0 2rem;
}
}

Expand Down Expand Up @@ -271,20 +271,18 @@ footer {
font-size: 1.6rem;

@media (max-width: 1199px) {
max-width: 70rem;
padding: 3.2rem 0 10.8rem;
padding: 3.2rem 5rem 10.8rem;
}

@media (max-width: 767px) {
max-width: 40rem;
padding: 3.2rem 2rem 6.5rem;
display: grid;
grid-template-columns: 1fr 1fr;
grid-template-rows: auto auto;
grid-template-areas:
"footer-menu socialMedia"
"copyright .";
gap: 2.5rem;
padding: 3.2rem 0 6.5rem;
}
}

Expand Down