유희정

navigating pages and extract events

......@@ -8,7 +8,7 @@ var session = require('express-session');
var index = require('./routes/index');
var users = require('./routes/users');
var calendar = require('./routes/calendar');
var login = require('./routes/login');
var events = require('./routes/events');
passport.serializeUser(function(user,done) {
console.log('serialized');
......@@ -43,7 +43,7 @@ app.use(passport.session());
app.use('/', index);
app.use('/users', users);
app.use('/calendar',calendar);
app.use('/login',login);
app.use('/events',events);
// catch 404 and forward to error handler
app.use(function(req, res, next) {
......
var express = require('express');
var router = express.Router();
var gcal = require('google-calendar');
router.post('/calendar',function(req,res,next){
var id = req.body.id;
res.render('calendar',{id: id});
});
router.get('/',function(req,res,next){
//router.get('/',function(req,res,next){
//var accessToken = req.session.access_token;
//gcal(accessToken).calendarList.list(function(err,data){
//if(err) return res.send(err);
......@@ -13,7 +14,27 @@ router.get('/',function(req,res,next){
//});
//res.render('calendar',{id:1});
console.log(1);
})
//})
calList = new Array();
router.get('/', function(req, res, next) {
if(!req.session.access_token) return res.redirect('/auth/google');
else
var accessToken = req.session.access_token;
//getAllcalendarID(accessToken);
//console.log(calList);
//getAllCalendars(accessToken);
//console.log(Calendars);
gcal(accessToken).calendarList.list(function(err,data){
if(err) return console.log(err);
else {
calList = data.items;
//console.log(calList);
res.render('calendar',{calList:calList,accessToken:accessToken});
}
});
});
module.exports = router;
......
var express = require('express');
var router = express.Router();
var gcal = require('google-calendar');
router.post('/', function(req, res, next) {
var accessToken = req.body.token;
var id = req.body.id;
gcal(accessToken).events.list(id,{maxResult:1},function(err,data){
if(err) return console.log(err);
else {
console.log(data.items[0].start);
res.render("events",{id:id,calendars:data.items});
}
});
});
module.exports = router;
//db에서 calendar id에 해당하는 이벤트 출력
\ No newline at end of file
......@@ -23,27 +23,15 @@ function(accessToken,refreshToken,params,profile,done){
router.get('/auth/google',passport.authenticate('google',{ session:false}));
router.get('/auth/google/callback',passport.authenticate('google',{
failureRedirect:'/login'
failureRedirect:'/'
}),function(req, res) {
req.session.access_token = req.user.accessToken;
res.redirect('/login');
res.redirect('/calendar');
});
calList = new Array();
Calendars = new Array();
/* GET home page. */
router.get('/login', function(req, res, next) {
if(!req.session.access_token) return res.redirect('/auth/google');
var accessToken = req.session.access_token;
getAllcalendarID(accessToken);
//console.log(calList);
//getAllCalendars(accessToken);
//console.log(Calendars);
res.redirect('/');
});
router.get('/',function(req,res,next){
res.render('index',{title:'Reminder-Talk'});
});
......@@ -55,42 +43,6 @@ router.get('/logout', function(req, res) {
});
function getAllcalendarID(accessToken){
gcal(accessToken).calendarList.list(function(err,data){
if(err) return console.log(err);
//console.log(data.items);
data.items.forEach(element => {
var cid = element.id;
calList.push(cid);
getAllCalendars(accessToken,cid);
});
});
};
var a = function(){
console.log(Calendars);
}
function getAllCalendars(accessToken,id){
gcal(accessToken).events.list(id,{maxResult:1},function(err,data){
if(err) return console.log(err);
for(var i =0 ; i< data.items.length;i++){
var cal = new Object();
cal.cid = id;
cal.id = data.items[i].id;
cal.summary = data.items[i].summary;
cal.start = data.items[i].start;
cal.end = data.items[i].end;
console.log(cal);
Calendars.push(cal);
}
})
}
module.exports = router;
//db에 id 별 이벤트 저장하고 calendar page 에서 출력해주자!
......
var express = require('express');
var router = express.Router();
//router.use(bodyParser.urlencoded({ extended: false }));
//router.use(bodyParser.json());
router.get('/',function(req,res){
res.render()
})
module.exports = router;
\ No newline at end of file
<h1><% calList.forEach(function(dat) { %>
<li><%dat%></li>
<% }); %> </h1>
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<link rel='stylesheet' href='/stylesheets/style.css' />
</head>
<body>
<h1>캘린더 ID</h1>
<p>
<form action="/events" method="POST">
<input type=hidden name="token" value=<%= accessToken %> >
<% calList.forEach(function(val){ %>
<input type=submit name="id" value=<%= val.id %> >
<% }) %>
</form>
</p>
</body>
</html>
\ No newline at end of file
......
<!DOCTYPE html>
<html>
<head>
<link rel='stylesheet' href='/stylesheets/style.css' />
</head>
<body>
<h1><%= id %></h1>
<p>
<% calendars.forEach(function(val){ %>
<li>summary : <%= val.summary %></li>
<li>created : <%= val.created %></li>
<li>start : <%= val.start.dateTime %></li>
<li>end : <%= val.end.dateTime %></li>
<% }) %>
</p>
</body>
</html>
\ No newline at end of file
......@@ -8,7 +8,7 @@
<body>
<h1><%= title %></h1>
<p>Welcome to <%= title %></p>
<form action='/login' method='GET'>
<form action='/auth/google' method='GET'>
<input type="submit" name='submit' value='로그인'/>
</form>
</body>
......