-
Notifications
You must be signed in to change notification settings - Fork 26
[이재원] sprint4 #71
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\uC7AC\uC6D0-sprint4"
[이재원] sprint4 #71
Changes from all commits
08b54c6
d2394f9
32aee0b
c9b016c
1c7dae7
4557f08
de88b5d
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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
const $userId = document.querySelector('#userId'); | ||
const $IdError = document.querySelector('#IdError'); | ||
const $password = document.querySelector('#password'); | ||
const $passwordError = document.querySelector('#passwordError'); | ||
const $loginBtn = document.querySelector('#loginBtn'); | ||
const $viewIcon = document.querySelector('#viewIcon'); | ||
let idCheck = false; | ||
let passwordCheck = false; | ||
|
||
function btnCheck() { | ||
if (idCheck && passwordCheck) { | ||
$loginBtn.disabled = false; | ||
} else { | ||
$loginBtn.disabled = true; | ||
} | ||
} | ||
|
||
function handleFocustOutId() { | ||
const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; | ||
const value = $userId.value.trim(); | ||
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. 공백 입력을 고려한 trim() 메소드 활용 좋습니다! 👍 |
||
if (value === '') { | ||
$IdError.style.display = 'block'; | ||
$IdError.innerText = '이메일을 입력해주세요.'; | ||
$userId.style.border = '2px solid red'; | ||
idCheck = false; | ||
} else if (!emailPattern.test(value)) { | ||
$IdError.style.display = 'block'; | ||
$IdError.innerText = '잘못된 이메일 형식입니다.'; | ||
$userId.style.border = '2px solid red'; | ||
idCheck = false; | ||
} else { | ||
$IdError.style.display = 'none'; | ||
$userId.style.border = ''; | ||
idCheck = true; | ||
} | ||
btnCheck(); | ||
} | ||
function handleFocutOutPassWord() { | ||
const value = $password.value.trim(); | ||
if (value === '') { | ||
$passwordError.style.display = 'block'; | ||
$passwordError.innerText = '비밀번호를 입력해주세요.'; | ||
$password.style.border = '2px solid red'; | ||
passwordCheck = false; | ||
} else if (value.length < 8) { | ||
$passwordError.style.display = 'block'; | ||
$passwordError.innerText = '비밀번호를 8자 이상 입력해주세요.'; | ||
$password.style.border = '2px solid red'; | ||
passwordCheck = false; | ||
} else { | ||
$passwordError.style.display = 'none'; | ||
$password.style.border = ''; | ||
passwordCheck = true; | ||
} | ||
btnCheck(); | ||
} | ||
|
||
function handlePassWordView() { | ||
const isPassWordVisible = $password.type === 'text'; | ||
$password.type = isPassWordVisible ? 'password' : 'text'; | ||
$viewIcon.src = isPassWordVisible | ||
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. src 컨트롤로 토글 버튼 구현해주신 점 좋네요!👏 |
||
? 'images/eye-close.png' | ||
: 'images/eye-open.png'; | ||
} | ||
|
||
$userId.addEventListener('focusout', handleFocustOutId); | ||
$password.addEventListener('focusout', handleFocutOutPassWord); | ||
$viewIcon.addEventListener('click', handlePassWordView); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ | |
href="https://cdn.jsdelivr.net/gh/orioncactus/pretendard@v1.3.9/dist/web/static/pretendard.min.css" | ||
/> | ||
<link rel="stylesheet" href="styles/global.css" /> | ||
<link rel="stylesheet" href="styles/login-signup.css" /> | ||
<link rel="stylesheet" href="styles/auth.css" /> | ||
</head> | ||
|
||
<body> | ||
|
@@ -21,30 +21,41 @@ | |
<img src="images/logo.png" alt="판다마켓" class="signup-logo" /> | ||
</a> | ||
<div class="signup-content"> | ||
<form action="/signup" method="POST" class="signup-form"> | ||
<form action="login.html" method="POST" class="signup-form"> | ||
<div class="form-group"> | ||
<label for="userId">이메일</label> | ||
<input id="userId" type="email" name="email" /> | ||
<p id="IdError" style="display: none; color: red"></p> | ||
</div> | ||
<div class="form-group"> | ||
<label for="nickname">닉네임</label> | ||
<input id="nickname" type="text" name="text" /> | ||
<p id="nicknameError" style="display: none; color: red"></p> | ||
</div> | ||
<div class="form-group"> | ||
<label for="password">비밀번호</label> | ||
<div class="input-wrapper"> | ||
<input id="password" type="password" name="password" /> | ||
<img src="images/password-icon1.png" alt="보기 아이콘" /> | ||
<img id="viewIcon" src="images/eye-close.png" alt="보기 아이콘" /> | ||
<p id="passwordError" style="display: none; color: red"></p> | ||
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. 현재 에러 메세지 요소를 보여줄때, JS에서 직접 인라인 스타일을 조작하고 계신데요, 이는 간단한 방법이긴 하지만 CSS 클래스와 충돌하거나 덮어쓰기 위험이 있어 유지보수에 불리합니다. 차라리 아래와 같이 에러 메시지용 클래스를 정의하고, js에서는 클래스 추가/제거만 담당하는 구조로 수정해보시면 어떨까요?? /* CSS */
.error-message {
display: none;
color: red;
font-size: 14px;
}
.error-message.visible {
display: block;
} |
||
</div> | ||
</div> | ||
<div class="form-group"> | ||
<label for="passwordCheck">비밀번호 확인</label> | ||
<div class="input-wrapper"> | ||
<input id="passwordCheck" type="text" name="text" /> | ||
<img src="images/password-icon2.png" alt="보기 아이콘" /> | ||
<img id="viewIcon2" src="images/eye-open.png" alt="보기 아이콘" /> | ||
<p id="passwordCheckError" style="display: none; color: red"></p> | ||
</div> | ||
</div> | ||
<a href="login.html" class="signup-btn button">회원가입</a> | ||
<button | ||
type="submit" | ||
id="signupBtn" | ||
class="signup-btn button" | ||
disabled | ||
> | ||
회원가입 | ||
</button> | ||
</form> | ||
<div class="simple-login"> | ||
간편 로그인하기 | ||
|
@@ -62,5 +73,6 @@ | |
</div> | ||
</div> | ||
</div> | ||
<script src="signup.js"></script> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
const $userId = document.querySelector('#userId'); | ||
const $IdError = document.querySelector('#IdError'); | ||
const $nickName = document.querySelector('#nickname'); | ||
const $nicknameError = document.querySelector('#nicknameError'); | ||
const $password = document.querySelector('#password'); | ||
const $passwordError = document.querySelector('#passwordError'); | ||
const $passwordCheck = document.querySelector('#passwordCheck'); | ||
const $passwordCheckError = document.querySelector('#passwordCheckError'); | ||
const $signupBtn = document.querySelector('#signupBtn'); | ||
const $viewIcon = document.querySelector('#viewIcon'); | ||
const $viewIcon2 = document.querySelector('#viewIcon2'); | ||
let idCheck = false; | ||
let passwordCheck = false; | ||
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. passwordCheck라는 변수명이 비밀번호 일치 여부인지, 비밀번호 유효성인지 불명확한 것 같습니다. isPasswordValid, isPasswordConfirmed 등으로 명확히 분리하면 좋을 것 같습니다. |
||
let nicknameCheck = false; | ||
let passwordAuthCheck = false; | ||
|
||
function btnCheck() { | ||
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 (idCheck && passwordCheck && nicknameCheck && passwordAuthCheck) { | ||
$signupBtn.disabled = false; | ||
} else { | ||
$signupBtn.disabled = true; | ||
} | ||
} | ||
|
||
function handleFocustOutId() { | ||
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. 이메일 인풋과 관련된 이벤트핸들러이니 |
||
const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; | ||
const value = $userId.value.trim(); | ||
if (value === '') { | ||
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.
위와 같은 코드 라인이 이메일, 닉네임, 비밀번호 등에서 계속 반복되고 있습니다.
|
||
$IdError.style.display = 'block'; | ||
$IdError.innerText = '이메일을 입력해주세요.'; | ||
$userId.style.border = '2px solid red'; | ||
idCheck = false; | ||
} else if (!emailPattern.test(value)) { | ||
$IdError.style.display = 'block'; | ||
$IdError.innerText = '잘못된 이메일 형식입니다.'; | ||
$userId.style.border = '2px solid red'; | ||
idCheck = false; | ||
} else { | ||
$IdError.style.display = 'none'; | ||
$userId.style.border = ''; | ||
idCheck = true; | ||
} | ||
btnCheck(); | ||
} | ||
|
||
function handleFocusOutNickName() { | ||
const value = $nickName.value.trim(); | ||
if (value === '') { | ||
$nicknameError.style.display = 'block'; | ||
$nicknameError.innerText = '닉네임을 입력해주세요.'; | ||
$nickName.style.border = '2px solid red'; | ||
passwordCheck = false; | ||
} else { | ||
$nicknameError.style.display = 'none'; | ||
$nickName.style.border = ''; | ||
nicknameCheck = true; | ||
} | ||
btnCheck(); | ||
} | ||
|
||
function handleFocutOutPassWord() { | ||
const value = $password.value.trim(); | ||
if (value === '') { | ||
$passwordError.style.display = 'block'; | ||
$passwordError.innerText = '비밀번호를 입력해주세요.'; | ||
$password.style.border = '2px solid red'; | ||
passwordCheck = false; | ||
} else if (value.length < 8) { | ||
$passwordError.style.display = 'block'; | ||
$passwordError.innerText = '비밀번호를 8자 이상 입력해주세요.'; | ||
$password.style.border = '2px solid red'; | ||
passwordCheck = false; | ||
} else { | ||
$passwordError.style.display = 'none'; | ||
$password.style.border = ''; | ||
passwordCheck = true; | ||
} | ||
btnCheck(); | ||
} | ||
|
||
function handleFocusOutPassWordCheck() { | ||
const value = $passwordCheck.value.trim(); | ||
if (value === $password.value) { | ||
$passwordCheckError.style.display = 'none'; | ||
$passwordCheck.style.border = ''; | ||
passwordAuthCheck = true; | ||
} else { | ||
$passwordCheckError.style.display = 'block'; | ||
$passwordCheckError.innerText = '비밀번호가 일치하지 않습니다.'; | ||
$passwordCheck.style.border = '2px solid red'; | ||
passwordAuthCheck = false; | ||
} | ||
btnCheck(); | ||
} | ||
|
||
function handlePassWordView() { | ||
const isPassWordVisible = $password.type === 'text'; | ||
$password.type = isPassWordVisible ? 'password' : 'text'; | ||
$viewIcon.src = isPassWordVisible | ||
? 'images/eye-close.png' | ||
: 'images/eye-open.png'; | ||
} | ||
|
||
function handlePassWordView2() { | ||
const isPassWordVisible = $passwordCheck.type === 'text'; | ||
$passwordCheck.type = isPassWordVisible ? 'password' : 'text'; | ||
$viewIcon2.src = isPassWordVisible | ||
? 'images/eye-close.png' | ||
: 'images/eye-open.png'; | ||
} | ||
|
||
$userId.addEventListener('focusout', handleFocustOutId); | ||
$password.addEventListener('focusout', handleFocutOutPassWord); | ||
$nickName.addEventListener('focusout', handleFocusOutNickName); | ||
$passwordCheck.addEventListener('focusout', handleFocusOutPassWordCheck); | ||
$viewIcon.addEventListener('click', handlePassWordView); | ||
$viewIcon2.addEventListener('click', handlePassWordView2); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,6 +73,7 @@ | |
.signup-btn { | ||
height: 56px; | ||
border-radius: 40px; | ||
font-size: 20px; | ||
} | ||
|
||
.simple-login { | ||
|
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.
login.js 와 signup.js 에서 아래와 같은 유틸 함수가 중복되어 있습니다.
이러한 구조는 유지보수에 불리하고, 검증 기준이 바뀔 경우 양 파일을 모두 수정해야 하므로 실수를 유발하기 쉽습니다. 이런 유효성 판단 함수는 아래와 같이 ** 공통 유틸 함수**로 분리 하면 좋을 것 같네요.