Showing
1 changed file
with
72 additions
and
87 deletions
| ... | @@ -2,86 +2,65 @@ var express = require('express'); | ... | @@ -2,86 +2,65 @@ var express = require('express'); |
| 2 | var cheerio = require('cheerio'); | 2 | var cheerio = require('cheerio'); |
| 3 | var request = require('request'); | 3 | var request = require('request'); |
| 4 | var mysql = require('mysql'); | 4 | var mysql = require('mysql'); |
| 5 | -var sha256 = require('js-sha256'); | ||
| 6 | 5 | ||
| 7 | // 설명 | 6 | // 설명 |
| 8 | var client = require('cheerio-httpcli'); | 7 | var client = require('cheerio-httpcli'); |
| 9 | -var passport = require('passport') | 8 | +var passport = require('passport'), KakaoStrategy = require('passport-kakao').Strategy; |
| 10 | -var KakaoStrategy = require('passport-kakao').Strategy; | ||
| 11 | var router = express.Router(); | 9 | var router = express.Router(); |
| 12 | 10 | ||
| 13 | // 설명 | 11 | // 설명 |
| 14 | -var kakaoKey = { | 12 | +passport.use(new KakaoStrategy({ |
| 15 | - clientID : 'd7ba37067bddfb0661513607bb5eddef', | 13 | + |
| 16 | - clientSecret : 'NZQsjsqhzDnjjMqFuEY805wBM1AwIsBY', | 14 | + clientID : '5634a5f8ca5c9a5eb378d6b6e6e869a0', |
| 17 | - callbackURL : 'http://localhost:3000/api/auth/kakao/callback' | 15 | + callbackURL :'/auth/login/kakao/callback', |
| 18 | -}; | 16 | + //clientSecret : 'eUtJGtlLoCZJufevp3LKfDP0KOtZUV7R' |
| 17 | + | ||
| 18 | + }, function(accessToken, refreshToken,params, profile, done){ | ||
| 19 | + | ||
| 20 | + //사용자 정보 -> profile | ||
| 21 | + loginByThirdparty(accessToken, refreshToken, profile); | ||
| 22 | + console.log("(!)로그인 : " + profile._json.id+"("+profile._json.properties.nickname +")"); | ||
| 23 | + | ||
| 24 | + //return done(null,profile) | ||
| 25 | + return done(null, { | ||
| 26 | + 'user_id': profile._json.id, | ||
| 27 | + 'nickname': profile._json.properties.nickname | ||
| 28 | + | ||
| 29 | + }); | ||
| 30 | + } | ||
| 31 | +)); | ||
| 19 | 32 | ||
| 20 | -passport.use("kakao-login", new KakaoStrategy(kakaoKey, function(accessToken, refreshToken, profile, done){ | 33 | +// kakao 로그인, // passport.authenticate('kakao',{state: "myStateValue"}) |
| 21 | - var _profile = profile._json; | 34 | +router.get('/auth/login/kakao', passport.authenticate('kakao')); |
| 22 | - console.log("error1"); | ||
| 23 | - //사용자 정보는 profile에 | ||
| 24 | - loginByThirdparty({ | ||
| 25 | - 'auth_type': 'kakao', | ||
| 26 | - 'auth_id': _profile.id, | ||
| 27 | - 'auth_name': _profile.properties.nickname, | ||
| 28 | - 'auth_email': _profile.id | ||
| 29 | - }, done); | ||
| 30 | - console.log("(!)로그인 : " + profile._json.id + "(" + profile._json.properties.nickname + ")" ); | ||
| 31 | - console.log("error2"); | ||
| 32 | -})); | ||
| 33 | - | ||
| 34 | -// kakao 로그인, // passport.authenticate('kakao',{state: "myStateValue"}) | ||
| 35 | -router.get('/api/auth/kakao', passport.authenticate('kakao-login')); | ||
| 36 | 35 | ||
| 37 | // kakao 로그인 연동 콜백 | 36 | // kakao 로그인 연동 콜백 |
| 38 | -router.get('/api/auth/kakao/callback', passport.authenticate('kakao-login', { | 37 | +router.get('/auth/login/kakao/callback', passport.authenticate('kakao', { |
| 39 | - //session: false, | 38 | + |
| 40 | - successRedirect: '/routes/mytoons', | 39 | + //session: false, |
| 41 | - failureRedirect: '/' | 40 | + successRedirect: '/mytoons', |
| 42 | - }) | 41 | + failureRedirect: '/' |
| 42 | + }) | ||
| 43 | ); | 43 | ); |
| 44 | 44 | ||
| 45 | // 설명 | 45 | // 설명 |
| 46 | -function loginByThirdparty(info, done) { | 46 | +function loginByThirdparty(accessToken, refreshToken, profile) { |
| 47 | - console.log("error3"); | 47 | + // 예전 코드는 MySQL 버젼이 맞지 않음 |
| 48 | - // 예전 코드는 MySQL 버젼이 맞지 않음 | 48 | + // var sql = 'INSERT INTO `user`(id) VALUES(?) ON DUPLICATE KEY(PRIMARY) UPDATE id=(?);' |
| 49 | - // var sql = 'INSERT INTO `user`(id) VALUES(?) ON DUPLICATE KEY(PRIMARY) UPDATE id=(?);' | 49 | + var sql = "INSERT INTO `user` (id) VALUES (?) ON DUPLICATE KEY UPDATE id=id"; |
| 50 | - var sql = 'select *from `user` where `user_id` = ?'; | 50 | + var kid=[profile._json.id]; |
| 51 | - | 51 | + connection.query(sql,kid,function(err,result){ |
| 52 | - connection.query(sql, info.auth_id, function(err,result){ | 52 | + if (err) { |
| 53 | - if (err) { | 53 | + console.log("로그인 쿼리중 에러 : " + err); |
| 54 | - return done(err); | 54 | + } else { |
| 55 | - } else { | 55 | + console.log("로그인 DB처리 완료!"); |
| 56 | - if (result.length === 0) { | 56 | + } |
| 57 | - // 신규 유저는 회원 가입 이후 로그인 처리 | 57 | + }); |
| 58 | - var stmt_thridparty_signup = 'insert into `user` set `user_id`= ?, `nickname`= ?'; | ||
| 59 | - connection.query(stmt_thridparty_signup, [info.auth_id, info.auth_name], function (err, result) { | ||
| 60 | - if(err){ | ||
| 61 | - return done(err); | ||
| 62 | - }else{ | ||
| 63 | - done(null, { | ||
| 64 | - 'user_id': info.auth_id, | ||
| 65 | - 'nickname': info.auth_name | ||
| 66 | - }); | ||
| 67 | - } | ||
| 68 | - }); | ||
| 69 | - } else { | ||
| 70 | - //기존유저 로그인 처리 | ||
| 71 | - console.log('Old User'); | ||
| 72 | - done(null, { | ||
| 73 | - 'user_id': result[0].user_id, | ||
| 74 | - 'nickname': result[0].nickname | ||
| 75 | - }); | ||
| 76 | - } | ||
| 77 | - } | ||
| 78 | - }); | ||
| 79 | } | 58 | } |
| 80 | 59 | ||
| 81 | // 설명 | 60 | // 설명 |
| 82 | -router.get('/api/auth/logout/kakao',function (req,res) { | 61 | +router.get('/auth/logout/kakao',function (req,res) { |
| 83 | - req.logout(); | 62 | + req.logout(); |
| 84 | - res.redirect('/'); | 63 | + res.redirect('/'); |
| 85 | }) | 64 | }) |
| 86 | 65 | ||
| 87 | // | 66 | // |
| ... | @@ -95,35 +74,35 @@ allWebtoons = new Array(); | ... | @@ -95,35 +74,35 @@ allWebtoons = new Array(); |
| 95 | // 설명 | 74 | // 설명 |
| 96 | function getAllToons() { | 75 | function getAllToons() { |
| 97 | 76 | ||
| 98 | - allWebtoonList = new Array(); | 77 | + allWebtoonList = new Array(); |
| 99 | 78 | ||
| 100 | - //월요일 다음 웹툰 | 79 | + //월요일 다음 웹툰 |
| 101 | - var mon='mon'; | 80 | + var mon='mon'; |
| 102 | - var mon_name='MON'; | 81 | + var mon_name='MON'; |
| 103 | - var daum = `http://webtoon.daum.net/data/pc/webtoon/list_serialized/${mon}?timeStamp=1515819276574`; | 82 | + var daum = `http://webtoon.daum.net/data/pc/webtoon/list_serialized/${mon}?timeStamp=1515819276574`; |
| 104 | - var site = 'daum'; | 83 | + var site = 'daum'; |
| 105 | 84 | ||
| 106 | - client.fetch(daum, {}, function (err, $, res, body) { | 85 | + client.fetch(daum, {}, function (err, $, res, body) { |
| 107 | 86 | ||
| 108 | - var data = JSON.parse(body); | 87 | + var data = JSON.parse(body); |
| 109 | - var list = data["data"]; | 88 | + var list = data["data"]; |
| 110 | 89 | ||
| 111 | - list.forEach(function (item, idx) { | 90 | + list.forEach(function (item, idx) { |
| 112 | 91 | ||
| 113 | - var webtoon_link = 'http://webtoon.daum.net/webtoon/view/' + item.nickname.toString(); | 92 | + var webtoon_link = 'http://webtoon.daum.net/webtoon/view/' + item.nickname.toString(); |
| 114 | - var webtoon = { | 93 | + var webtoon = { |
| 115 | - toon_index: item.id, | 94 | + toon_index: item.id, |
| 116 | - name: item.title, | 95 | + name: item.title, |
| 117 | - thum_link: item.pcThumbnailImage.url, | 96 | + thum_link: item.pcThumbnailImage.url, |
| 118 | - webtoon_link: webtoon_link, | 97 | + webtoon_link: webtoon_link, |
| 119 | - week :mon_name, | 98 | + week :mon_name, |
| 120 | - site: site, | 99 | + site: site, |
| 121 | - latest: 0 | 100 | + latest: 0 |
| 122 | - }; | 101 | + }; |
| 123 | 102 | ||
| 124 | - allWebtoonList.push(webtoon); | 103 | + allWebtoonList.push(webtoon); |
| 104 | + }); | ||
| 125 | }); | 105 | }); |
| 126 | - }); | ||
| 127 | 106 | ||
| 128 | //화요일 다음 웹툰 | 107 | //화요일 다음 웹툰 |
| 129 | var tue='tue'; | 108 | var tue='tue'; |
| ... | @@ -274,6 +253,9 @@ function getAllToons() { | ... | @@ -274,6 +253,9 @@ function getAllToons() { |
| 274 | }); | 253 | }); |
| 275 | }); | 254 | }); |
| 276 | 255 | ||
| 256 | + | ||
| 257 | + | ||
| 258 | + | ||
| 277 | //네이버 웹툰 | 259 | //네이버 웹툰 |
| 278 | var allWeeklyToonsUrl = "http://comic.naver.com/webtoon/weekday.nhn"; | 260 | var allWeeklyToonsUrl = "http://comic.naver.com/webtoon/weekday.nhn"; |
| 279 | request(allWeeklyToonsUrl,function (err, res, html) { | 261 | request(allWeeklyToonsUrl,function (err, res, html) { |
| ... | @@ -316,6 +298,9 @@ function getAllToons() { | ... | @@ -316,6 +298,9 @@ function getAllToons() { |
| 316 | }); | 298 | }); |
| 317 | } | 299 | } |
| 318 | }); | 300 | }); |
| 301 | + | ||
| 302 | + | ||
| 303 | + | ||
| 319 | allWebtoons = allWebtoonList; | 304 | allWebtoons = allWebtoonList; |
| 320 | }; | 305 | }; |
| 321 | 306 | ... | ... |
-
Please register or login to post a comment