From 4971682b6731ada742652d3548dff926b88bb183 Mon Sep 17 00:00:00 2001 From: junv Date: Fri, 19 Jul 2013 00:49:53 +0800 Subject: [PATCH] add google calendar support,half of the functionalities has been done --- api/controllers/AuthController.js | 9 +++------ assets/js/message.js | 26 ++++++++++++++++++++++++++ config/routes.js | 4 ++++ views/message/view.ejs | 2 ++ 4 files changed, 35 insertions(+), 6 deletions(-) diff --git a/api/controllers/AuthController.js b/api/controllers/AuthController.js index 603dc35..6c25b92 100644 --- a/api/controllers/AuthController.js +++ b/api/controllers/AuthController.js @@ -1,11 +1,9 @@ var passport = require('passport'); var GoogleStrategy = require('passport-google-oauth').OAuth2Strategy; -var gcal = require('google-calendar'); -var util = require('util'); passport.use(new GoogleStrategy({ - clientID: '553555458366-bl2e989fn88t27recf2cgp74b3ogcdc1.apps.googleusercontent.com', - clientSecret: '8TNPb5ehq-t7g1uiwztaHmC7', + clientID: process.env.CLIENT_ID, + clientSecret: process.env.CLIENT_SECRET, callbackURL: "http://127.0.0.1:1337/auth/google" },function(accessToken, refreshToken, profile, done) { @@ -32,8 +30,7 @@ passport.deserializeUser(function (obj, done) { var AuthController = { - index: passport.authenticate('google', { scope: ['https://www.googleapis.com/auth/userinfo.profile', - 'https://www.googleapis.com/auth/userinfo.email'] }), + index: passport.authenticate('google', { scope: ['openid', 'email', 'https://www.googleapis.com/auth/calendar'] }), auth: passport.authenticate('google',function(req,res){ diff --git a/assets/js/message.js b/assets/js/message.js index 75a36de..685fc04 100644 --- a/assets/js/message.js +++ b/assets/js/message.js @@ -150,4 +150,30 @@ $(document).ready(function () { }); }, interval * 3 - 1000 * 30); + setTimeout(function () { + $.get('/calendar', function (json) { + console.log(json); + var calendarContainer = $('.calendar-content'); + for (var i = 0; i < json.length; i++) { + var item = $('
  • '); + + var footprint = $('
    ').addClass('footprint'); + footprint.append('

    '+json[i].location+'

    '); + footprint.append('
    ' + json[i].creator.displayName + '发布于' + timeSince(new Date(json[i].created)) + '
    '); + item.append(footprint); + var content = $('
    '); +// if (json[i].original_pic !== undefined) { +// content.append(''); +// } + content.append('

    ' + json[i].summary + '

    '); + item.append(content); + calendarContainer.append(item); + + } + + slideDiv(calendarContainer, textMessageCount); + + }); + }, interval * 4 - 1000 * 30); + }); \ No newline at end of file diff --git a/config/routes.js b/config/routes.js index 0b5fe64..1fa0326 100644 --- a/config/routes.js +++ b/config/routes.js @@ -69,6 +69,10 @@ module.exports.routes = { 'get /auth/google': { controller: 'auth', action: 'auth' + }, + 'get /calendar': { + controller: 'calendar', + action: 'index' } diff --git a/views/message/view.ejs b/views/message/view.ejs index 82576f2..38b3552 100644 --- a/views/message/view.ejs +++ b/views/message/view.ejs @@ -15,4 +15,6 @@ +