-
Notifications
You must be signed in to change notification settings - Fork 39
[박지섭] sprint4 #154
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-\uBC15\uC9C0\uC12D-sprint4"
[박지섭] sprint4 #154
Changes from 5 commits
eb18053
c8db0a2
4c58a02
0f4b199
8f290b3
e9804bd
33104fd
cbea560
207b4fb
30061c7
f6d7d01
ae78424
2df8348
a272a02
f3d9da8
7d3772e
b6d53c5
c742e2e
5d79ad1
7d15f89
1d18116
5f39d9b
3782006
3331c60
9052253
9d79bba
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,18 @@ | ||
| export const EMAIL_VALIDATION = Object.freeze({ | ||
| invalid_email: '잘못된 이메일 형식입니다.', | ||
| required_email: '이메일을 입력해주세요.', | ||
| }); | ||
|
|
||
| export const NICKNAME_VALIDATION = Object.freeze({ | ||
| required_nickname: '닉네임을 입력해주세요.', | ||
| }); | ||
|
|
||
| export const PASSWORD_VALIDATION = Object.freeze({ | ||
| required_password: '비밀번호를 입력해주세요.', | ||
| invalid_password: '비밀번호를 8자 이상 입력해주세요.', | ||
| }); | ||
|
|
||
| export const CONFIRM_PASSWORD_VALIDATION = Object.freeze({ | ||
| required_confirm_password: '비밀번호를 다시 입력해주세요.', | ||
| not_matched_password: '비밀번호가 일치하지 않습니다.', | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| export const SYMBOL = Object.freeze({ | ||
| email_validate_regex: /^[^\s@]+@[^\s@]+\.[^\s@]+$/, | ||
| password_min_length: 8, | ||
| empty_message: '', | ||
| }); | ||
|
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. 💊 제안 |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,7 +36,7 @@ | |
| </div> | ||
| </div> | ||
|
|
||
| <button type="submit" class="auth__button">로그인</button> | ||
| <button type="submit" class="auth__button" disabled>로그인</button> | ||
| </form> | ||
|
|
||
| <div class="auth__social"> | ||
|
|
@@ -68,5 +68,7 @@ | |
| 375px 이상의 화면에서 이용해 주세요. | ||
| </div> | ||
| </div> | ||
|
|
||
| <script type="module" src="./scripts/login_validation.js"></script> | ||
|
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. 💊 제안 |
||
| </body> | ||
| </html> | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,74 @@ | ||||||||||||||||||||||||||||||||||||||||||||||
| import { validateEmail, validatePassword } from './validation/validation.js'; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| document.addEventListener('DOMContentLoaded', () => { | ||||||||||||||||||||||||||||||||||||||||||||||
| const emailInput = document.getElementById('email'); | ||||||||||||||||||||||||||||||||||||||||||||||
| const passwordInput = document.getElementById('password'); | ||||||||||||||||||||||||||||||||||||||||||||||
| const loginButton = document.querySelector('.auth__button'); | ||||||||||||||||||||||||||||||||||||||||||||||
| const loginForm = document.querySelector('form'); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+6
to
+7
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. 💬 여담
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| const showError = (input, message) => { | ||||||||||||||||||||||||||||||||||||||||||||||
| const wrapper = input.closest('.auth__input'); | ||||||||||||||||||||||||||||||||||||||||||||||
| wrapper.classList.add('auth__input-error'); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| let errorMessage = wrapper.querySelector('.auth__error-message'); | ||||||||||||||||||||||||||||||||||||||||||||||
| if (!errorMessage) { | ||||||||||||||||||||||||||||||||||||||||||||||
| errorMessage = document.createElement('span'); | ||||||||||||||||||||||||||||||||||||||||||||||
| errorMessage.className = 'auth__error-message'; | ||||||||||||||||||||||||||||||||||||||||||||||
| wrapper.appendChild(errorMessage); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| errorMessage.innerText = message; | ||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| const hideError = input => { | ||||||||||||||||||||||||||||||||||||||||||||||
| const wrapper = input.closest('.auth__input'); | ||||||||||||||||||||||||||||||||||||||||||||||
| wrapper.classList.remove('auth__input-error'); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| const errorMessage = wrapper.querySelector('.auth__error-message'); | ||||||||||||||||||||||||||||||||||||||||||||||
| if (errorMessage) { | ||||||||||||||||||||||||||||||||||||||||||||||
| errorMessage.remove(); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+26
to
+29
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. 💊 제안 |
||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| const updateButtonState = () => { | ||||||||||||||||||||||||||||||||||||||||||||||
| const emailValid = !validateEmail(emailInput.value.trim()); | ||||||||||||||||||||||||||||||||||||||||||||||
| const passwordValid = !validatePassword(passwordInput.value.trim()); | ||||||||||||||||||||||||||||||||||||||||||||||
| loginButton.disabled = !(emailValid && passwordValid); | ||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| const validateEmailInput = () => { | ||||||||||||||||||||||||||||||||||||||||||||||
| const email = emailInput.value.trim(); | ||||||||||||||||||||||||||||||||||||||||||||||
| hideError(emailInput); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| const error = validateEmail(email); | ||||||||||||||||||||||||||||||||||||||||||||||
| if (error) { | ||||||||||||||||||||||||||||||||||||||||||||||
| showError(emailInput, error); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| updateButtonState(); | ||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+38
to
+48
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. 💊 제안
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| const validatePasswordInput = () => { | ||||||||||||||||||||||||||||||||||||||||||||||
| const password = passwordInput.value.trim(); | ||||||||||||||||||||||||||||||||||||||||||||||
| hideError(passwordInput); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| const error = validatePassword(password); | ||||||||||||||||||||||||||||||||||||||||||||||
| if (error) { | ||||||||||||||||||||||||||||||||||||||||||||||
| showError(passwordInput, error); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| updateButtonState(); | ||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| emailInput.addEventListener('blur', validateEmailInput); | ||||||||||||||||||||||||||||||||||||||||||||||
| passwordInput.addEventListener('blur', validatePasswordInput); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| loginForm.addEventListener('submit', e => { | ||||||||||||||||||||||||||||||||||||||||||||||
| e.preventDefault(); | ||||||||||||||||||||||||||||||||||||||||||||||
| const emailError = validateEmail(emailInput.value.trim()); | ||||||||||||||||||||||||||||||||||||||||||||||
| const passwordError = validatePassword(passwordInput.value.trim()); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| if (!emailError && !passwordError) { | ||||||||||||||||||||||||||||||||||||||||||||||
| window.location.href = '/items.html'; | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+67
to
+72
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. 💊 제안
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||
|
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. 👍 칭찬 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import { | ||
| EMAIL_VALIDATION, | ||
| NICKNAME_VALIDATION, | ||
| PASSWORD_VALIDATION, | ||
| CONFIRM_PASSWORD_VALIDATION, | ||
| } from '../../constants/message.js'; | ||
|
|
||
| import { SYMBOL } from '../../constants/symbol.js'; | ||
|
|
||
| /** | ||
| * 이메일 유효성 검사 | ||
| * @param {string} email - 입력된 이메일 | ||
| * @returns {string} - 에러 메시지 또는 빈 문자열 | ||
| */ | ||
| export const validateEmail = email => { | ||
| if (!email) { | ||
| return EMAIL_VALIDATION.required_email; | ||
| } | ||
| return !SYMBOL.email_validate_regex.test(email) ? EMAIL_VALIDATION.invalid_email : SYMBOL.empty_message; | ||
| }; | ||
|
|
||
| /** | ||
| * 닉네임 유효성 검사 | ||
| * @param {string} nickname - 입력된 닉네임 | ||
| * @returns {string} - 에러 메시지 또는 빈 문자열 | ||
| */ | ||
| export const validateNickname = nickname => { | ||
| return !nickname ? NICKNAME_VALIDATION.required_nickname : SYMBOL.empty_message; | ||
| }; | ||
|
|
||
| /** | ||
| * 비밀번호 유효성 검사 | ||
| * @param {string} password - 입력된 비밀번호 | ||
| * @returns {string} - 에러 메시지 또는 빈 문자열 | ||
| */ | ||
| export const validatePassword = password => { | ||
| if (!password) { | ||
| return PASSWORD_VALIDATION.required_password; | ||
| } | ||
| return password.length < SYMBOL.password_min_length ? PASSWORD_VALIDATION.invalid_password : SYMBOL.empty_message; | ||
| }; | ||
|
|
||
| /** | ||
| * 비밀번호 확인 유효성 검사 | ||
| * @param {string} password - 비밀번호 | ||
| * @param {string} confirmPassword - 비밀번호 확인 값 | ||
| * @returns {string} - 에러 메시지 또는 빈 문자열 | ||
| */ | ||
| export const validatePasswordConfirm = (password, confirmPassword) => { | ||
| if (!confirmPassword) { | ||
| return CONFIRM_PASSWORD_VALIDATION.required_confirm_password; | ||
| } | ||
|
|
||
| // 비밀번호와 같더라도 비밀번호 조건이 통과되어야 함 | ||
| if (password.length < SYMBOL.password_min_length) { | ||
| return PASSWORD_VALIDATION.invalid_password; | ||
| } | ||
|
|
||
| return password !== confirmPassword ? CONFIRM_PASSWORD_VALIDATION.not_matched_password : SYMBOL.empty_message; | ||
| }; |
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.
💊 제안
EMAIL_VALIDATION 이름보다 EMAIL_ERROR_MESSAGE와 같이 에러문구 객체라는 것을 알 수 있는 이름이 더 좋을 것 같아요~