유희정

navigating pages and extract events

...@@ -8,7 +8,7 @@ var session = require('express-session'); ...@@ -8,7 +8,7 @@ var session = require('express-session');
8 var index = require('./routes/index'); 8 var index = require('./routes/index');
9 var users = require('./routes/users'); 9 var users = require('./routes/users');
10 var calendar = require('./routes/calendar'); 10 var calendar = require('./routes/calendar');
11 -var login = require('./routes/login'); 11 +var events = require('./routes/events');
12 12
13 passport.serializeUser(function(user,done) { 13 passport.serializeUser(function(user,done) {
14 console.log('serialized'); 14 console.log('serialized');
...@@ -43,7 +43,7 @@ app.use(passport.session()); ...@@ -43,7 +43,7 @@ app.use(passport.session());
43 app.use('/', index); 43 app.use('/', index);
44 app.use('/users', users); 44 app.use('/users', users);
45 app.use('/calendar',calendar); 45 app.use('/calendar',calendar);
46 -app.use('/login',login); 46 +app.use('/events',events);
47 47
48 // catch 404 and forward to error handler 48 // catch 404 and forward to error handler
49 app.use(function(req, res, next) { 49 app.use(function(req, res, next) {
......
1 var express = require('express'); 1 var express = require('express');
2 var router = express.Router(); 2 var router = express.Router();
3 +var gcal = require('google-calendar');
3 4
4 router.post('/calendar',function(req,res,next){ 5 router.post('/calendar',function(req,res,next){
5 var id = req.body.id; 6 var id = req.body.id;
6 res.render('calendar',{id: id}); 7 res.render('calendar',{id: id});
7 }); 8 });
8 -router.get('/',function(req,res,next){ 9 +//router.get('/',function(req,res,next){
9 //var accessToken = req.session.access_token; 10 //var accessToken = req.session.access_token;
10 //gcal(accessToken).calendarList.list(function(err,data){ 11 //gcal(accessToken).calendarList.list(function(err,data){
11 //if(err) return res.send(err); 12 //if(err) return res.send(err);
...@@ -13,7 +14,27 @@ router.get('/',function(req,res,next){ ...@@ -13,7 +14,27 @@ router.get('/',function(req,res,next){
13 //}); 14 //});
14 //res.render('calendar',{id:1}); 15 //res.render('calendar',{id:1});
15 console.log(1); 16 console.log(1);
16 -}) 17 +//})
18 +
19 +calList = new Array();
20 +
21 +router.get('/', function(req, res, next) {
22 + if(!req.session.access_token) return res.redirect('/auth/google');
23 + else
24 + var accessToken = req.session.access_token;
25 + //getAllcalendarID(accessToken);
26 + //console.log(calList);
27 + //getAllCalendars(accessToken);
28 + //console.log(Calendars);
29 + gcal(accessToken).calendarList.list(function(err,data){
30 + if(err) return console.log(err);
31 + else {
32 + calList = data.items;
33 + //console.log(calList);
34 + res.render('calendar',{calList:calList,accessToken:accessToken});
35 + }
36 + });
37 +});
17 38
18 39
19 module.exports = router; 40 module.exports = router;
......
1 +var express = require('express');
2 +var router = express.Router();
3 +var gcal = require('google-calendar');
4 +
5 +router.post('/', function(req, res, next) {
6 + var accessToken = req.body.token;
7 + var id = req.body.id;
8 + gcal(accessToken).events.list(id,{maxResult:1},function(err,data){
9 + if(err) return console.log(err);
10 + else {
11 + console.log(data.items[0].start);
12 + res.render("events",{id:id,calendars:data.items});
13 + }
14 + });
15 +});
16 +
17 +
18 +module.exports = router;
19 +
20 +//db에서 calendar id에 해당하는 이벤트 출력
...\ No newline at end of file ...\ No newline at end of file
...@@ -23,27 +23,15 @@ function(accessToken,refreshToken,params,profile,done){ ...@@ -23,27 +23,15 @@ function(accessToken,refreshToken,params,profile,done){
23 23
24 router.get('/auth/google',passport.authenticate('google',{ session:false})); 24 router.get('/auth/google',passport.authenticate('google',{ session:false}));
25 router.get('/auth/google/callback',passport.authenticate('google',{ 25 router.get('/auth/google/callback',passport.authenticate('google',{
26 - failureRedirect:'/login' 26 + failureRedirect:'/'
27 }),function(req, res) { 27 }),function(req, res) {
28 req.session.access_token = req.user.accessToken; 28 req.session.access_token = req.user.accessToken;
29 - res.redirect('/login'); 29 + res.redirect('/calendar');
30 }); 30 });
31 31
32 calList = new Array(); 32 calList = new Array();
33 Calendars = new Array(); 33 Calendars = new Array();
34 34
35 -/* GET home page. */
36 -router.get('/login', function(req, res, next) {
37 - if(!req.session.access_token) return res.redirect('/auth/google');
38 -
39 - var accessToken = req.session.access_token;
40 - getAllcalendarID(accessToken);
41 - //console.log(calList);
42 - //getAllCalendars(accessToken);
43 - //console.log(Calendars);
44 - res.redirect('/');
45 -});
46 -
47 router.get('/',function(req,res,next){ 35 router.get('/',function(req,res,next){
48 res.render('index',{title:'Reminder-Talk'}); 36 res.render('index',{title:'Reminder-Talk'});
49 }); 37 });
...@@ -55,42 +43,6 @@ router.get('/logout', function(req, res) { ...@@ -55,42 +43,6 @@ router.get('/logout', function(req, res) {
55 }); 43 });
56 44
57 45
58 -
59 -function getAllcalendarID(accessToken){
60 - gcal(accessToken).calendarList.list(function(err,data){
61 - if(err) return console.log(err);
62 - //console.log(data.items);
63 - data.items.forEach(element => {
64 - var cid = element.id;
65 - calList.push(cid);
66 - getAllCalendars(accessToken,cid);
67 - });
68 - });
69 -};
70 -var a = function(){
71 - console.log(Calendars);
72 -}
73 -function getAllCalendars(accessToken,id){
74 - gcal(accessToken).events.list(id,{maxResult:1},function(err,data){
75 - if(err) return console.log(err);
76 - for(var i =0 ; i< data.items.length;i++){
77 - var cal = new Object();
78 - cal.cid = id;
79 - cal.id = data.items[i].id;
80 - cal.summary = data.items[i].summary;
81 - cal.start = data.items[i].start;
82 - cal.end = data.items[i].end;
83 - console.log(cal);
84 - Calendars.push(cal);
85 - }
86 - })
87 -}
88 -
89 -
90 -
91 -
92 -
93 -
94 module.exports = router; 46 module.exports = router;
95 47
96 //db에 id 별 이벤트 저장하고 calendar page 에서 출력해주자! 48 //db에 id 별 이벤트 저장하고 calendar page 에서 출력해주자!
......
1 -var express = require('express');
2 -var router = express.Router();
3 -//router.use(bodyParser.urlencoded({ extended: false }));
4 -//router.use(bodyParser.json());
5 -
6 -
7 -
8 -router.get('/',function(req,res){
9 - res.render()
10 -})
11 -
12 -
13 -module.exports = router;
...\ No newline at end of file ...\ No newline at end of file
1 -<h1><% calList.forEach(function(dat) { %>
2 - <li><%dat%></li>
3 - <% }); %> </h1>
...\ No newline at end of file ...\ No newline at end of file
1 +<!DOCTYPE html>
2 +<html>
3 + <head>
4 + <link rel='stylesheet' href='/stylesheets/style.css' />
5 +
6 + </head>
7 + <body>
8 + <h1>캘린더 ID</h1>
9 + <p>
10 + <form action="/events" method="POST">
11 + <input type=hidden name="token" value=<%= accessToken %> >
12 + <% calList.forEach(function(val){ %>
13 + <input type=submit name="id" value=<%= val.id %> >
14 + <% }) %>
15 + </form>
16 + </p>
17 + </body>
18 +</html>
...\ No newline at end of file ...\ No newline at end of file
......
1 +<!DOCTYPE html>
2 +<html>
3 + <head>
4 + <link rel='stylesheet' href='/stylesheets/style.css' />
5 +
6 + </head>
7 + <body>
8 + <h1><%= id %></h1>
9 + <p>
10 + <% calendars.forEach(function(val){ %>
11 + <li>summary : <%= val.summary %></li>
12 + <li>created : <%= val.created %></li>
13 + <li>start : <%= val.start.dateTime %></li>
14 + <li>end : <%= val.end.dateTime %></li>
15 + <% }) %>
16 + </p>
17 + </body>
18 +</html>
...\ No newline at end of file ...\ No newline at end of file
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
8 <body> 8 <body>
9 <h1><%= title %></h1> 9 <h1><%= title %></h1>
10 <p>Welcome to <%= title %></p> 10 <p>Welcome to <%= title %></p>
11 - <form action='/login' method='GET'> 11 + <form action='/auth/google' method='GET'>
12 <input type="submit" name='submit' value='로그인'/> 12 <input type="submit" name='submit' value='로그인'/>
13 </form> 13 </form>
14 </body> 14 </body>
......