Skip to content

Commit

Permalink
5주차 위클리미션 요구사항 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
mijin0928 committed Nov 19, 2023
1 parent 19c0b81 commit 0591d6e
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 17 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"liveServer.settings.port": 5501
}
46 changes: 37 additions & 9 deletions week5/js/signin.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
import { correct, errorMessage, emptyInput, errorPrint } from "./utils.js";

const input = document.querySelectorAll('.input');
const eye = document.querySelectorAll('.eye');
const pwInput = document.getElementById('signin-password');
const emailInput = document.getElementById('signin-email');
const btnLogin = document.querySelector('.btn-login');

// 로그인 버튼 클릭 시 페이지 이동
function login(e){
e.preventDefault();

function login(){
const { email, password } = correct.userInfo;

if(emailInput.value !== '' && pwInput.value !== ''){
if(emailInput.value === email && pwInput.value === password) {
if(emailInput.value === email && pwInput.value === password){
location.href = './folder.html';
}else{
emailInput.classList.add('active');
pwInput.classList.add('active');
errorPrint(emailInput, errorMessage.check);
errorPrint(pwInput, errorMessage.check);
pwInput.classList.add('active');
errorPrint(emailInput, errorMessage.check);
errorPrint(pwInput, errorMessage.check);
}
}else{
emailInput.classList.add('active');
Expand All @@ -42,8 +39,39 @@ function eyeToggle(e){
}
}

btnLogin.addEventListener('click', login);
// 로그인 api
async function userLogin(){
try{
const data = {
email: '[email protected]',
password: 'sprint101',
}
const response = await fetch('https://bootcamp-api.codeit.kr/api/sign-in',{
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
})

const { email, password } = data;
const takeToken = await response.json();
const token = await takeToken.data.accessToken;
localStorage.setItem('accessToken', token);

if(localStorage.getItem('accessToken')) login(email, password);
}catch(error){
console.log(error);
}
}

btnLogin.addEventListener('click', (e) => {
e.preventDefault();
login();
userLogin(emailInput, pwInput);
});
eye.forEach((el) => el.addEventListener('click', eyeToggle))
input.forEach((el) => {el.addEventListener('focusout', emptyInput)})



71 changes: 65 additions & 6 deletions week5/js/signup.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ const eye = document.querySelectorAll('.eye');
const btnJoin = document.querySelector('.btn-box .btn-join');

// 회원가입 버튼 클릭 시 페이지 이동
function join(e){
e.preventDefault();

function join(){
const { email } = correct.userInfo;

if(emailInput.value !== email){
if(pwInput.value !== '' && pwCheckInput.value !== '') location.href = './folder.html';
}else{
Expand Down Expand Up @@ -50,10 +48,71 @@ function eyeToggle(e){
}
}

btnJoin.addEventListener('click', join);
// 이메일 중복체크 api
async function emailCheck(){
if(emailInput.value === '') return;

try{
const data = {
email: emailInput.value,
}

const response = await fetch('https://bootcamp-api.codeit.kr/api/check-email',{
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
})

if(response.status === 200){
const { email } = data;
join(email);
}
}catch(error){
console.log(error);
}
}

// 회원가입 api
async function userJoin(emailInput, pwInput, pwCheckInput){
if(emailInput.value === '' && pwInput.value === '') return;

try{
const data = {
email: emailInput.value,
password: pwInput.value,
passwordCheck: pwCheckInput,
}

const response = await fetch('https://bootcamp-api.codeit.kr/api/sign-up',{
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
})

const { email, password } = data;
const takeToken = await response.json();
const token = await takeToken.data.accessToken;
localStorage.setItem('accessToken', token);

if(localStorage.getItem('accessToken')) join(email, password);
}catch(error){
console.log(error);
}
}

btnJoin.addEventListener('click', (e) => {
e.preventDefault();
join();
emailCheck(emailInput);
userJoin(emailInput, pwInput);
});
eye.forEach((el) => el.addEventListener('click', eyeToggle))
input.forEach((el) => {el.addEventListener('focusout', ({ target }) => {
emptyInput({ target });
pwCheck();
pwCheck();
})})

1 change: 0 additions & 1 deletion week5/signin.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,5 @@ <h1 class="logo">
</div>
<script type="module" src="./js/utils.js"></script>
<script type="module" src="./js/signin.js"></script>
<script type="module" src="./js/login_check.js"></script>
</body>
</html>
1 change: 0 additions & 1 deletion week5/signup.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,5 @@ <h1 class="logo">
</div>
<script type="module" src="./js/utils.js"></script>
<script type="module" src="./js/signup.js"></script>
<script type="module" src="./js/join_check.js"></script>
</body>
</html>

0 comments on commit 0591d6e

Please sign in to comment.