Akhidjon

merging

dd
\ No newline at end of file
니툰내툰 URL : http://52.79.239.80:3000
2013100924 이현종
2018102151 Abdullaev Akhidjon
1. 네이버, 구글 로그인을 추가하였습니다.
2. 레진 코믹스 웹툰을 추가하였습니다.
3. 코드의 생산성을 증가시켰습니다.
(코드의 중복과 필요없는 부분을 삭제함, 주석을 달음)
......@@ -47,7 +47,6 @@ var mytoons = require('./routes/mytoons');
var yourtoons =require('./routes/yourtoons');
var setting = require('./routes/setting');
// 최초 로그인 성공시 (Strategy 성공시) 단 한번만 호출
passport.serializeUser(function(user, done) {
console.log('serialized');
......
......@@ -9,27 +9,27 @@ var NaverStrategy = require('passport-naver').Strategy;
var GoogleStrategy = require('passport-google-oauth').OAuth2Strategy;
var router = express.Router();
// 설명
// kakao login API
var kakaoKey = {
clientID : '5634a5f8ca5c9a5eb378d6b6e6e869a0',
callbackURL : '/auth/login/kakao/callback'
};
//
// naver login API
var naverKey = {
clientID : 'OHmCrpQuVFnIEB4GkmF_',
callbackURL : '/auth/login/naver/callback',
clientSecret : 'BBgcRdnj0M'
};
//
// google login API
var googleKey = {
clientID : '924802195853-ir977i2ohnddaaninlqlbeg6sov629hq.apps.googleusercontent.com',
callbackURL : '/auth/login/google/callback',
clientSecret : 'NaWeoJouUzYq4VfBesTkdUfA'
};
//
// kakao passport
passport.use(new KakaoStrategy(kakaoKey,
function(accessToken, refreshToken,params, profile, done) {
console.log(profile);
......@@ -41,7 +41,7 @@ passport.use(new KakaoStrategy(kakaoKey,
}
));
//
// naver passport
passport.use(new NaverStrategy(naverKey,
function (accessToken, refreshToken, profile, done) {
console.log(profile);
......@@ -53,7 +53,7 @@ passport.use(new NaverStrategy(naverKey,
}
));
//
// google passport
passport.use(new GoogleStrategy(googleKey,
function (accessToken, refreshToken, profile, done) {
console.log(profile);
......@@ -68,29 +68,28 @@ passport.use(new GoogleStrategy(googleKey,
// kakao 로그인, 로그인 콜백
router.get('/auth/login/kakao', passport.authenticate('kakao'));
router.get('/auth/login/kakao/callback', passport.authenticate('kakao', {
successRedirect: '/mytoons',
failureRedirect: '/'
})
successRedirect: '/mytoons',
failureRedirect: '/'
})
);
// naver 로그인
// naver 로그인, 로그인 콜백
router.get('/auth/login/naver', passport.authenticate('naver'));
router.get('/auth/login/naver/callback',
passport.authenticate('naver', {
successRedirect: '/mytoons',
failureRedirect: '/'
router.get('/auth/login/naver/callback', passport.authenticate('naver', {
successRedirect: '/mytoons',
failureRedirect: '/'
})
);
// facebook 로그인, 로그인 콜백
router.get('/auth/login/google', passport.authenticate('google', { scope: ['email profile'] }));
router.get('/auth/login/google/callback', passport.authenticate('google', {
successRedirect: '/mytoons',
failureRedirect: '/'
successRedirect: '/mytoons',
failureRedirect: '/'
})
);
// 설명
// 로그인 처리
function loginByThirdparty(info, done) {
var stmt_duplicated = "select *from `user` where id = id";
//'select *from `user` where `id` = ?
......@@ -125,27 +124,27 @@ function loginByThirdparty(info, done) {
});
}
router.get('/login', function(req,res){
router.get('/login', function(req,res) {
res.render('login_page')
})
// 라우터 설정, 카카오
router.get('/auth/logout/kakao',function (req,res) {
req.logout();
res.redirect('/');
req.logout();
res.redirect('/');
})
// 라우터 설정, 페이스북
router.get('/auth/logout/naver',function (req,res) {
req.logout();
res.redirect('/');
req.logout();
res.redirect('/');
})
// 라우터 설정, 구글
router.get('/auth/logout/google',function (req,res) {
req.logout();
res.redirect('/');
req.logout();
res.redirect('/');
})
//
......@@ -175,20 +174,27 @@ function gettop(){
};
function getDaumToons(_day){
// X요일 다음 웹툰
var daumCount = 0;
//_day요일의 다음웹툰 불러오기
function getDaumToons(_day) {
var day = _day;
var day_name = day;
var daum = `http://webtoon.daum.net/data/pc/webtoon/list_serialized/${day}?timeStamp=1515819276574`;
var site = 'daum';
client.fetch(daum, {}, function (err, $, res, body) {
client.fetch(daum, {}, function (err, $, res, body){
var data = JSON.parse(body);
var list = data["data"];
var data = JSON.parse(body);
var list = data["data"];
if(err) {
console.log("다음웹툰 DB 에러 : " + err);
} else {
list.forEach(function (item, idx) {
<<<<<<< HEAD
var webtoon_link = 'http://webtoon.daum.net/webtoon/view/' + item.nickname.toString();
var webtoon = {
toon_index : item.id,
......@@ -202,14 +208,35 @@ function getDaumToons(_day){
};
allWebtoonList.push(webtoon);
=======
var webtoon_link = 'http://webtoon.daum.net/webtoon/view/' + item.nickname.toString();
var webtoon = {
toon_index : item.id,
name : item.title,
thum_link : item.pcThumbnailImage.url,
webtoon_link : webtoon_link,
week : day_name,
site : site,
latest : 0
};
daumCount++;
allWebtoonList.push(webtoon);
>>>>>>> 0b039040370950fe61e1c6ae5d5cf6650db9652f
});
}
});
}
//
function getNaverToons(){
// 네이버 전체 웹툰 불러오기
function getNaverToons() {
var allWeeklyToonsUrl = "http://comic.naver.com/webtoon/weekday.nhn";
// 네이버 웹툰 개수
var naverCount = 0;
var webtoonCount = 0;
request(allWeeklyToonsUrl,function (err, res, html) {
<<<<<<< HEAD
if(!err){
var $ = cheerio.load(html);
var p = Promise.resolve();
......@@ -247,11 +274,54 @@ function getNaverToons(){
}
});
})
=======
if(!err){
var $ = cheerio.load(html);
var p = Promise.resolve();
var eachs = $(".thumb").each(function (i) {
var week = $(this).parent().parent().prev().attr('class');
var webtoon_link = "http://comic.naver.com" + $(this).children().first().attr('href');
var thumb_link = $(this).children().first().children().first().attr('src');
var name = $(this).next().text();
var titleid = webtoon_link.split('?')[1].split('&')[0].split('=')[1];
var site = 'naver';
var webtoon= {
toon_index: titleid,
name : name,
thum_link : thumb_link,
webtoon_link : webtoon_link,
week : week,
site : site,
latest : 0
};
naverCount++;
allWebtoonList.push(webtoon);
});
p.then(function() {
i = 0;
allWebtoonList.forEach(function (webtoon) {
var sql= "INSERT INTO `toon` (toon_index, name, thum_link, webtoon_link, week, site, latest) VALUES(?) ON DUPLICATE KEY UPDATE latest=latest";
var values=[webtoon.toon_index, webtoon.name, webtoon.thum_link, webtoon.webtoon_link,webtoon.week, webtoon.site, webtoon.latest];
connection.query(sql,[values],function(err,result){
if(err) {
console.log("웹툰 DB 에러 : " + err);
} else {
webtoonCount++;
console.log(`웹툰 ${webtoonCount}개 DB처리 완료!`);
}
>>>>>>> 0b039040370950fe61e1c6ae5d5cf6650db9652f
});
}
})
});
}
console.log(`다음웹툰 ${daumCount}개, 네이버웹툰 ${naverCount}개`)
});
}
<<<<<<< HEAD
......@@ -261,6 +331,9 @@ function getTomicsToons(){
}
// 설명
=======
// 모든 웹툰을 담고있는 배열
>>>>>>> 0b039040370950fe61e1c6ae5d5cf6650db9652f
allWebtoons = new Array();
// 설명
......
......@@ -2,42 +2,40 @@ var express = require('express');
var async = require('async');
var router = express.Router();
function getMyToons(id,cb){
//id 값을 가진 user가 저장한 웹툰들 가져오기
var sqlquery = "SELECT t.toon_index, t.name, t.thum_link, t.webtoon_link, t.week, t.site FROM user u, user_toon_relation ur, toon t WHERE u.id = '"+id+"' && u.id=ur.user_id && t.toon_index=ur.toon_index;";
var mylist = new Array();
connection.query(sqlquery,id,function(err,rows,result){
if(!err){
mylist=rows;
cb(mylist);
console.log(mylist);
}else{
console.log("내 웹툰 리스트 가져오는데 실패했습니다!");
//throw err;
}
});
function getMyToons(id,cb) {
//id 값을 가진 user가 저장한 웹툰들 가져오기
var sqlquery = "SELECT t.toon_index, t.name, t.thum_link, t.webtoon_link, t.week, t.site FROM user u, user_toon_relation ur, toon t WHERE u.id = '"+id+"' && u.id=ur.user_id && t.toon_index=ur.toon_index;";
var mylist = new Array();
connection.query(sqlquery,id,function(err,rows,result) {
if(!err) {
mylist=rows;
cb(mylist);
console.log(mylist);
} else {
console.log("내 웹툰 리스트 가져오는데 실패했습니다!");
//throw err;
}
});
}
/* GET home page. */
router.get('/', function(req, res, next) {
if(!req.isAuthenticated()){
res.redirect('/');
}else{
async.series(
[
function(callback){
getMyToons(req.user.user_id, function (mytoon_list) {
callback(null,mytoon_list);
});
}
],
function(err, results){
res.render('mytoons', {
mytoons: results[0]
});
}
);
}
if(!req.isAuthenticated()) {
res.redirect('/');
} else {
async.series([
function(callback){
getMyToons(req.user.user_id, function (mytoon_list) {
callback(null,mytoon_list);
});
}],
function(err, results){
res.render('mytoons', {
mytoons: results[0]
});
}
);
}
});
module.exports = router;
......
......@@ -2,70 +2,69 @@ var express = require('express');
var router = express.Router();
function addMyToons(id,index,cb){
connection.query("INSERT INTO user_toon_relation SET ?;", {user_id : id,toon_index : index},function (err) {
if(err) {
throw err;
console.log("내 웹툰 추가 중 에러!")
} else{
// alert("추가되었습니다.")
cb();
}
});
connection.query("INSERT INTO user_toon_relation SET ?;", {user_id : id,toon_index : index},function (err) {
if(err) {
throw err;
console.log("내 웹툰 추가 중 에러!")
} else {
alert("추가되었습니다.")
cb();
}
});
}
//내툰 수정하기
router.post('/toggle_toon',function(req,res,next){
var index = req.body.toon_index;
var id = req.user.user_id;
connection.query("SELECT COUNT(*) FROM user_toon_relation WHERE user_id='"+id+"' && toon_index='"+index+"'", [id,index], function (err, rows,result) {
if(err) {
console.log("내 웹툰 등록 중 에러!");
} else {
var count = rows[0]["COUNT(*)"];
if(count>0) {//이미 등록되어 있는 것이라면,
connection.query("DELETE FROM user_toon_relation WHERE user_id='"+id+"' && toon_index='"+index+"';", [id, index],function (err, rows, result) {
if(err) {
console.log("내 웹툰 제거중 에러!");
throw err;
} else {
//alert("제거되었습니다.")
res.redirect('/setting');
}
});
} else {
addMyToons(id,index,function(){
res.redirect('/setting');
});
}
}
});
router.post('/toggle_toon',function(req,res,next) {
var index = req.body.toon_index;
var id = req.user.user_id;
connection.query("SELECT COUNT(*) FROM user_toon_relation WHERE user_id='"+id+"' && toon_index='"+index+"'", [id,index], function (err, rows,result) {
if(err) {
console.log("내 웹툰 등록 중 에러!");
} else {
var count = rows[0]["COUNT(*)"];
if(count > 0) { //이미 등록되어 있는 것이라면,
connection.query("DELETE FROM user_toon_relation WHERE user_id='"+id+"' && toon_index='"+index+"';", [id, index],function (err, rows, result) {
if(err) {
console.log("내 웹툰 제거중 에러!");
throw err;
} else {
alert("제거되었습니다.")
res.redirect('/setting');
}
});
} else {
addMyToons(id,index,function() {
res.redirect('/setting');
});
}
}
});
});
//
function getMyToons(id,cb){
//mysql5.7 syntax에 맞게 수정 => 로그인한 유저의
var sqlquery = "SELECT t.toon_index, t.name, t.thum_link, t.webtoon_link, t.week, t.site FROM user u, user_toon_relation ur, toon t WHERE u.id = '"+id+"' && u.id=ur.user_id && t.toon_index=ur.toon_index;";
var mylist = new Array();
connection.query(sqlquery,id,function(err,rows,result){
if(!err){
mylist=rows;
cb(mylist);
}else{
router.get('/')
console.log("내 웹툰 리스트 가져오는데 실패했습니다!");
//throw err;
}
});
//mysql5.7 syntax에 맞게 수정 => 로그인한 유저의
var sqlquery = "SELECT t.toon_index, t.name, t.thum_link, t.webtoon_link, t.week, t.site FROM user u, user_toon_relation ur, toon t WHERE u.id = '"+id+"' && u.id=ur.user_id && t.toon_index=ur.toon_index;";
var mylist = new Array();
connection.query(sqlquery,id,function(err,rows,result) {
if(!err) {
mylist = rows;
cb(mylist);
} else {
router.get('/')
console.log("내 웹툰 리스트 가져오는데 실패했습니다!");
//throw err;
}
});
}
router.get('/', function(req, res, next) {
getMyToons(req.user.user_id,function (mytoons) {
res.render('setting',{
alltoons : allWebtoons,
mytoons : mytoons
});
})
getMyToons(req.user.user_id,function (mytoons) {
res.render('setting',{
alltoons : allWebtoons,
mytoons : mytoons
});
})
});
module.exports = router;
......
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.