윤혜원

DB에 user, toon 정보 INSERT 성공!

...@@ -2,5 +2,6 @@ ...@@ -2,5 +2,6 @@
2 <project version="4"> 2 <project version="4">
3 <component name="VcsDirectoryMappings"> 3 <component name="VcsDirectoryMappings">
4 <mapping directory="$PROJECT_DIR$" vcs="Git" /> 4 <mapping directory="$PROJECT_DIR$" vcs="Git" />
5 + <mapping directory="$PROJECT_DIR$/YTMT" vcs="Git" />
5 </component> 6 </component>
6 </project> 7 </project>
...\ No newline at end of file ...\ No newline at end of file
......
This diff is collapsed. Click to expand it.
...@@ -15,9 +15,7 @@ var setting = require('./routes/setting'); ...@@ -15,9 +15,7 @@ var setting = require('./routes/setting');
15 var session = require('express-session'); 15 var session = require('express-session');
16 var toonviewer = require('./routes/toonviewer'); 16 var toonviewer = require('./routes/toonviewer');
17 17
18 -
19 //port 18 //port
20 -
21 passport.serializeUser(function(user, done) { 19 passport.serializeUser(function(user, done) {
22 console.log('serialized'); 20 console.log('serialized');
23 done(null, user); 21 done(null, user);
...@@ -44,7 +42,7 @@ app.use(express.static(path.join(__dirname, 'public'))); ...@@ -44,7 +42,7 @@ app.use(express.static(path.join(__dirname, 'public')));
44 connection = mysql.createConnection({ 42 connection = mysql.createConnection({
45 host : 'localhost', 43 host : 'localhost',
46 user : 'root', 44 user : 'root',
47 - password : 'hs970010!', 45 + password : 'password',
48 port : 3306, 46 port : 3306,
49 database : 'ytmt' 47 database : 'ytmt'
50 }); 48 });
...@@ -62,8 +60,6 @@ app.use('/users', users); ...@@ -62,8 +60,6 @@ app.use('/users', users);
62 app.use('/mytoons', mytoons); 60 app.use('/mytoons', mytoons);
63 app.use('/setting', setting); 61 app.use('/setting', setting);
64 app.use('/toonviewer', toonviewer); 62 app.use('/toonviewer', toonviewer);
65 -//app.use('/daum', daum);
66 -
67 //app.use(express.static('views')); 63 //app.use(express.static('views'));
68 64
69 // catch 404 and forward to error handler 65 // catch 404 and forward to error handler
......
...@@ -9,8 +9,8 @@ var passport = require('passport'), ...@@ -9,8 +9,8 @@ var passport = require('passport'),
9 9
10 passport.use(new KakaoStrategy({ 10 passport.use(new KakaoStrategy({
11 clientID : 'bd2e610396fb7bbb84cf91a786b3cc72', 11 clientID : 'bd2e610396fb7bbb84cf91a786b3cc72',
12 - callbackURL :'/auth/login/kakao/callback' 12 + callbackURL :'/auth/login/kakao/callback',
13 - // clientSecret : 'eUtJGtlLoCZJufevp3LKfDP0KOtZUV7R' 13 + clientSecret : 'eUtJGtlLoCZJufevp3LKfDP0KOtZUV7R'
14 }, 14 },
15 function(accessToken, refreshToken,params, profile, done){ 15 function(accessToken, refreshToken,params, profile, done){
16 //사용자 정보는 profile에 16 //사용자 정보는 profile에
...@@ -41,8 +41,11 @@ router.get('/auth/login/kakao/callback', ...@@ -41,8 +41,11 @@ router.get('/auth/login/kakao/callback',
41 ); 41 );
42 42
43 function loginByThirdparty(accessToken, refreshToken, profile) { 43 function loginByThirdparty(accessToken, refreshToken, profile) {
44 - var stmt_duplicated = 'INSERT INTO user(id) VALUES(?) ON DUPLICATE KEY UPDATE id=?;' 44 + //예전 코드는 MySQL 버젼이 맞지 않음
45 - connection.query(stmt_duplicated, [profile._json.id] , function (err, result) { 45 + // var sql = 'INSERT INTO `user`(id) VALUES(?) ON DUPLICATE KEY(PRIMARY) UPDATE id=(?);'
46 + var sql = "INSERT INTO `user` (id) VALUES (?) ON DUPLICATE KEY UPDATE id=id";
47 + var kid=[profile._json.id];
48 + connection.query(sql,kid,function(err,result){
46 if (err) { 49 if (err) {
47 console.log("로그인 쿼리중 에러 : " + err); 50 console.log("로그인 쿼리중 에러 : " + err);
48 } else { 51 } else {
...@@ -59,7 +62,7 @@ router.get('/auth/logout/kakao',function (req,res) { ...@@ -59,7 +62,7 @@ router.get('/auth/logout/kakao',function (req,res) {
59 allWebtoons = new Array(); 62 allWebtoons = new Array();
60 63
61 function getLatestToon(titleid, day ,cb) { 64 function getLatestToon(titleid, day ,cb) {
62 - var url = "http://comic.naver.com/webtoon/list.nhn?titleId=" + titleid+ "&weekday="+day; 65 + /*var url = "http://comic.naver.com/webtoon/list.nhn?titleId=" + titleid+ "&weekday="+day;
63 console.log(url); 66 console.log(url);
64 request(url, function (err, res, html) { 67 request(url, function (err, res, html) {
65 if (!err) { 68 if (!err) {
...@@ -88,7 +91,7 @@ function getLatestToon(titleid, day ,cb) { ...@@ -88,7 +91,7 @@ function getLatestToon(titleid, day ,cb) {
88 console.log("최신화 못가져왔습니다."); 91 console.log("최신화 못가져왔습니다.");
89 //throw err; 92 //throw err;
90 } 93 }
91 - }); 94 + });*/
92 } 95 }
93 96
94 function getAllToons() { 97 function getAllToons() {
...@@ -150,7 +153,7 @@ function getAllToons() { ...@@ -150,7 +153,7 @@ function getAllToons() {
150 var list = data["data"]; 153 var list = data["data"];
151 154
152 list.forEach(function(item, idx){ 155 list.forEach(function(item, idx){
153 - console.log(item.id + ' ' + item.title + ' ' + wed); 156 +
154 var webtoon_link='http://webtoon.daum.net/webtoon/view/'+item.nickname.toString(); 157 var webtoon_link='http://webtoon.daum.net/webtoon/view/'+item.nickname.toString();
155 var webtoon= { 158 var webtoon= {
156 toon_index: item.id, 159 toon_index: item.id,
...@@ -279,23 +282,30 @@ function getAllToons() { ...@@ -279,23 +282,30 @@ function getAllToons() {
279 site : site, 282 site : site,
280 latest : 0 283 latest : 0
281 }; 284 };
282 -
283 allWebtoonList.push(webtoon); 285 allWebtoonList.push(webtoon);
284 }); 286 });
285 p.then(function() { 287 p.then(function() {
286 i = 0; 288 i = 0;
287 allWebtoonList.forEach(function (webtoon) { 289 allWebtoonList.forEach(function (webtoon) {
288 - getLatestToon(webtoon.toon_index, webtoon.week, function (latest_toon) { 290 + // getLatestToon(webtoon.toon_index, webtoon.week, function (latest_toon) {
289 - webtoon.latest = latest_toon.latest; 291 + // webtoon.latest = latest_toon.latest;
290 - console.log(i + " = " + webtoon.name + " : " + webtoon.latest) 292 + //i++;
291 - i++; 293 + //console.log(i + " = " + webtoon.name + " : " + webtoon.latest);
292 - connection.query("INSERT INTO toon SET ? ON DUPLICATE KEY UPDATE latest=?", 294 + var sql= "INSERT INTO `toon` (toon_index, name, thum_link, webtoon_link, week, site, latest) VALUES(?) ON DUPLICATE KEY UPDATE latest=latest";
293 - [webtoon,webtoon.latest], function () { 295 + var values=[webtoon.toon_index, webtoon.name, webtoon.thum_link, webtoon.webtoon_link,webtoon.week, webtoon.site, webtoon.latest];
294 - if(err){ 296 + connection.query(sql,[values],function(err,result){
295 - console.log("웹툰 갱신중 에러!"); 297 + if (err) {
296 - } 298 + console.log("웹툰 DB 에러 : " + err);
299 + } else {
300 + console.log("웹툰 DB처리 완료!");
301 + }
302 + //[webtoon,webtoon.latest], function () {
303 + // if (err) {
304 + // console.log("웹툰 갱신중 에러!");
305 + //}
306 + // }
297 }); 307 });
298 - }); 308 + //});
299 }) 309 })
300 }); 310 });
301 } 311 }
......
...@@ -33,7 +33,11 @@ function getUpdatedToons(cb){ ...@@ -33,7 +33,11 @@ function getUpdatedToons(cb){
33 } 33 }
34 34
35 function getMyToons(id,cb){ 35 function getMyToons(id,cb){
36 - var sqlquery = 'SELECT name, thum_link, webtoon_link, week, last, latest, t.toon_index AS toon_index FROM user u, user_toon_relation ur, toon t WHERE u.id=? && u.id=ur.user_id && t.toon_index=ur.toon_index;'; 36 + //var sql = "INSERT INTO `user` (id) VALUES (?)";
37 + //var kid=[profile._json.id];
38 + //connection.query(sql,kid,function(err,result){
39 + var sqlquery = "SELECT name, thum_link, webtoon_link, week, last, t.toon_index AS toon_index FROM user u, user_toon_relation ur, toon t WHERE u.id=? && u.id=ur.user_id && t.toon_index=ur.toon_index;";
40 + //var sqlquery = "SELECT name, thum_link, webtoon_link, week, last, latest, t.toon_index AS toon_index FROM user u, user_toon_relation ur, toon t WHERE u.id=? && u.id=ur.user_id && t.toon_index=ur.toon_index;";
37 var mylist = new Array(); 41 var mylist = new Array();
38 connection.query(sqlquery,id,function(err,rows,result){ 42 connection.query(sqlquery,id,function(err,rows,result){
39 if(!err){ 43 if(!err){
......