Toggle navigation
Toggle navigation
This project
Loading...
Sign in
유희정
/
Reminder-Talk
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
유희정
2019-11-30 00:28:10 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
ad6fe3096ecff324fd73f81b1a80a7df5e059796
ad6fe309
1 parent
6f54ab7a
navigating pages and extract events
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
85 additions
and
72 deletions
app.js
routes/calendar.js
routes/events.js
routes/index.js
routes/login.js
views/calendar.ejs
views/events.ejs
views/index.ejs
app.js
View file @
ad6fe30
...
...
@@ -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
)
{
...
...
routes/calendar.js
View file @
ad6fe30
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
});
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
;
...
...
routes/events.js
0 → 100644
View file @
ad6fe30
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
routes/index.js
View file @
ad6fe30
...
...
@@ -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 에서 출력해주자!
...
...
routes/login.js
deleted
100644 → 0
View file @
6f54ab7
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
views/calendar.ejs
View file @
ad6fe30
<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
...
...
views/events.ejs
0 → 100644
View file @
ad6fe30
<!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
views/index.ejs
View file @
ad6fe30
...
...
@@ -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>
...
...
Please
register
or
login
to post a comment