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
Binary file removed img/logo_noicon.png
Binary file not shown.
Binary file added img/logo_onlyText.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
58 changes: 30 additions & 28 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<body>
<header id="header">
<nav>
<a href="/"><div class="logo_img"></div> </a>
<a href="/"><div class="logo_img"></div></a>
<button><a href="./login.html">로그인</a></button>
</nav>
</header>
Expand Down Expand Up @@ -76,33 +76,35 @@ <h2>믿을 수 있는<br />판다마켓 중고 거래</h2>
</section>

<footer>
<span class="copyright">©codeit - 2024</span>
<!-- <div class="infos"> -->
<span class="info"><a href="./privacy.html">Privacy Policy</a></span>
<span class="info"><a href="./faq.html">FAQ</a></span>
<!-- </div> -->
<ul>
<li>
<a href="https://www.facebook.com/?locale=ko_KR" target="_blank">
<img class="sns" src="./img/ic_facebook.png" alt="facebook" />
</a>
</li>
<li>
<a href="https://x.com/" target="_blank">
<img class="sns" src="./img/ic_twitter.png" alt="twitter" />
</a>
</li>
<li>
<a href="https://www.youtube.com" target="_blank">
<img class="sns" src="./img/ic_youtube.png" alt="youtube" />
</a>
</li>
<li>
<a href="https://www.instagram.com/" target="_blank">
<img class="sns" src="./img/ic_instagram.png" alt="instagram" />
</a>
</li>
</ul>
<div id="footer_wrapper">
<span class="copyright">©codeit - 2024</span>
<span class="info privacy"
><a href="./privacy.html">Privacy Policy</a></span
>
<span class="info faq"><a href="./faq.html">FAQ</a></span>
<ul>
<li>
<a href="https://www.facebook.com/?locale=ko_KR" target="_blank">
<img class="sns" src="./img/ic_facebook.png" alt="facebook" />
</a>
</li>
<li>
<a href="https://x.com/" target="_blank">
<img class="sns" src="./img/ic_twitter.png" alt="twitter" />
</a>
</li>
<li>
<a href="https://www.youtube.com" target="_blank">
<img class="sns" src="./img/ic_youtube.png" alt="youtube" />
</a>
</li>
<li>
<a href="https://www.instagram.com/" target="_blank">
<img class="sns" src="./img/ic_instagram.png" alt="instagram" />
</a>
</li>
</ul>
</div>
</footer>
</div>
</body>
Expand Down
25 changes: 10 additions & 15 deletions login.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>로그인</title>

<link rel="stylesheet" href="./styles/reset.css" />
<link rel="stylesheet" href="./styles/login.css" />
</head>
Expand All @@ -16,41 +15,37 @@
</a>
</header>
<form>
<label for="email">이메일</label>
<input type="email" id="email" name="email" />
<div>
<label for="email">이메일</label>
<input type="email" id="email" name="email" />
</div>
<div class="pw_area">
<label for="password" name="password">비밀번호</label>
<div class="visible_icon"></div>
<input type="password" name="" id="password" />
</div>
<button class="primary_btn">로그인</button>
<button type="button" class="primary_btn">로그인</button>
</form>
<section>
<div class="sns_login">
<span>간편 로그인하기</span>
<ul>
<li>
<a href="https://www.google.com/"
><img
class="sns_icon"
src="./img/google_icon.png"
alt="구글로그인"
><img class="sns_icon" src="./img/google_icon.png" alt="구글로그인"
/></a>
</li>
<li>
<a href="https://www.kakaocorp.com/page/"
><img
class="sns_icon"
src="./img/kakaotalk_icon.png"
alt="카카오로그인"
><img class="sns_icon" src="./img/kakaotalk_icon.png" alt="카카오로그인"
/></a>
</li>
</ul>
</div>
<p class="go_joinpage">
판다마켓이 처음이신가요? <a href="./signup.html">회원가입</a>
</p>
<p class="go_joinpage">판다마켓이 처음이신가요? <a href="./signup.html">회원가입</a></p>
</section>
</main>
<script src="./login.js" type="module"></script>
<script src="./loginFunctions.js" type="module"></script>
Comment on lines +48 to +49
Copy link
Collaborator

Choose a reason for hiding this comment

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

💊 제안
script 태그는 상단에 있는게 구조 파악측면에서 유리하다고 생각해서 큰 이유가 없다면 상단 head 태그에 두시는 것을 추천드려요~
특히 타입이 모듈인 스크립트는 defer 속성을 자동으로 가지기 때문에 따로 하단에 배치하실 이유가 없습니다~

</body>
</html>
25 changes: 25 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.

💊 제안
내부 로직들을 loginFunction으로 분리하신점 좋습니다~
다만 분리된 로직을 페이지에 연결하는 것을 한 파일로 해결한 점이 아쉬워요. 이렇게 되면 로그인 페이지에서 nickname, password_check 관련 불필요한 코드를 불어오게 되니까요.
잘 분리하셨으니 login, signup.js 로 나눠서 작성하시면 각 페이지별 로직이 더 명확하게 표현될 것 같아요.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {
buttonDeactivate,
requireContent,
buttonActivate,
checkPassword,
visibleIconToggle,
} from "./loginFunctions.js";
const primary_btn = document.querySelector(".primary_btn");
buttonDeactivate(primary_btn);

document.getElementById("email").addEventListener("focusout", requireContent);
document.getElementById("password").addEventListener("focusout", requireContent);
document.getElementById("nickname")?.addEventListener("focusout", requireContent);
document.getElementById("password_check")?.addEventListener("focusout", (e) => {
checkPassword(e);
buttonActivate(e);
});
primary_btn.addEventListener("click", (e) => {
e.preventDefault();
console.log("Button clicked! Moving to ./login.html");
window.location.href = "./login.html";
});
document.querySelectorAll(".visible_icon").forEach((item) => {
item.addEventListener("click", visibleIconToggle);
});
103 changes: 103 additions & 0 deletions loginFunctions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
const ERRORMESSAGE = {
wrongEmail: "잘못된 이메일 형식입니다",
wrongPassword: "비밀번호를 8자 이상 입력해주세요",
emailIsEmpty: "이메일을 입력해주세요",
passwordIsEmpty: "비밀번호를 입력해주세요",
nicknameIsEmpty: "닉네임을 입력해주세요",
passwordIsNotSame: "비밀번호가 일치하지 않습니다.",
};
Comment on lines +1 to +8
Copy link
Collaborator

Choose a reason for hiding this comment

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

💊 제안
반복사용되는 에러메시지를 따로 상수로 모아두신 것 좋습니다. 다만 단어를 구분할 수 있게 아래처럼 명명하시는 것을 추천드려요!

Suggested change
const ERRORMESSAGE = {
wrongEmail: "잘못된 이메일 형식입니다",
wrongPassword: "비밀번호를 8자 이상 입력해주세요",
emailIsEmpty: "이메일을 입력해주세요",
passwordIsEmpty: "비밀번호를 입력해주세요",
nicknameIsEmpty: "닉네임을 입력해주세요",
passwordIsNotSame: "비밀번호가 일치하지 않습니다.",
};
const ERROR_MESSAGE = {
wrongEmail: "잘못된 이메일 형식입니다",
wrongPassword: "비밀번호를 8자 이상 입력해주세요",
emailIsEmpty: "이메일을 입력해주세요",
passwordIsEmpty: "비밀번호를 입력해주세요",
nicknameIsEmpty: "닉네임을 입력해주세요",
passwordIsNotSame: "비밀번호가 일치하지 않습니다.",
};


const requireContent = (e) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

💊 제안
해당 함수는 input의 value가 있으면 유효성 검사를 하고 없으면 에러 메시지를 보여주는 로직을 처리하고 있네요~
가독성 측면에서 내부 로직을 분리하면 더 좋을 것 같아요!
각 input 별로 유효성 검사를 하고 에러메시지를 보여주는 방식으로 분리하시면 좋겠네요~

const checkEmailValid = (input) => {
  const emailRegex =
    /^[a-zA-Z0-9]+([._-][a-zA-Z0-9]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z]{2,})+$/;

  if (emailRegex.test(input.value)) return ERRORMESSAGE.wrongEmail;
  return ERRORMESSAGE.emailIsEmpty;
};

const checkPasswordValid = () => {
  if (input.value.length < 8) return ERRORMESSAGE.wrongPassword;
  return ERRORMESSAGE.passwordIsEmpty;
};

const checkNicknameValid = (input) => {
  if (input.value.trim() === "") return ERRORMESSAGE.nicknameIsEmpty;
};

const requireContent = (e) => {
  const target = e.target;

  switch (target.id) {
    case "email":
      createNewMessage(checkEmailValid(target), target);
      break;
    case "password":
      createNewMessage(checkPasswordValid(target), target);
      document.querySelector(".visible_icon").style = "bottom: 6.9rem;";
      break;
    case "nickname":
      createNewMessage(checkNicknameValid(target), target);
      break;
  }

  if (e.target.nextElementSibling?.tagName == "P") {
    e.target.style = "border: none";
    e.target.nextElementSibling.remove();
    document.querySelector(".visible_icon").style = "bottom: 1.4rem;";
  }
};

내부로직을 제가 다 잘 파악한 것인지 모르겠으니 위의 코드는 방향성만 참고해주세요~

console.log("requireContent called for:", e.target.id);
let content = e.target.value;
Copy link
Collaborator

Choose a reason for hiding this comment

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

❗️ 수정요청
재할당하는 경우가 아니라면 const로 선언해주세요~

Suggested change
let content = e.target.value;
const content = e.target.value;

let emailRegex = /^[a-zA-Z0-9]+([._-][a-zA-Z0-9]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z]{2,})+$/;

if (content) {
if (emailRegex.test(content) === false && e.target.id == "email") {
createNewMessage(ERRORMESSAGE.wrongEmail, e.target);
} else if (e.target.nextElementSibling?.tagName == "P") {
e.target.style = "border: none";
e.target.nextElementSibling.remove();
document.querySelector(".visible_icon").style = "bottom: 1.4rem;";
}
if (e.target.id == "password" && content.length < 8) {
createNewMessage(ERRORMESSAGE.wrongPassword, e.target);
document.querySelector(".visible_icon").style = "bottom: 6.9rem;";
}
} else {
let messageContent;
switch (e.target.id) {
case "email":
messageContent = ERRORMESSAGE.emailIsEmpty;
break;
case "password":
messageContent = ERRORMESSAGE.passwordIsEmpty;
break;
case "nickname":
messageContent = ERRORMESSAGE.nicknameIsEmpty;
break;
}
createNewMessage(messageContent, e.target);
document.querySelector(".visible_icon").style = "bottom: 6.9rem;";
}
};

const createNewMessage = (messageContent, target) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

💊 제안
에러 메시지를 보여주는 것이니 이를 알 수 있는 이름으로 하시는 것을 추천드립니다~

Suggested change
const createNewMessage = (messageContent, target) => {
const createErrorMessage = (messageContent, target) => {

target.style = "border: 1px solid red";
if (target.nextElementSibling?.tagName == "P") {
target.nextElementSibling.innerText = messageContent;
} else {
let pTag = document.createElement("p");
pTag.textContent = messageContent;
pTag.classList.add("plzInputText");
target.after(pTag);
}
};

const buttonDeactivate = (tag) => {
tag.disabled = true;
tag.style = "background-color: var(--gray400)";
};

const buttonActivate = (e) => {
const nodeList = document.getElementsByClassName("plzInputText");
const inputs = [...document.getElementsByTagName("input")];
let inputIsEmpty = inputs.every((input) => input.value && input.value.trim() !== "");
if (nodeList.length !== 0 && !inputIsEmpty) {
} else {
let submit_btn = document.querySelector(".primary_btn");
submit_btn.disabled = false;
submit_btn.style = "background-color: var(--blue)";
}
};

const checkPassword = (e) => {
let password = document.getElementById("password");
let passwordCheck = document.getElementById("password_check");
if (password && passwordCheck) {
if (password.value !== passwordCheck.value) {
createNewMessage(ERRORMESSAGE.passwordIsNotSame, e.target);
e.target.previousElementSibling.style = "bottom: 6.9rem;";
} else if (e.target.nextElementSibling?.tagName === "P") {
e.target.style = "border: none";
e.target.nextElementSibling.remove();
}
}
};

const visibleIconToggle = (e) => {
e.target.classList.toggle("passwordIsVisible");
if (e.target.nextElementSibling.type == "password") {
Copy link
Collaborator

Choose a reason for hiding this comment

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

💊 제안
이렇게 접근하시는 것도 나쁘지 않지만 이는 HTML 구조와 긴밀하게 연관되게 되므로,
HTML에서 위치만 변경되어도 작동되지 않을 위험이 커집니다~
가능하면 부모요소로 접근해 해당 요소 내에서 재탐색을 해보세요.

e.target.nextElementSibling.type = "text";
} else {
e.target.nextElementSibling.type = "password";
}
};
export {
requireContent,
createNewMessage,
buttonDeactivate,
buttonActivate,
checkPassword,
visibleIconToggle,
};
18 changes: 6 additions & 12 deletions signup.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,34 +30,28 @@
<div class="visible_icon"></div>
<input type="password" name="password_check" id="password_check" />
</div>
<button href="" class="primary_btn">회원가입</button>
<button class="primary_btn" type="button">회원가입</button>
</form>
<section>
<div class="sns_login">
<span>간편 로그인하기</span>
<ul>
<li>
<a href="https://www.google.com/"
><img
class="sns_icon"
src="./img/google_icon.png"
alt="구글로그인"
><img class="sns_icon" src="./img/google_icon.png" alt="구글로그인"
/></a>
</li>
<li>
<a href="https://www.kakaocorp.com/page/"
><img
class="sns_icon"
src="./img/kakaotalk_icon.png"
alt="카카오로그인"
><img class="sns_icon" src="./img/kakaotalk_icon.png" alt="카카오로그인"
/></a>
</li>
</ul>
</div>
<p class="go_joinpage">
이미 회원이신가요? <a href="./login.html">로그인</a>
</p>
<p class="go_joinpage">이미 회원이신가요? <a href="/login.html">로그인</a></p>
</section>
</main>
<script src="./login.js" type="module"></script>
<script src="./loginFunctions.js" type="module"></script>
</body>
</html>
13 changes: 12 additions & 1 deletion styles/login.css
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ form label {
width: 100%;
text-align: center;
display: block;
background-color: var(--blue);
background-color: var(--gray400);
color: #ffffff;
padding: 1.2rem 0;
font-size: 2rem;
Expand All @@ -74,6 +74,7 @@ form label {
width: 2.4rem;
height: 2.4rem;
position: absolute;
z-index: 9999;
right: 2.4rem;
bottom: 1.4rem;
}
Expand Down Expand Up @@ -116,3 +117,13 @@ form label {
max-width: 40rem;
}
}

.plzInputText {
padding: 2rem;
font-size: 1.5rem;
color: red;
}

.passwordIsVisible {
background-image: url("../img/btn_visibility_on.svg");
}
Loading
Loading