kimkyeonghun

로그인 기능 구현

......@@ -7,8 +7,10 @@
var express = require('express')
, routes = require('./routes')
, todo = require('./routes/todo')
, login =require('./routes/login')
, http = require('http')
, path = require('path');
, path = require('path')
, fs = require('fs');
var app = express(); // 어플리케이션 생성
var port = 3000; // 어플리케이션 포트
......@@ -36,6 +38,20 @@ app.configure('development', function(){ // 개발 버전
// 라우팅
app.get('/', routes.index);
app.get('/login',function(req,res){
fs.readFile('./views/login.html',function(error,data){
res.writeHead(200, {'Content-Type': 'text/html'});
res.end(data);
})
});
app.get('/signup',function(req,res){
fs.readFile('./views/signup.html',function(error,data){
res.writeHead(200,{'Content-Type':'text/html'});
res.end(data);
})
})
app.get('/LogInForm',login.LogInForm);
app.post('/SignUpForm',login.SignUpForm);
app.get('/list', todo.list);
app.post('/add', todo.add);
app.post('/complete', todo.complete);
......
$(document).ready(function(){
// 로그인 처리
$('#login-submit').click(function(e) {
if ($("#userid").val() == '') {
alert('아이디를 입력하세요');
$("#userid").focus();
return false;
}
if ($("#password").val() == '') {
alert('비밀번호를 입력하세요');
$("#password").focus();
return false;
}
var Info={
'userId': $('#userid').val(),
'password' : $('#password').val()
}
$.ajax('/LogInForm',{
'method': 'GET',
'data': {
'Info' : Info
},
'success': function(list){
list=JSON.parse(list).list;
for (var i=0, len=list.length; i < len; i++){
if (list[i].userId==Info['userId']){
if (list[i].password==Info['password']){
location.href='/';
}
}
}
}
})
})
$('#makeInfo').click(function(e){
location.href='/signup';
})
});
$(function() {
// 로그인 처리
$('#submit').click(function(e) {
if ($("#fname").val() == '') {
alert('이름을 입력하세요');
$("#fname").focus();
return false;
}
if ($("#email").val()== ''){
alert('아이디를 입력하세요.')
$('#email').focus();
return false;
}
if ($("#ssnein").val()==''){
alert("API키를 입력하세요");
$("#ssnein").focus();
return false;
}
if ($("#passwd").val() == '') {
alert('비밀번호를 입력하세요');
$("#passwd").focus();
return false;
}
if ($("#passwdcheck").val() != $("#passwd").val()){
alert("비밀번호 불일치");
$("#passwdcheck").focus();
return false;
}
$.ajax('/SignUpForm',{
'method': 'Post',
'data': {
'fname': $('#fname').val(),
'userId': $('#email').val(),
'API':$('#ssnein').val(),
'password' : $('#passwd').val(),
},
'success': function(e){
location.href='/login';
}
})
})
});
\ No newline at end of file
......@@ -3,7 +3,6 @@ $(document).ready(function () {
$.ajax('/list', {
'success': function (list) {
var trs = '';
list = JSON.parse(list).list;
for(var i = 0, len = list.length; i < len; i++) { // 테이블 내용 만들기
......@@ -21,7 +20,7 @@ $(document).ready(function () {
};
get_list();
$('.form-inline button').click(function () { // 새로운 할 일 추가하기
var $getVal = $('#new_todo').val();
var $getVal2 = $('#count').val();
......
......@@ -5,4 +5,4 @@
exports.index = function(req, res){
res.render('index', { title: '나만의 YOUTUBE 리스트' });
};
\ No newline at end of file
};
......
var fs = require('fs');
var request = require('request');
exports.LogInForm=function(req,res){
fs.exists('./user_list.json', function (exists) { // ToDo 목록 존재 확인
if(exists) {
fs.readFile('./user_list.json', {
'encoding': 'utf8'
}, function (err, list) {
console.log(list);
res.json(list);
});
} else {
var list = { // 기본 ToDo 목록 형식
'list': []
};
fs.writeFile('./user_list.json', JSON.stringify(list), function (err) { // todo_list.json 파일 쓰기
res.json(list);
});
}
});
};
exports.SignUpForm=function(req,res){
fs.readFile('./user_list.json',{
'encoding':'utf-8'
},function(err,data){
data=JSON.parse(data);
var Info={
'fname': req.body.fname,
'userId': req.body.userId,
'API':req.body.API,
'password' : req.body.password,
}
data.list.push(Info);
fs.writeFile('./user_list.json',JSON.stringify(data),function(err){
res.json(true);
});
}
)
}
\ No newline at end of file
......@@ -43,10 +43,6 @@ exports.add = function(req, res1){ // 새로운 ToDo 항목 추가하기
regionCode:"KR",
order:"viewCount"
};
console.log("'");
console.log("`");
optionParams.q = encodeURI(optionParams.q);
var url="https://www.googleapis.com/youtube/v3/search?";
......@@ -66,7 +62,6 @@ exports.add = function(req, res1){ // 새로운 ToDo 항목 추가하기
'encoding':'utf8'
},function(err,data){
data= JSON.parse(data);
data.list=[];
for (var content in data2){
var todo = { // 기본 ToDo 항목 형식
'contents': '',
......@@ -84,24 +79,6 @@ exports.add = function(req, res1){ // 새로운 ToDo 항목 추가하기
}
});
});
//todo.contents = req.body.contents;
/*
fs.readFile('./todo_list.json', {
'encoding': 'utf8'
}, function (err, data) {
data = JSON.parse(data);
for (var i=0;i<5;i++)
{
data.list.push(VideoIds[i]);
}
// 새로운 ToDo 항목 추가
fs.writeFile('./todo_list.json', JSON.stringify(data), function (err) {
res.json(true);
});
});*/
};
exports.complete = function(req, res){ // 선택한 ToDo 항목 완료하기
......
{"list":[{"contents":"[런닝맨] &#39;박지성(Park ji sung)&amp;런닝맨 vs 설기현(Seol ki hyeon)&amp;아이돌&#39; / &#39;RunningMan&#39; Review","videoId":"sVtNdmAKvUw","complete":false},{"contents":"박지성이 우리 팀에 일일용병으로 나온다면? (100% 리얼) ㅋㅋㅋㅋㅋㅋㅋㅋ l 슛포러브 Shoot for Love","videoId":"VqM7SZU1Qgk","complete":false},{"contents":"멕시코전 앞두고 손흥민과 치차리토를 만난 박지성. 긴 대화가 진짜 필요없는 듯 l 후방빌드업 in 러시아 월드컵 l 슛포러브 Shoot for Love","videoId":"GfHfuVOO37Q","complete":false},{"contents":"36m에서 떨어지는 공 트래핑 하기 도전하는 박지성ㄷㄷㄷ 퍼스트 터치 지렸다 l 슛포러브 Shoot for Love","videoId":"fhtUPZTaWPM","complete":false},{"contents":"방금 나온 박지성 2명재끼고 골 대박 [맨유 vs MLS 올스타]","videoId":"e0uZXCEFaes","complete":false},{"contents":"박지성, 맨유 현지팬들의 솔직한 평가(정말 예상치 못한 대답들..)","videoId":"6xUEoAiYIAk","complete":false},{"contents":"[감동주의] 박지성과 퍼거슨","videoId":"HJr_4FWvRmE","complete":false}]}
\ No newline at end of file
{"list":[{"contents":"구자철·기성용 &quot;남태희, 백성동 빨리 안나와?&quot;","videoId":"JFedpGFFjkM","complete":false}]}
\ No newline at end of file
......
{"list":[{"fname":"김경훈","userId":"kkh115505@naver.com","API":"abcdefg","password":"1234"}]}
\ No newline at end of file
......@@ -15,7 +15,7 @@
<div class ="form-group">
<input type="number"class="form-control" id="count" placeholder ="갯수">
</div>
<button type="button" class="btn btn-primary">추가</button>
<button type="button" class="btn btn-primary">검색</button>
</form>
<table class="table"> <!-- ToDo 목록 -->
<thead>
......
<!------ Include the above in your HEAD tag ---------->
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<!-- Fonts -->
<link rel="dns-prefetch" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css?family=Raleway:300,400,600" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="/stylesheets/style.css">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
<title>로그인</title>
</head>
<body>
<main class="login-form">
<div class="cotainer">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">Login</div>
<div class="card-body">
<form action="" method="">
<div class="form-group row">
<label for="userid" class="col-md-4 col-form-label text-md-right">E-Mail Address</label>
<div class="col-md-6">
<input type="text" id="userid" class="form-control" name="userid" required autofocus>
</div>
</div>
<div class="form-group row">
<label for="password" class="col-md-4 col-form-label text-md-right">Password</label>
<div class="col-md-6">
<input type="password" id="password" class="form-control" name="password" required>
</div>
</div>
<div class="col-md-6 offset-md-4">
<button type="submit" id="login-submit" class="btn btn-primary">
로그인
</button>
<button type="button" id="makeInfo" class="btn btn-primary">
회원가입하기
</button>
</a>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</main>
</body>
<script src="/javascripts/login.js"></script>
</html>
\ No newline at end of file
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link href="//netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.0/js/bootstrap.min.js"></script>
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<!------ Include the above in your HEAD tag ---------->
<title>회원가입 페이지</title>
</head>
<form class="form-horizontal">
<fieldset>
<!-- Form Name -->
<legend>새로운 사용자 등록</legend>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="fname">이름</label>
<div class="col-md-5">
<input id="fname" name="fname" type="text" placeholder="이름을 입력하세요." class="form-control input-md" required="">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="email">아이디</label>
<div class="col-md-5">
<input id="email" name="email" type="eamil" placeholder="이메일을 입력하세요." class="form-control input-md" required="">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="ssnein">YouTube Api Key</label>
<div class="col-md-5">
<input id="ssnein" name="ssnein" type="text" placeholder="YouTube Api Key" class="form-control input-md" required="">
<span class="help-block">링크 걸어줍시다.</span>
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="passwd">비밀번호</label>
<div class="col-md-5">
<input id="passwd" name="passwd" type="password" placeholder="비밀번호를 입력하세요." class="form-control input-md" required="">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label" for="passwdcheck">비밀번호확인</label>
<div class="col-md-5">
<input id="passwdcheck" name="passwdcheck" type="password" placeholder="비밀번호를 입력하세요." class="form-control input-md" required="">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label" for="submit"></label>
<div class="col-md-4">
<label class="checkbox-inline" for="submit">
<input class="btn btn-success" type="submit" name="submit" id="submit" value="새로운 계정 생성하기">
</label>
</div>
</div>
</fieldset>
</form>
<script src="/javascripts/signup.js"></script>
</html>
\ No newline at end of file
This file is too large to display.
This file is too large to display.
This file is too large to display.
This file is too large to display.