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
81 changes: 74 additions & 7 deletions auth.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,26 @@

.head-img {
text-align: center;
padding: 20px;
padding-bottom: 50px;
}

.login-link {
color: #f3f4f6;
text-decoration: none;
display: flex;
align-items: center;
justify-content: center;
gap: 30px;
}

.pandaMarketImg {
max-width: 396px;
max-width: 103.53px;
width: 100%;
height: auto;
}

.pandaMarketImg-name {
max-width: 266px;
width: 100%;
height: auto;
}
Expand Down Expand Up @@ -75,17 +90,16 @@
}

.login-button {
text-decoration: none;
color: #f3f4f6;
border: none;
border-radius: 40px;
background-color: #3692ff;
font-size: 20px;
font-weight: 600;
line-height: 32px;
width: 100%;
height: 56px;
cursor: pointer;
font-size: 20px;
font-weight: 600;
}

.blue-section {
Expand Down Expand Up @@ -119,6 +133,7 @@
display: flex;
align-items: center;
justify-content: center;
gap: 4px;
}

.advice {
Expand Down Expand Up @@ -148,16 +163,68 @@
padding-left: 20px;
}

@media (max-width: 767px) and (min-width: 375px) {
.error {
border: 1px solid red;
}

#error-message {
color: red;
font-size: 14px;
font-weight: 600;
display: none;
margin-left: 15px;
}

#error-password {
color: red;
font-size: 14px;
font-weight: 600;
display: none;
margin-left: 15px;
}

#error-nicname {
color: red;
font-size: 14px;
font-weight: 600;
display: none;
margin-left: 15px;
}

#error-checkPassword {
color: red;
font-size: 14px;
font-weight: 600;
display: none;
margin-left: 15px;
}

#signupBtn:disabled {
background-color: #9ca3af;
}

#loginBtn:disabled {
background-color: #9ca3af;
}

@media (max-width: 767px) {
.content {
max-width: 400px;
width: 100%;
padding: 0 16px;
margin: 100px auto;
}
.pandaMarketImg {
max-width: 197px;
max-width: 51px;
height: auto;
width: 100%;
}
.pandaMarketImg-name {
max-width: 133px;
height: auto;
width: 100%;
}
.login-link {
gap: 10px;
}
}
Binary file removed img/logo.png
Binary file not shown.
Binary file added img/logoHead.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/logoName.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 4 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
<div class="container">
<div class="header-container">
<a class="login-link" href="/">
<img class="title-logo" src="img/logo.png" />
<img class="title-logo" src="img/logoHead.png" />
<img class="title-logo-name" src="img/logoName.png" />
</a>
<div class="login">
<a class="login-link" href="login.html">로그인</a>
<a class="login-link-see" href="login.html">로그인</a>
</div>
</div>
</div>
Expand All @@ -34,7 +35,7 @@ <h2 class="title">
거래해 보세요
</h2>
<div class="button-buy">
<a class="login-link" href="/items">구경하러 가기</a>
<a class="login-link-see" href="/items">구경하러 가기</a>
</div>
</div>
<img class="panda-pic" src="img/panda1.png" alt="fashionist_panda" />
Expand Down
10 changes: 8 additions & 2 deletions login.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
<div class="content">
<div class="head-img">
<a class="login-link" href="/">
<img class="pandaMarketImg" src="img/logo.png" />
<img class="pandaMarketImg" src="img/logoHead.png" />
<img class="pandaMarketImg-name" src="img/logoName.png" />
</a>
</div>
<form action="/login" method="post">
Expand All @@ -29,6 +30,7 @@
class="userName"
placeholder="이메일을 입력해주세요"
/>
<div id="error-message"></div>
<label for="userPassword" class="userPassword-label">비밀번호</label>
<input
type="password"
Expand All @@ -37,9 +39,12 @@
class="userPassword"
placeholder="비밀번호를 입력해주세요"
/>
<div id="error-password"></div>
</div>
<div class="content-login">
<button type="submit" class="login-button">로그인</button>
<button type="submit" class="login-button" id="loginBtn" disabled>
로그인
</button>
</div>
</form>
<div>
Expand All @@ -64,5 +69,6 @@
<a class="membership" href="signup.html">회원가입</a>
</div>
</div>
<script src="login.js"></script>
Copy link
Collaborator

Choose a reason for hiding this comment

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

💊 제안

아마 script 태그를 HTML의 하단에 배치하신 이유가 script가 문서의 렌더링을 막지 않도록 하기 위해서이실 것 같아요.
하지만, script 태그에 defer나 async 속성을 사용하면 이런 문제를 해결할 수 있기 때문에 반드시 하단에 배치할 필요는 없습니다!
또한 script 태그는 상단에 있는게 구조 파악에서도 유리하기 때문에 상단 head 태그에 두시는 것을 추천드려요~

script async
script defer

지금과 같은 경우 DOM을 조작하는 JS 이니 defer 속성을 추가하시면 되겠습니다~

</body>
</html>
81 changes: 81 additions & 0 deletions login.js
Copy link
Collaborator

Choose a reason for hiding this comment

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

💊 제안
form이 유효하게 작성되어 있는지를 판단해 버튼을 활성화하는 updateButtonState 함수를 input 이벤트와 focusout 이벤트 시 모두 실행하고 있네요. 다만 input 이벤트에서 해당 함수를 호출한다면 이미 값이 변경되는 시점에 updateButtonState 함수를 호출했기 때문에 focusout시에는 호출하지 않아도 될 것 같습니다.

Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
const emailInput = document.getElementById("userName");
const passwordInput = document.getElementById("userPassword");

const errorMessage = document.getElementById("error-message");
const errorPassword = document.getElementById("error-password");
Comment on lines +4 to +5
Copy link
Collaborator

Choose a reason for hiding this comment

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

💊 제안
이름은 코드에 있어 내용을 파악하는데 도움을 주는 중요한 단서입니다.
지금 errorMessage의 경우는 이메일관련 에러를 나타내는 태그의 클래스명인데 일반 명사인 errorMessage로 이름이 지어져 있어
errorPassword와 비교해서 어떤 변수인지 명확하지 않습니다.
가능하면 어떤 변수인지 잘 설명해줄 수 있는 이름으로 변경해주세요~

Suggested change
const errorMessage = document.getElementById("error-message");
const errorPassword = document.getElementById("error-password");
const errorEmail = document.getElementById("error-message");
const errorPassword = document.getElementById("error-password");


const loginBtn = document.getElementById("loginBtn");

document.addEventListener("DOMContentLoaded", () => {
emailInput.addEventListener("input", () => {
if (emailInput.value !== "" && emailInput.value.includes("@")) {
Comment on lines +10 to +11
Copy link
Collaborator

Choose a reason for hiding this comment

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

💊 제안
바로 email input의 값이 비어있는지 확인하게 되면 " " 와 같이 공백만 존재하는 경우에도 값이 있다고 판단하게 됩니다.
따라서 string의 trim method를 통해 공백을 제거하시면 의도한 바와 더 가까울 것 같습니다.
조건문에서 이메일 형식을 확인하는 emailInput.value.includes("@") 부분의 경우도 @ 라는 요소가 들어가있는지만 확인하는 것이라 명확한 이메일 형식 확인은 되지 않고 있으니 이메일 관련 정규식을 통해 구현하시면 더 좋겠습니다~

Suggested change
emailInput.addEventListener("input", () => {
if (emailInput.value !== "" && emailInput.value.includes("@")) {
emailInput.addEventListener("input", () => {
if (emailInput.value.trim() !== "" && emailInput.value.includes("@")) {

emailInput.classList.remove("error");
errorMessage.textContent = "";
errorMessage.style.display = "none";
}
updateButtonState();
});

passwordInput.addEventListener("input", () => {
if (passwordInput.value.length >= 8) {
passwordInput.classList.remove("error");
errorPassword.textContent = "";
errorPassword.style.display = "none";
}
updateButtonState();
});

emailInput.addEventListener("focusout", () => {
if (emailInput.value === "") {
emailInput.classList.add("error");
errorMessage.textContent = "잘못된 이메일입니다.";
errorMessage.style.display = "block";
} else if (!emailInput.value.includes("@")) {
emailInput.classList.add("error");
errorMessage.textContent = "잘못된 이메일 형식입니다.";
errorMessage.style.display = "block";
} else {
emailInput.classList.remove("error");
errorMessage.textContent = "";
errorMessage.style.display = "none";
}
updateButtonState();
});

passwordInput.addEventListener("focusout", () => {
if (passwordInput.value === "") {
passwordInput.classList.add("error");
errorPassword.textContent = "비밀번호를 입력해주세요";
errorPassword.style.display = "block";
} else if (passwordInput.value.length < 8) {
passwordInput.classList.add("error");
errorPassword.textContent = "비밀번호를 8자 이상 입력해주세요.";
errorPassword.style.display = "block";
} else {
passwordInput.classList.remove("error");
errorPassword.textContent = "";
errorPassword.style.display = "none";
}
updateButtonState();
});

loginBtn.addEventListener("click", function (e) {
e.preventDefault();
if (!loginBtn.disabled) {
window.location.href = "/item";
}
});
Comment on lines +62 to +67
Copy link
Collaborator

Choose a reason for hiding this comment

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

💊 제안
form이 유효하지 않으면 submit button이 disabled 상태라 제출이 되지 않으므로 관련 코드는 없어도 될 것 같아요~

Suggested change
loginBtn.addEventListener("click", function (e) {
e.preventDefault();
if (!loginBtn.disabled) {
window.location.href = "/item";
}
});
loginBtn.addEventListener("click", function (e) {
e.preventDefault();
window.location.href = "/item";
});

});

function updateButtonState() {
const hasError =
emailInput.classList.contains("error") ||
passwordInput.classList.contains("error");

const isFilled = emailInput.value !== "" && passwordInput.value.length >= 8;

const shouldEnable = !hasError && isFilled;

loginBtn.disabled = !shouldEnable;
}
//비활성화 시킨 버튼 어떻게 활성화 시킬지 모르겠어서 updateButtonState()부분은 챗GPT의 도움을 받았습니다. 코드 보면서 더 공부하겠습니다.
Loading
Loading