From 2abcb419488e14ba9615ef9a69cfda7d7eb9c0f5 Mon Sep 17 00:00:00 2001 From: sam1360 Date: Tue, 28 Mar 2017 18:28:20 -0400 Subject: [PATCH 01/14] added gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0a3676b --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules/* +.DS_Store \ No newline at end of file From 61422842661940421a390fcb2cc5a7a408711390 Mon Sep 17 00:00:00 2001 From: sam1360 Date: Tue, 28 Mar 2017 19:50:35 -0400 Subject: [PATCH 02/14] Minor code style changes --- .eslintignore | 6 ++++++ .eslintrc.json | 11 +++++++++++ lib/citationGeneration.js | 1 - package.json | 7 ++++++- routes/v01/citation.js | 2 +- routes/v01/index.js | 8 ++++---- 6 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 .eslintignore create mode 100644 .eslintrc.json diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..12666b7 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,6 @@ +/docs/* +/node_modules/* +/utils/array.js +**/*.md +**/*.json +**/*.conf diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..d97e805 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,11 @@ +{ + "extends": "airbnb-base", + "plugins": [ + "import" + ], + "rules": { + "max-len": "off", + "brace-style": ["error", "stroustrup"], + "no-unused-vars": ["error", { "args": "none" }] + } +} diff --git a/lib/citationGeneration.js b/lib/citationGeneration.js index ce9a253..976b21f 100644 --- a/lib/citationGeneration.js +++ b/lib/citationGeneration.js @@ -10,7 +10,6 @@ let CitationCore = require('citation-core'); */ exports.generate = function(req, res) { let siteToCite = req.body; - console.log(CitationCore); let formatOptions = new CitationCore.FormatOptions(); formatOptions.url = siteToCite.url; formatOptions.style = CitationCore.styles[siteToCite.style]; diff --git a/package.json b/package.json index 10688ed..720c397 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,12 @@ "dependencies": { "body-parser": "^1.17.0", "citation-core": "^1.0.1", - "eslint": "^3.17.1", "express": "^4.15.0" + }, + "devDependencies": { + "eslint": "^3.13.1", + "eslint-config-airbnb-base": "^11.0.1", + "eslint-plugin-import": "^2.2.0", + "mocha": "^3.2.0" } } diff --git a/routes/v01/citation.js b/routes/v01/citation.js index 71f5ca5..a9b973f 100644 --- a/routes/v01/citation.js +++ b/routes/v01/citation.js @@ -4,7 +4,7 @@ var express = require('express'); var router = express.Router(); var citations = require('../../lib/citationGeneration'); -router.get('/', function(req, res) { +router.get('/', (req, res) => { res.send('Citation web server api'); }); diff --git a/routes/v01/index.js b/routes/v01/index.js index 1953a4f..2e559e8 100644 --- a/routes/v01/index.js +++ b/routes/v01/index.js @@ -7,12 +7,12 @@ router.use('/citation', require('./citation')); // used so Angular may be able to log out by // simply destroying the token -router.get('/', function(req, res) { +router.get('/', (req, res) => { res.send('Citation System API'); -}) +}); -router.get('/about', function(req, res) { +router.get('/about', (req, res) => { res.send('api.SoftwareCitationTools.com'); -}) +}); module.exports = router; From be586ecca3f283a7ee5486ee236633c856ee2dd0 Mon Sep 17 00:00:00 2001 From: sam1360 Date: Tue, 28 Mar 2017 19:54:37 -0400 Subject: [PATCH 03/14] more minor changes --- app.js | 1 + lib/citationGeneration.js | 15 ++++++--------- routes/v01/citation.js | 7 +++---- routes/v01/index.js | 9 +++------ 4 files changed, 13 insertions(+), 19 deletions(-) diff --git a/app.js b/app.js index e42e58b..efd6b01 100644 --- a/app.js +++ b/app.js @@ -1,3 +1,4 @@ + var express = require('express') // call express var app = express() // define our app using express var bodyParser = require('body-parser') diff --git a/lib/citationGeneration.js b/lib/citationGeneration.js index 976b21f..e1618cd 100644 --- a/lib/citationGeneration.js +++ b/lib/citationGeneration.js @@ -1,19 +1,16 @@ -"use strict"; -let express = require('express'); -let CitationCore = require('citation-core'); + +const CitationCore = require('citation-core'); /** * Consumes the citation from the user and passes it to CitationCore. * @param JSON req Passes in the string of the website to be cited, as well as the citation type. * @param String res String that is passed back to the website and displayed to the user. * @return String the string that is returned. */ -exports.generate = function(req, res) { - let siteToCite = req.body; - let formatOptions = new CitationCore.FormatOptions(); +exports.generate = (req, res) => { + const siteToCite = req.body; + const formatOptions = new CitationCore.FormatOptions(); formatOptions.url = siteToCite.url; formatOptions.style = CitationCore.styles[siteToCite.style]; - CitationCore.generate(formatOptions, (citationStr, errors) => { - return res.send({"citation": citationStr}); - }); + CitationCore.generate(formatOptions, (citationStr, errors) => res.send({ citation: citationStr })); }; diff --git a/routes/v01/citation.js b/routes/v01/citation.js index a9b973f..f90703f 100644 --- a/routes/v01/citation.js +++ b/routes/v01/citation.js @@ -1,8 +1,7 @@ -"use strict"; +const express = require('express'); +const citations = require('../../lib/citationGeneration'); -var express = require('express'); -var router = express.Router(); -var citations = require('../../lib/citationGeneration'); +const router = express.Router(); router.get('/', (req, res) => { res.send('Citation web server api'); diff --git a/routes/v01/index.js b/routes/v01/index.js index 2e559e8..cbd7e72 100644 --- a/routes/v01/index.js +++ b/routes/v01/index.js @@ -1,11 +1,8 @@ -var express = require('express'); -var router = express.Router(); +const express = require('express'); -router.use('/citation', require('./citation')); +const router = express.Router(); -// This may not be needed. Sessions are not -// used so Angular may be able to log out by -// simply destroying the token +router.use('/citation', require('./citation')); router.get('/', (req, res) => { res.send('Citation System API'); From fd0afad065aa1f496aedf90c8a3c8ae01b012e32 Mon Sep 17 00:00:00 2001 From: sam1360 Date: Wed, 12 Apr 2017 20:49:54 -0400 Subject: [PATCH 04/14] Style changes to the code and touched up package.json --- package.json | 7 ------- public/js/httpController.js | 16 ++++------------ 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/package.json b/package.json index 57f3664..759072d 100644 --- a/package.json +++ b/package.json @@ -34,20 +34,13 @@ "citation-core": "^1.0.1", "express": "^4.15.0" }, -<<<<<<< HEAD - "devDependencies": { -======= "devDependencies": { ->>>>>>> 407cb05fd532df00c2de80d4dff97e632f68d267 "eslint": "^3.13.1", "eslint-config-airbnb-base": "^11.0.1", "eslint-plugin-import": "^2.2.0", "mocha": "^3.2.0" -<<<<<<< HEAD -======= }, "engines": { "node": "6.10.0" ->>>>>>> 407cb05fd532df00c2de80d4dff97e632f68d267 } } diff --git a/public/js/httpController.js b/public/js/httpController.js index 0e749b9..91ac2da 100644 --- a/public/js/httpController.js +++ b/public/js/httpController.js @@ -1,11 +1,8 @@ function replaceCitation(msg, error) { - let $citationOutput, - $citationMsg; - - $citationOutput = $('#citationOutput'); - $citationMsg = $citationOutput.children('.panel-body'); + const $citationOutput = $('#citationOutput'); + const $citationMsg = $citationOutput.children('.panel-body'); if (error) { $citationMsg.addClass('error'); @@ -26,20 +23,15 @@ function replaceCitation(msg, error) { } function getCitation(window) { - let data, - url; - - url = 'https://boiling-lake-36327.herokuapp.com/v01/citation/'; - console.log(url); + const url = 'https://boiling-lake-36327.herokuapp.com/v01/citation/'; - data = { + const data = { style: $('#citationFormat').val(), url: $('#citationUrl').val(), }; $.post(url, data) .done((returnData) => { - console.log(returnData); replaceCitation(returnData.citation); }) .fail((jqxhr, status, err) => { From 98cd67041a71a24e473a6fb1676abaedafa1cbbe Mon Sep 17 00:00:00 2001 From: sam1360 Date: Wed, 12 Apr 2017 22:47:10 -0400 Subject: [PATCH 05/14] Added oauthToken and did some cleanup with jslint --- lib/citationGeneration.js | 1 + public/js/httpController.js | 18 +++++++++--------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/citationGeneration.js b/lib/citationGeneration.js index 0d0c7e7..3ce476d 100644 --- a/lib/citationGeneration.js +++ b/lib/citationGeneration.js @@ -11,5 +11,6 @@ exports.generate = (req, res) => { const formatOptions = new CitationCore.FormatOptions(); formatOptions.url = siteToCite.url; formatOptions.style = CitationCore.styles[siteToCite.style]; + formatOptions.oauthToken = siteToCite.oauthToken; CitationCore.generate(formatOptions, (citationStr, errors) => res.send({ citation: citationStr })); }; diff --git a/public/js/httpController.js b/public/js/httpController.js index 0432fd1..f6846f1 100644 --- a/public/js/httpController.js +++ b/public/js/httpController.js @@ -24,15 +24,15 @@ function replaceCitation(msg, error) { function getCitation() { - var data = { - style: $('#citationFormat').val(), - url: $('#citationUrl').val() - } - - $.post(window.location.href.slice(0, window.location.href.indexOf('?')) + '/v01/citation/', data) - .done(function (returnData) { - console.log(returnData); - replaceCitation(returnData.citation); + const data = { + style: $('#citationFormat').val(), + url: $('#citationUrl').val(), + }; + + $.post(`${window.location.href.slice(0, window.location.href.indexOf('?'))}/v01/citation/`, data) + .done((returnData) => { + console.log(returnData); + replaceCitation(returnData.citation); }) .fail((jqxhr, status, err) => { console.error(`Error (HTTP status code )${status}): ${err}`); From 79909bcfa3bc549688f74721b86f08bd3029a77e Mon Sep 17 00:00:00 2001 From: sam1360 Date: Wed, 12 Apr 2017 23:57:56 -0400 Subject: [PATCH 06/14] ****NOT WORKING****added github secret route and partially added github token --- .eslintrc.json | 3 ++- lib/github.js | 58 ++++++++++++++++++++++++++++++++++++++++++++ routes/v01/github.js | 0 3 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 lib/github.js create mode 100644 routes/v01/github.js diff --git a/.eslintrc.json b/.eslintrc.json index 246aded..8e42858 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -10,6 +10,7 @@ }, "env": { "node": true, - "jquery": true + "jquery": true, + "browser": true } } diff --git a/lib/github.js b/lib/github.js new file mode 100644 index 0000000..8889b6e --- /dev/null +++ b/lib/github.js @@ -0,0 +1,58 @@ +const config = require('../config.json') +const crypto = require('crypto'); +const + +/** + * Generates the secret that is optional for github + * @param {JSON} req The values that are sent in from the server + * @param {JSON} res The secret value that is returned from the server to be sent to github. + */ +exports.generateSecret = (req, res) => { + const clientIp = req.connection.remoteAddress; + const clientId = req.body.clientId; + const salt = config.salt; + const hash = crypto.createHash('md5').update(clientIp + clientId + salt).digest('hex'); + res.send({"secret": hash}); +}; + +exports.getAccessToken = (req, res) => { + const temporaryCode = req.body.code; + const secret = req.body.secret; + + const postData = querystring.stringify({ + 'client_id': config.client_id, + 'client_secret': config.client_secret, + 'code': temporaryCode, + 'state': secret + }); + + const options = { + hostname: 'https://github.com/', + path: 'login/oauth/access_token', + method: 'POST', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + 'Content-Length': Buffer.byteLength(postData) + } + }; + + const req = http.request(options, (res) => { + console.log(`STATUS: ${res.statusCode}`); + console.log(`HEADERS: ${JSON.stringify(res.headers)}`); + res.setEncoding('utf8'); + res.on('data', (chunk) => { + console.log(`BODY: ${chunk}`); + }); + res.on('end', () => { + console.log('No more data in response.'); + }); + }); + + req.on('error', (e) => { + console.error(`problem with request: ${e.message}`); + }); + + // write data to request body + req.write(postData); + req.end(); +}; \ No newline at end of file diff --git a/routes/v01/github.js b/routes/v01/github.js new file mode 100644 index 0000000..e69de29 From cdcaed9d7da6e4725f2ae53cf22fab09b98fae1a Mon Sep 17 00:00:00 2001 From: sam1360 Date: Tue, 2 May 2017 19:02:06 -0400 Subject: [PATCH 07/14] Small change in package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d7d3d48..4abe345 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "homepage": "https://github.com/sam1360/citation-web-server#readme", "dependencies": { "body-parser": "^1.17.0", - "citation-core": "1.1.0", + "citation-core": "^1.1.0", "express": "^4.15.0", "request": "^2.81.0" }, From b39c84a97fe39c53b14d0d28bf6b7e216fdb4c41 Mon Sep 17 00:00:00 2001 From: sam1360 Date: Tue, 2 May 2017 19:03:54 -0400 Subject: [PATCH 08/14] updated version number --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4abe345..ae8293e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "citation-web-server", - "version": "0.0.2", + "version": "0.0.3", "description": "The node based server for the software citation tools.", "main": "index.js", "directories": { From 5356793e608b15d589454301e515e24981378cd7 Mon Sep 17 00:00:00 2001 From: sam1360 Date: Tue, 2 May 2017 19:54:52 -0400 Subject: [PATCH 09/14] changes to make server to properly run on heroku --- app.js | 2 +- lib/citationGeneration.js | 2 ++ lib/github.js | 9 +++++---- package.json | 4 ++-- public/js/httpController.js | 4 +++- 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/app.js b/app.js index 7406525..1c57dcf 100644 --- a/app.js +++ b/app.js @@ -1,5 +1,4 @@ - const express = require('express'); // call express const bodyParser = require('body-parser'); @@ -14,6 +13,7 @@ const path = require('path'); app.use(bodyParser.urlencoded({ extended: true })); app.use(bodyParser.json()); + // REGISTER OUR ROUTES ------------------------------- // all of our version 01 routes will be prefixed with /v01 app.use('/v01', require('./routes/v01')); diff --git a/lib/citationGeneration.js b/lib/citationGeneration.js index 1f72963..23e83ee 100644 --- a/lib/citationGeneration.js +++ b/lib/citationGeneration.js @@ -7,11 +7,13 @@ const CitationCore = require('citation-core'); * @param String res String that is passed back to the website and displayed to the user. * @return String the string that is returned. */ + exports.generate = (req, res) => { const siteToCite = req.body; const formatOptions = new CitationCore.FormatOptions(); formatOptions.url = siteToCite.url; formatOptions.style = CitationCore.styles[siteToCite.style]; + formatOptions.token = siteToCite.token; console.log(formatOptions.token); CitationCore.generate(formatOptions, (citationStr, errors) => res.send({ citation: citationStr })); diff --git a/lib/github.js b/lib/github.js index 215f2c7..70287d3 100644 --- a/lib/github.js +++ b/lib/github.js @@ -1,5 +1,4 @@ -const config = require('../config.json'); const crypto = require('crypto'); const request = require('request'); @@ -11,7 +10,8 @@ const request = require('request'); exports.generateSecret = (req, res) => { console.log('generateing a secret'); const clientId = req.body.clientId; - const salt = config.salt; + //If running locally create a config file that has the salt. + const salt = process.env.salt; const data = clientId + salt; console.log(data); const hash = crypto.createHash('md5').update(data).digest('hex'); @@ -21,12 +21,13 @@ exports.generateSecret = (req, res) => { exports.getAccessToken = (req, res) => { const temporaryCode = req.body.code; const secret = req.body.secret; + //If running locally add a config with client_id and a client secret const options = { uri: 'https://github.com/login/oauth/access_token', method: 'POST', json: { - client_id: config.client_id || process.env.client_id, - client_secret: config.client_secret || process.env.client_secret, + client_id: process.env.client_id, + client_secret: process.env.client_secret, code: temporaryCode, state: secret }, }; diff --git a/package.json b/package.json index d7d3d48..ae8293e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "citation-web-server", - "version": "0.0.2", + "version": "0.0.3", "description": "The node based server for the software citation tools.", "main": "index.js", "directories": { @@ -31,7 +31,7 @@ "homepage": "https://github.com/sam1360/citation-web-server#readme", "dependencies": { "body-parser": "^1.17.0", - "citation-core": "1.1.0", + "citation-core": "^1.1.0", "express": "^4.15.0", "request": "^2.81.0" }, diff --git a/public/js/httpController.js b/public/js/httpController.js index 7e71ff2..32275a5 100644 --- a/public/js/httpController.js +++ b/public/js/httpController.js @@ -1,6 +1,7 @@ -const GITHUB_CLIENT_ID = '2c034c1c587df515c7d9'; +const GITHUB_CLIENT_ID = '92ead414d69dd0f9ef84'; + const urlParams = new Map(window.location.search.slice(1).split('&').map(e => [e.split('=')[0], e.split('=')[1]])); function replaceCitation(msg, error) { @@ -85,6 +86,7 @@ function getGitHubToken() { }); } + function getCitation() { let authToken; const src = $('#citationUrl').val(); From d75bd048c11cfeb36e8090df14ea93ec9fb8104d Mon Sep 17 00:00:00 2001 From: sam1360 Date: Tue, 9 May 2017 23:15:52 -0400 Subject: [PATCH 10/14] Fix to make it so the cookie wont be overwritten --- public/js/httpController.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/public/js/httpController.js b/public/js/httpController.js index 32275a5..b19f6ef 100644 --- a/public/js/httpController.js +++ b/public/js/httpController.js @@ -1,6 +1,8 @@ -const GITHUB_CLIENT_ID = '92ead414d69dd0f9ef84'; +// const GITHUB_CLIENT_ID = '92ead414d69dd0f9ef84'; +const GITHUB_CLIENT_ID = '7ee065082a2f0242619f'; + const urlParams = new Map(window.location.search.slice(1).split('&').map(e => [e.split('=')[0], e.split('=')[1]])); @@ -110,7 +112,10 @@ function getCitation() { url: src, }; - $.post(`${window.location.href.slice(0, window.location.href.indexOf('?'))}v01/citation/`, data) + const citationUrl = window.location.protocol+ "//" + window.location.hostname + "/v01/citation"; + + + $.post(citationUrl, data) .done((returnData) => { if (returnData.citation) { replaceCitation(returnData.citation); @@ -136,5 +141,12 @@ $('#citeBtn').click((evt) => { }); if (urlParams.has('code')) { - getGitHubToken(); + if(~document.cookie.indexOf('gitHubToken=')){ + + } + else{ + getGitHubToken(); + } } + + From 763367f2aa3ecae78e118024fa3c6d224ae469a3 Mon Sep 17 00:00:00 2001 From: sam1360 Date: Tue, 9 May 2017 23:15:52 -0400 Subject: [PATCH 11/14] Fix to make it so the cookie wont be overwritten --- public/js/httpController.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/public/js/httpController.js b/public/js/httpController.js index 32275a5..f471d84 100644 --- a/public/js/httpController.js +++ b/public/js/httpController.js @@ -110,7 +110,10 @@ function getCitation() { url: src, }; - $.post(`${window.location.href.slice(0, window.location.href.indexOf('?'))}v01/citation/`, data) + const citationUrl = window.location.protocol+ "//" + window.location.hostname + "/v01/citation"; + + + $.post(citationUrl, data) .done((returnData) => { if (returnData.citation) { replaceCitation(returnData.citation); @@ -136,5 +139,12 @@ $('#citeBtn').click((evt) => { }); if (urlParams.has('code')) { - getGitHubToken(); + if(~document.cookie.indexOf('gitHubToken=')){ + + } + else{ + getGitHubToken(); + } } + + From dd27280efcc01f09c7482e2676b01239250f3b1f Mon Sep 17 00:00:00 2001 From: sam1360 Date: Tue, 9 May 2017 23:20:44 -0400 Subject: [PATCH 12/14] client id change --- public/js/httpController.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/public/js/httpController.js b/public/js/httpController.js index b19f6ef..f471d84 100644 --- a/public/js/httpController.js +++ b/public/js/httpController.js @@ -1,8 +1,6 @@ -// const GITHUB_CLIENT_ID = '92ead414d69dd0f9ef84'; -const GITHUB_CLIENT_ID = '7ee065082a2f0242619f'; - +const GITHUB_CLIENT_ID = '92ead414d69dd0f9ef84'; const urlParams = new Map(window.location.search.slice(1).split('&').map(e => [e.split('=')[0], e.split('=')[1]])); From c6c2122ab30ac95a622574472e1f901859c6f8fd Mon Sep 17 00:00:00 2001 From: sam1360 Date: Wed, 10 May 2017 12:50:25 -0400 Subject: [PATCH 13/14] Fix formatting for pr. --- public/js/httpController.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/public/js/httpController.js b/public/js/httpController.js index f471d84..42b7360 100644 --- a/public/js/httpController.js +++ b/public/js/httpController.js @@ -110,7 +110,7 @@ function getCitation() { url: src, }; - const citationUrl = window.location.protocol+ "//" + window.location.hostname + "/v01/citation"; + const citationUrl = window.location.protocol + "//" + window.location.hostname + "/v01/citation"; $.post(citationUrl, data) @@ -139,10 +139,10 @@ $('#citeBtn').click((evt) => { }); if (urlParams.has('code')) { - if(~document.cookie.indexOf('gitHubToken=')){ + if (~document.cookie.indexOf('gitHubToken=')) { } - else{ + else { getGitHubToken(); } } From ea0fefc2aaf2a92f1a29907abfece495b0d15ead Mon Sep 17 00:00:00 2001 From: sam1360 Date: Thu, 11 May 2017 15:21:36 -0400 Subject: [PATCH 14/14] Updated the citation core --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 687fa22..69d1abd 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "homepage": "https://github.com/sam1360/citation-web-server#readme", "dependencies": { "body-parser": "^1.17.0", - "citation-core": "^1.1.1", + "citation-core": "^1.2.0", "express": "^4.15.0", "request": "^2.81.0" },