diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..eabe228 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..084a924 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/smart-rms-calendar.iml b/.idea/smart-rms-calendar.iml new file mode 100644 index 0000000..24643cc --- /dev/null +++ b/.idea/smart-rms-calendar.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/watcherTasks.xml b/.idea/watcherTasks.xml new file mode 100644 index 0000000..9338ba6 --- /dev/null +++ b/.idea/watcherTasks.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/app/controllers/home.controller.js b/app/controllers/home.controller.js index 3f95fe4..d0e448a 100644 --- a/app/controllers/home.controller.js +++ b/app/controllers/home.controller.js @@ -166,7 +166,7 @@ function oauth2callback(req, res) { res.send(err) res.end() } else { - res.redirect('http://localhost:8000/calendar') + res.redirect('http://localhost:3030/home') } }) } diff --git a/app/lib/index.js b/app/lib/index.js index 3b026b1..45ffebd 100644 --- a/app/lib/index.js +++ b/app/lib/index.js @@ -62,7 +62,7 @@ function storeToken(token, emails) { throw err; } // ** new - Promise.try(function () { }) + Promise.try(function () {}) .then(function () { tokendb.save(function (err, result) { if (err) { @@ -91,18 +91,19 @@ module.exports = { var auth = new googleAuth(); var oauth2Client = new auth.OAuth2(clientId, clientSecret, REDIRECTURL); var setToken = {} // set token from callback - Token.findOne({ email: 'tzbattleboy@gmail.com' }, function (err, token) { - + Token.findOne({ + email: 'tzbattleboy@gmail.com' + }, function (err, token) { if (err) { return callback(null, null, getNewToken(oauth2Client, callback)); } else if (token) { setToken = { - access_token: token.access_token, - refresh_token: token.refresh_token, - token_type: token.token_type, - expiry_date: token.expiry_date - } - // console.log(setToken) + access_token: token.access_token, + refresh_token: token.refresh_token, + token_type: token.token_type, + expiry_date: token.expiry_date + } + // console.log(setToken) oauth2Client.credentials = setToken; return callback(null, oauth2Client); } else { @@ -127,19 +128,28 @@ module.exports = { var auth = new googleAuth(); var oauth2Client = new auth.OAuth2(clientId, clientSecret, REDIRECTURL); - fs.readFile(TOKEN_PATH, (err, token) => { - if (err) { + Token.findOne({ + email: 'tzbattleboy@gmail.com' + }, function (err, token) { + if (token) { + oauth2Client.credentials = JSON.parse(token); + return callback(null, oauth2Client); + } else { oauth2Client.getToken(code, function (err, token) { if (err) { console.log('Error while trying to retrieve access token', err); return; } else { oauth2Client.credentials = token; - var params = { userId: 'me', fields: 'emails', auth: oauth2Client }; + var params = { + userId: 'me', + fields: 'emails', + auth: oauth2Client + }; plus.people.get(params, function (err, response) { if (err) { - consol.error(err) + console.error(err) } else { storeToken(token, response.emails); } @@ -149,11 +159,16 @@ module.exports = { } }) - } else { - oauth2Client.credentials = JSON.parse(token); - return callback(null, oauth2Client); } }); + + // fs.readFile(TOKEN_PATH, (err, token) => { + // if (err) { + + // } else { + + // } + // }); }); }, -- libgit2 0.21.2