Skip to content
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

[고성선] week4 #164

Merged
merged 10 commits into from
Nov 14, 2023
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
14 changes: 14 additions & 0 deletions .github/workflows/delete-merged-branch-config.yml
Copy link
Collaborator

Choose a reason for hiding this comment

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

workflow는 직접 작성하신건가요 오... 👍 👍 👍

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: delete branch on close pr

on:
pull_request:
types: [closed]

jobs:
delete-branch:
runs-on: ubuntu-latest
steps:
- name: delete branch
uses: SvanBoxel/delete-merged-branch@main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
11 changes: 11 additions & 0 deletions folder.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<script type="module" src=""></script>
</body>
</html>
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -188,5 +188,6 @@ <h2>
</div>
</div>
</footer>
<script type="module" src="./script/index.js"></script>
</body>
</html>
6 changes: 6 additions & 0 deletions script/emailData.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//사용중인 유저 데이터
const userData = [
{ email: "[email protected]", password: "codeit101" },
{ email: "[email protected]", password: "dksdkffuwna1" },
];
Comment on lines +2 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.

일반적으로 상수값을 쓸 때는 일반 변수와 다르게 PASCAL_CASE 등을 사용해서 상수임을 명확하게 드러내는걸 권장하는데요. 참고 하시면 좋을거 같네용 ㅎㅎ

Suggested change
const userData = [
{ email: "[email protected]", password: "codeit101" },
{ email: "[email protected]", password: "dksdkffuwna1" },
];
const USER_DATA = [
{ email: "[email protected]", password: "codeit101" },
{ email: "[email protected]", password: "dksdkffuwna1" },
];

export default userData;
Comment on lines +1 to +6
Copy link
Collaborator

Choose a reason for hiding this comment

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

이렇게 모아서 관리하니 좋네요 ㅎㅎ 👍 👍 👍 💯

Empty file added script/folder.js
Copy link
Collaborator

Choose a reason for hiding this comment

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

empty file이 같이 올라왔네요 👀

Empty file.
36 changes: 36 additions & 0 deletions script/function.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import userData from "./emailData.js";

function createTag(target, message) {
//태그 생성
if (target.nextSibling) {
Comment on lines +2 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.

형제요소 등을 기준으로 요소를 찾거나 조건문을 거는 경우에는 구조의 변경에 굉장히 취약하고, 코드를 읽을 때 가독성도 떨어지는데요. 다른 방법을 고민해보시면 좋을거 같습니다!

return;
}
target.classList = "redBorder";
const span = document.createElement("span");
span.innerHTML = `${message}`;
span.classList.add("redMessage");
target.parentElement.append(span);
}
function removeTag(target) {
//태그 삭제
target.classList.toggle("redBorder", 0);
if (target.nextSibling) {
target.nextSibling.remove();
}
}
function checkEmail(str) {
//이메일 정규식
const reg_email =
/^([0-9a-zA-Z_\.-]+)@([0-9a-zA-Z_-]+)(\.[0-9a-zA-Z_-]+){1,2}$/;
if (!reg_email.test(str)) {
return false;
} else {
return true;
}
Comment on lines +25 to +29
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
if (!reg_email.test(str)) {
return false;
} else {
return true;
}
return reg_email.test(str)

}
function emailDuplicateCheck(str) {
// 이메일 중복 확인 함수
return userData.find((el) => el.email === str);
}

export { createTag, removeTag, checkEmail, emailDuplicateCheck };
Empty file added script/index.js
Empty file.
77 changes: 77 additions & 0 deletions script/signin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { inputEmail, inputPassword, eyeIcon, form } from "./tags.js";
import { createTag, removeTag, checkEmail } from "./function.js";
import userData from "./emailData.js";
let emailEnable = false; //이메일 사용 가능 여부
let passwordEnable = false; //패스워드 사용 가능 여부
function emailCheck(e) {
//이메일 확인 함수
if (e.type === "focusout" || (e.type === "keyup" && e.key === "Enter")) {
Comment on lines +6 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
function emailCheck(e) {
//이메일 확인 함수
if (e.type === "focusout" || (e.type === "keyup" && e.key === "Enter")) {
function emailCheck({ type, key }) {
//이메일 확인 함수
if (type === "focusout" || (type === "keyup" && key === "Enter")) {

let input = e.target;
if (input.value === "") {
createTag(input, "이메일을 입력해주세요");
} else if (!checkEmail(input.value)) {
createTag(input, "올바른 이메일이 아닙니다.");
} else {
emailEnable = true;
}
}
}

function passwordCheck(e) {
//패스워드 확인 함수
if (e.type === "focusout" || (e.type === "keyup" && e.key === "Enter")) {
let input = e.target;
Copy link
Collaborator

Choose a reason for hiding this comment

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

inputlet일 필요가 있을까요?

if (input.value === "") {
createTag(input, "비밀번호를 입력해주세요");
} else if (
input.value.length < 9 ||
!/[a-zA-Z]/.test(input.value) ||
!/\d/.test(input.value)
) {
createTag(input, "비밀번호는 영문, 숫자 조합 8자 이상 입력해 주세요.");
} else {
passwordEnable = true;
}
}
}
function login(e) {
//로그인 가능 여부 확인 판단 후 form 제출 조건에 부합되지 않으면 e정지!
const user = userData.find((el) => el.email === inputEmail.value);
if (emailEnable && passwordEnable) {
if (user === undefined) {
createTag(inputEmail, "존재하지 않는 이메일 입니다.");
e.preventDefault();
} else if (user.password !== inputPassword.value) {
createTag(inputPassword, "비밀번호가 틀렸습니다.");
e.preventDefault();
}
} else {
e.preventDefault();
}
Comment on lines +40 to +50
Copy link
Collaborator

Choose a reason for hiding this comment

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

조건문의 depth를 줄일 수 있을까요?

}

function init(e) {
//추가된 span 내용 삭제 및 보더 값 삭제
let input = e.target;
removeTag(input);
}
function passwordOpen() {
//패스워드 보이게 안보이게 하는 기능 추가
const icon =
eyeIcon[0].getAttribute("src") === "./images/eye_off.svg"
Copy link
Collaborator

Choose a reason for hiding this comment

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

배경지식 없이 코드를 읽는 입장에서는 eyeIcon의 0번째 인덱스에 어떤 값이 들어있는지 알기가 어려운데요. 더 좋은 방법은 없을까요?

? "./images/eye-on.svg"
: "./images/eye_off.svg";
eyeIcon[0].setAttribute("src", icon);
const type =
inputPassword.getAttribute("type") === "password" ? "text" : "password";
inputPassword.setAttribute("type", type);
}
//이벤트 리스너
inputEmail.addEventListener("focusout", (e) => emailCheck(e, "이메일"));
inputEmail.addEventListener("keyup", (e) => emailCheck(e, "이메일"));
inputPassword.addEventListener("focusout", (e) => passwordCheck(e, "비밀번호"));
inputPassword.addEventListener("keyup", (e) => passwordCheck(e, "비밀번호"));
inputEmail.addEventListener("focusin", init);
inputPassword.addEventListener("focusin", init);
eyeIcon[0].addEventListener("click", passwordOpen);
form.addEventListener("submit", login);
110 changes: 110 additions & 0 deletions script/signup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import {
inputEmail,
inputPassword,
inputPasswordCheck,
eyeIcon,
form,
} from "./tags.js";
import {
createTag,
removeTag,
checkEmail,
emailDuplicateCheck,
} from "./function.js";
import userData from "./emailData.js";

let emailEnable = false; //이메일 사용 가능 여부
let passwordEnable = false; // 패스워드 사용 가능 여부
function emailCheck(e) {
//이메일 사용 가능 여부 판단 함수
if (e.type === "focusout" || (e.type === "keyup" && e.key === "Enter")) {
let input = e.target;
if (input.value === "") {
createTag(input, "이메일을 입력해주세요");
} else if (!checkEmail(input.value)) {
createTag(input, "올바른 이메일이 아닙니다.");
} else {
const user = emailDuplicateCheck(input.value);
if (user) {
createTag(input, "이미 사용중인 이메일입니다.");
}
emailEnable = true;
}
}
}

function PasswordCheck(e, type) {
//패스워드 사용 가능 여부 판단 함수
if (e.type === "focusout" || (e.type === "keyup" && e.key === "Enter")) {
let input = e.target;
if (
input.value === "" &&
(type === "비밀번호" || type === "비밀번호체크")
) {
createTag(input, "비밀번호를 입력해주세요");
} else if (
input.value.length < 9 ||
Copy link
Collaborator

Choose a reason for hiding this comment

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

9와 같은 매직 넘버는 아무런 정보도 전달할 수 없기 때문에 적절하게 상수화해서 사용하는걸 추천드리고 싶습니다!

!/[a-zA-Z]/.test(input.value) ||
!/\d/.test(input.value)
) {
createTag(input, "비밀번호는 영문, 숫자 조합 8자 이상 입력해 주세요.");
} else if (type === "비밀번호체크" && input.value !== inputPassword.value) {
createTag(input, "비밀번호가 일치하지 않습니다.");
}
passwordEnable = true;
}
}
function init(e) {
//에러로 판단 된 내용 삭제
let input = e.target;
removeTag(input);
}
function passwordOpen() {
//패스워드 보이게 하는 함수
const icon =
eyeIcon[0].getAttribute("src") === "./images/eye-on.svg"
? "./images/eye_off.svg"
: "./images/eye-on.svg";
eyeIcon[0].setAttribute("src", icon);
const type =
inputPassword.getAttribute("type") === "text" ? "password" : "text";
inputPassword.setAttribute("type", type);
}
function passwordCheckOpen() {
const icon =
eyeIcon[1].getAttribute("src") === "./images/eye-on.svg"
? "./images/eye_off.svg"
: "./images/eye-on.svg";
eyeIcon[1].setAttribute("src", icon);
const type =
inputPasswordCheck.getAttribute("type") === "text" ? "password" : "text";
inputPasswordCheck.setAttribute("type", type);
}
function signup(e) {
//회원 가입을 위한 조건 판단 후 form 제출
const user = emailDuplicateCheck(inputEmail.value);
console.log(user);
if (!(emailEnable && passwordEnable) || user.email === inputEmail.value) {
e.preventDefault();
}
userData.push({
email: inputEmail.value,
password: inputPasswordCheck.value,
});
} //이벤트 리스너
inputEmail.addEventListener("focusout", (e) => emailCheck(e, "이메일"));
inputEmail.addEventListener("keyup", (e) => emailCheck(e, "이메일"));
inputPassword.addEventListener("focusout", (e) => PasswordCheck(e, "비밀번호"));
inputPassword.addEventListener("keyup", (e) => PasswordCheck(e, "비밀번호"));
inputEmail.addEventListener("focusin", init);
inputPassword.addEventListener("focusin", init);
inputPasswordCheck.addEventListener("focusout", (e) =>
PasswordCheck(e, "비밀번호체크")
);
inputPasswordCheck.addEventListener("keyup", (e) =>
PasswordCheck(e, "비밀번호체크")
);
inputPasswordCheck.addEventListener("focusin", init);
eyeIcon[0].addEventListener("click", passwordOpen);
eyeIcon[1].addEventListener("click", passwordCheckOpen);
form.addEventListener("submit", signup);
14 changes: 14 additions & 0 deletions script/tags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const inputEmail = document.querySelector("#email");
const inputPassword = document.querySelector("#password");
const inputPasswordCheck = document.querySelector("#passwordCheck");
const formButton = document.querySelector("#button");
const eyeIcon = document.querySelectorAll(".eyeIcon");
const form = document.querySelector(".formContainer");
export {
inputEmail,
inputPassword,
inputPasswordCheck,
formButton,
eyeIcon,
form,
};
15 changes: 10 additions & 5 deletions signin.css
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,14 @@ input {
position: relative;
outline: none;
}

.redBorder {
border-color: var(--red);
}
.redMessage {
color: var(--red);
font-size: 14px;
font-weight: 400;
}
input:focus {
border: 1px solid var(--primary);
}
Expand Down Expand Up @@ -128,7 +135,8 @@ img.eyeIcon {
width: 1rem;
height: 1rem;
right: 1rem;
bottom: 1rem;
top: 3rem;
z-index: 1;
}
.secondaryContainer {
display: flex;
Expand Down Expand Up @@ -187,8 +195,5 @@ a.socialLoginLink > img {
width: 100%;
max-width: 400px;
}
.inputField {
width: 100%;
}
}
}
32 changes: 20 additions & 12 deletions signin.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta property="og:type" content="website" />
<meta property="og:url" content="https://seongseonko.netlify.app/" />
<meta property="og:title" content="Linkbrary" />
<meta
property="og:image"
content="https://seongseonko.netlify.app/images/lotto.jpg"
/>
<meta
property="og:description"
content="세상의 모든 정보를 쉽게 저장하고 관리해 보세요"
/>
<meta property="og:site_name" content="Linkbrary" />
<meta property="og:image:width" content="1200" />
<meta property="og:image:height" content="630" />
<link rel="stylesheet" href="./signin.css" />
<title>Linkbrary</title>
</head>
Expand All @@ -24,24 +38,17 @@
</div>
</div>
</div>
<form class="formContainer">
<form class="formContainer" action="./folder.html">
<div class="inputGroup">
<label for="email"> 이메일 </label>
<input
id="email"
type="email"
name="email"
placeholder="[email protected]"
/>
<input id="email" type="email" name="email" />
</div>
<div class="inputGroup">
<label for="password"> 비밀번호 </label>
<div class="inputField">
<input id="password" type="password" name="password" />
<img class="eyeIcon" src="./images/eye_off.svg" alt="감은 눈" />
</div>
<img class="eyeIcon" src="./images/eye_off.svg" alt="감은 눈" />
<input id="password" type="password" name="password" />
</div>
<button>로그인</button>
<button id="button">로그인</button>
</form>
</div>
<div class="secondaryContainer">
Expand All @@ -57,5 +64,6 @@
</div>
</div>
</section>
<script type="module" src="./script/signin.js"></script>
</body>
</html>
15 changes: 12 additions & 3 deletions signup.css
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,21 @@ input {
.inputFieldContainer {
position: relative;
}
.inputFieldContainer > img {
img.eyeIcon {
position: absolute;
right: 1rem;
bottom: 1.1rem;
width: 1rem;
height: 1rem;
right: 1rem;
top: 1.2rem;
z-index: 1;
}
.redBorder {
border-color: var(--red);
}
.redMessage {
color: var(--red);
font-size: 14px;
font-weight: 400;
}
input:focus {
border: 1px solid var(--primary);
Expand Down
Loading