hyunjong

네이버, 다음 로그인 에러 처리, 클린코드

......@@ -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('/');
})
//
......@@ -153,87 +152,134 @@ function getLatestToon(titleid, day ,cb) {
}
function getDaumToons(_day){
// X요일 다음 웹툰
//_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"];
list.forEach(function (item, idx) {
list.forEach(function (item, idx) {
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
};
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
};
allWebtoonList.push(webtoon);
});
});
});
}
//
function getNaverToons(){
// 네이버 전체 웹툰 불러오기
function getNaverToons() {
var allWeeklyToonsUrl = "http://comic.naver.com/webtoon/weekday.nhn";
request(allWeeklyToonsUrl,function (err, res, html) {
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
};
allWebtoonList.push(webtoon);
});
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
};
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 {
console.log("웹툰 DB처리 완료!");
}
});
})
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 {
console.log("웹툰 DB처리 완료!");
}
});
}
})
});
}
});
}
// 구현중
function getTomicsToons(){
var allWeeklyToonsUrl = "https://www.lezhin.com/ko/scheduled";
request(allWeeklyToonsUrl,function (err, res, html) {
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 = "https://www.lezhin.com/ko" + $(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
};
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 {
console.log("웹툰 DB처리 완료!");
}
});
})
});
}
});
}
// 설명
// 모든 웹튼을 담고있는 배열
allWebtoons = new Array();
// 설명
......
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.