-
Notifications
You must be signed in to change notification settings - Fork 37
[이민서] Sprint4 #152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The head ref may contain hidden characters: "Basic-\uC774\uBBFC\uC11C-sprint4"
[이민서] Sprint4 #152
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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']"); | ||
|
|
||
| // 오류 메세지 노출 함수 | ||
| function showError(input, errorClass) { | ||
|
|
@@ -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(); | ||
|
|
||
| // 오류 메세지 및 입력 필드 상태 초기화 | ||
|
|
@@ -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; | ||
|
|
@@ -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
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. HTML에서 이렇게 <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) { | ||
|
|
@@ -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
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
하지만 연습이라는 의미에서는 좋습니다~ |
||
| }); | ||
| } | ||
| // 회원가입 폼 처리 | ||
| if (signupForm) { | ||
| signupForm.addEventListener("submit", (event) => { | ||
| event.preventDefault(); | ||
| removeEventListeners(); // 폼 제출 시 이벤트 제거 | ||
| window.location.href = "/login.html"; | ||
| }); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
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 다루는 연습을 미리 해두시면 좋을것 같아요!