-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
105 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"liveServer.settings.port": 5501 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
|
@@ -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)}) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters