diff --git a/.gitignore b/.gitignore index cfd50c6..fb4a2e7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ hackathon.sublime-project hackathon.sublime-workspace -node_modules \ No newline at end of file +node_modules +.sass-cache/ +**/.DS_Store diff --git a/README.md b/README.md new file mode 100644 index 0000000..606e571 --- /dev/null +++ b/README.md @@ -0,0 +1,25 @@ +An step by step live demo to explain how the Oauth2 dance works in the ORCID API and how to use the access tokens to edit an ORCID record. + +#### Install NodeJS + +[Install it!](https://nodejs.org/) + +### Install Gulp + +``` +sudo npm install --global gulp +``` + +### Install dependencies + +``` +npm install +``` + +### Run gulp, includes express web server + +``` +gulp +``` + +Source JavaScript and SCSS files are under /src folder, do not modify files that are in the root (/CSS and /JS) diff --git a/css/style.min.css b/css/style.min.css deleted file mode 100644 index e42e402..0000000 --- a/css/style.min.css +++ /dev/null @@ -1 +0,0 @@ -body{color:#494A4C;font-family:'Gill Sans W02',Helvetica,sans-serif}h1,h2,h3{color:#a6ce39}label,p,ul{font-size:18px}table{margin:40px 20px;background-color:#fff;border-radius:16px;box-shadow:0 0 5px #999}td{padding:16px;color:#9B9B9B;font-size:1.2em}tr{border-bottom:1px solid #d2d2d2;vertical-align:center}.api-chart img{width:64px}.api-chart h3{text-transform:uppercase}tr:last-of-type{border-bottom:none}.btn-default{background:#338caf;color:#FFF;border:none}.btn-default:hover{background:#a6ce39;color:#FFF;border:none}.wizard-btn-container{text-align:right;position:absolute;left:15px;right:15px;bottom:15px;border-top:1px solid #d2d2d2;padding-top:15px}.wizard-btn-container .wizard-nav-btn,.wizard-btn-container .wizard-nav-btn:hover,.wizard-btn-container input[type=submit],.wizard-btn-container input[type=submit]:hover{background:#f3f3f3;border:none;background-image:linear-gradient(#fbfbfb,#f3f3f3);border:1px solid rgba(0,0,0,.1);border-radius:2px;box-shadow:0 1px 1px rgba(0,0,0,.1);margin-left:15px;margin-right:0;height:30px;color:#444;display:inline-block;font-weight:700;margin-bottom:0;padding:4px 12px;text-decoration:none;text-shadow:none}.wizard-btn-container .wizard-nav-btn.disabled-button,.wizard-btn-container .wizard-nav-btn.disabled-button:hover,.wizard-btn-container input[type=submit].disabled-button,.wizard-btn-container input[type=submit].disabled-button:hover{background-color:#e4e4e4;background-image:linear-gradient(#e8e8e8,#e4e4e4);color:#c2c2c2;border-radius:2px;box-shadow:none}.steps-pane-container{border:none;float:left;min-width:15%;width:auto;height:100vh;box-sizing:border-box;background:#FFF;border-right:1px solid #d2d2d2}.steps-pane-container ul{list-style:none;padding:0;margin:0}.steps-pane-container ul li{border-bottom:1px solid #d2d2d2;text-shadow:none;cursor:default;padding:15px;color:#9b9b9b;position:relative;font-size:18px}.steps-pane-container ul li.current-step{text-shadow:none;background:#338caf;border-color:#a6ce39;border-style:none solid none none;border-width:5px;color:#FFF;font-weight:700}.steps-pane-container ul li.completed-step{color:#777;text-shadow:none}.steps-pane-container ul li.clickable-step-link{cursor:pointer}.steps-pane-container ul li.clickable-step-link:hover{color:#333}.steps-pane-container .logo{width:100%;text-align:left;padding:6px 0 0 15px;height:60px;border-bottom:1px solid #d2d2d2}.wizard-ext-container{overflow:hidden;box-sizing:border-box;box-shadow:0 0 4px rgba(0,0,0,.3)}.contents-pane-container{float:left;padding:15px;min-width:85%;width:auto;height:100vh;position:relative;box-sizing:border-box;background:#F8F8F8;border:none}.contents-pane{overflow:auto;position:absolute;left:15px;right:15px;top:15px;bottom:61px;border:none;padding-left:2px}.hidden-form-slide{display:none}.disabled-button{color:rgba(0,0,0,.3)} \ No newline at end of file diff --git a/gulpfile.js b/gulpfile.js index 7f86980..94d04c8 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -9,27 +9,47 @@ var gulp = require('gulp'), cache = require('gulp-cache'), livereload = require('gulp-livereload'), plumber = require('gulp-plumber'); + +// run livereload +gulp.task('livereload', function() { + tinylr = require('tiny-lr')(); + tinylr.listen(35729); +}); + +function notifyLiveReload(event) { + var fileName = require('path').relative(__dirname, event.path); + + tinylr.changed({ + body: { + files: [fileName] + } + }); +} + +// Styles gulp task gulp.task('styles', function () { return (sass('./src/scss')) .on('error', function (err) { console.log(err.message); }) .pipe(plumber()) + .pipe(gulp.dest('./public/css')) .pipe(rename({ suffix: '.min' })) .pipe(minifycss()) - .pipe(gulp.dest('./css')) + .pipe(gulp.dest('./public/css')) .pipe(notify({ message: 'Styles task complete' })); }); + // Scripts gulp.task('scripts', function() { return gulp.src('./src/js/*.js') .pipe(plumber()) .pipe(concat('app.js')) - .pipe(gulp.dest('./js')) + .pipe(gulp.dest('./public/js')) .pipe(rename({ suffix: '.min' })) .pipe(uglify()) - .pipe(gulp.dest('./js')) + .pipe(gulp.dest('./public/js')) .pipe(notify({ message: 'Custom Scripts task complete' })); }); @@ -38,10 +58,23 @@ gulp.task('scripts', function() { gulp.task('watch', function() { gulp.watch('./src/scss/*.scss', ['styles']); gulp.watch('./src/js/*.js', ['scripts']); + gulp.watch('./js/*', notifyLiveReload); + gulp.watch('./public/*', notifyLiveReload); }); + +// run express +gulp.task('express', function() { + var express = require('express'); + var app = express(); + app.use(require('connect-livereload')({port: 35729})); + app.use(express.static(__dirname + '/public')); + app.listen(8000); +}); + + // Default task -gulp.task('default', ['watch'], function() { +gulp.task('default', ['express','livereload','watch'], function() { gulp.start('styles','scripts'); }); diff --git a/js/.DS_Store b/js/.DS_Store deleted file mode 100644 index 5008ddf..0000000 Binary files a/js/.DS_Store and /dev/null differ diff --git a/js/app.min.js b/js/app.min.js deleted file mode 100644 index fd22121..0000000 --- a/js/app.min.js +++ /dev/null @@ -1 +0,0 @@ -var wizardNgModule=angular.module("wizardApp",["ngCookies","ngResource"]).config(["$locationProvider","$resourceProvider",function(e,o){e.html5Mode(!0),o.defaults.stripTrailingSlashes=!0}]);wizardNgModule.controller("stepsController",["$scope","wizardSrvc","$location",function(e,o,t){e.steps=[{title:"Introduction"},{title:"Accessing the API"},{title:"Technologies"},{title:"Get access token"},{title:"Get token"},{title:"Show token"},{title:"Read record"},{title:"Update record"}],e.init=function(){var o=t.search().code;void 0===o||null===o?console.log("Nothing here"):e.wizardSrvc.current=4},e.wizardSrvc=o,e.init()}]),wizardNgModule.controller("controlsController",["$scope","wizardSrvc",function(e,o){e.wizardSrvc=o,e.next=function(){o.next()},e.finish=function(){o.finish()},e.back=function(){o.back()}}]),wizardNgModule.controller("authorizationCodeController",["$scope","$cookies","wizardSrvc",function(e,o,t){"localhost"==location.hostname&&(e.form={},e.form.client_id="APP-1X454QYQ66U6XW7X"),e.authString="http://[api_url]/oauth/authorize?client_id=[client_id]&response_type=code&redirect_uri=[redirect_uri]&scope=[scope]",e.wizardSrvc=t,e.getAuthorizationCode=function(){var t=e.authString;t=t.replace("[api_url]","sandbox.orcid.org"),t=t.replace("[client_id]",e.form.client_id),t=t.replace("[redirect_uri]","http://"+location.hostname+":8000"),t=t.replace("[scope]",e.form.scope),console.log(t),o.put("current",e.wizardSrvc.current),o.put("orcid_oauth2_client_id",e.form.client_id),o.put("orcid_oauth2_redirect_uri","http://"+location.hostname+":8000"),setTimeout(function(){window.location.href=t},125)}}]),wizardNgModule.controller("tokenController",["$scope","$location","$cookies","$http",function(e,o,t,c){e.show_access_token=!1,e.expires_in=!1,e.name=!1,e.orcid=!1,e.scope=!1,e.token_type=!1,"localhost"==location.hostname&&(e.client_secret="8fa38bea-48e2-4238-9479-e55448ffa225"),e.access_code=null,e.client_id=null,e.getCode=function(){e.access_code=o.search().code,e.client_id=t.get("orcid_oauth2_client_id"),(void 0===e.access_code||null===e.access_code)&&o.path("/")},e.exchangeCode=function(){c({url:"http://pub.sandbox.orcid.org/oauth/token",method:"post",headers:{"Content-Type":"application/x-www-form-urlencoded",Accept:"application/json"},transformRequest:function(e){var o=[];for(var t in e)o.push(encodeURIComponent(t)+"="+encodeURIComponent(e[t]));var c=o.join("&");return console.log("****RETURNING "+c),c},data:{client_id:e.client_id,client_secret:e.client_secret,grant_type:"authorization_code",redirect_uri:"http://localhost:8000",code:e.access_code}}).success(function(o){e.wizardSrvc.current=5,e.token=o}).error(function(e,o,t,c){console.log("***OOPS "+o+" H: "+angular.toJson(e))})},e.show=function(o){switch(e.show_access_token=!1,e.show_expires_in=!1,e.show_name=!1,e.show_orcid=!1,e.show_scope=!1,e.show_token_type=!1,console.log(o),o){case"token":e.show_access_token=!0;break;case"expiration":e.show_expires_in=!0;break;case"name":e.show_name=!0;break;case"orcid":e.show_orcid=!0;break;case"scope":e.show_scope=!0;break;case"type":e.show_token_type=!0}},e.getCode()}]),wizardNgModule.service("wizardSrvc",["$rootScope",function(e){var o={current:0,elements:document.getElementsByClassName("step"),back:function(){o.current>0&&o.current--},next:function(){o.current==o.elements.length-1?o.current=0:o.current++},finish:function(){o.current=0}};return o}]); \ No newline at end of file diff --git a/package.json b/package.json index 50bab7c..8d1cfbb 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,12 @@ "gulp-uglify": "^1.2.0", "gulp-jshint": "^1.10.0" }, - "devDependencies": {}, + "devDependencies": { + "connect-livereload": "^0.5.3", + "express": "^4.12.4", + "gulp": "^3.8.11", + "tiny-lr": "^0.1.5" + }, "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, diff --git a/css/fonts.min.css b/public/css/fonts.min.css similarity index 100% rename from css/fonts.min.css rename to public/css/fonts.min.css diff --git a/public/css/style.min.css b/public/css/style.min.css new file mode 100644 index 0000000..ec3d9b8 --- /dev/null +++ b/public/css/style.min.css @@ -0,0 +1 @@ +body{color:#494A4C;font-family:'Gill Sans W02',Helvetica,sans-serif}h1,h2,h3{color:#a6ce39}label,ol,p,ul{font-size:18px}table{margin:40px 20px;background-color:#fff;border-radius:16px;box-shadow:0 0 5px #999}td{padding:16px;color:#9B9B9B;font-size:1.2em}tr{border-bottom:1px solid #d2d2d2;vertical-align:center}.api-chart img{width:64px}.api-chart h3{text-transform:uppercase}tr:last-of-type{border-bottom:none}.btn-default{background:#338caf;color:#FFF;border:none}.btn-default:hover{background:#a6ce39;color:#FFF;border:none}.wizard-btn-container{text-align:right;position:absolute;left:15px;right:15px;bottom:15px;border-top:1px solid #d2d2d2;padding-top:15px}.wizard-btn-container .wizard-nav-btn,.wizard-btn-container .wizard-nav-btn:hover,.wizard-btn-container input[type=submit],.wizard-btn-container input[type=submit]:hover{background:#f3f3f3;border:none;background-image:linear-gradient(#fbfbfb,#f3f3f3);border:1px solid rgba(0,0,0,.1);border-radius:2px;box-shadow:0 1px 1px rgba(0,0,0,.1);margin-left:15px;margin-right:0;height:30px;color:#444;display:inline-block;font-weight:700;margin-bottom:0;padding:4px 12px;text-decoration:none;text-shadow:none}.wizard-btn-container .wizard-nav-btn.disabled-button,.wizard-btn-container .wizard-nav-btn.disabled-button:hover,.wizard-btn-container input[type=submit].disabled-button,.wizard-btn-container input[type=submit].disabled-button:hover{background-color:#e4e4e4;background-image:linear-gradient(#e8e8e8,#e4e4e4);color:#c2c2c2;border-radius:2px;box-shadow:none}.steps-pane-container{border:none;float:left;min-width:15%;width:auto;height:100vh;box-sizing:border-box;background:#FFF;border-right:1px solid #d2d2d2}.steps-pane-container ul{list-style:none;padding:0;margin:0}.steps-pane-container ul li{border-bottom:1px solid #d2d2d2;text-shadow:none;cursor:default;padding:15px;color:#9b9b9b;position:relative;font-size:18px}.steps-pane-container ul li.current-step{text-shadow:none;background:#338caf;border-color:#a6ce39;border-style:none solid none none;border-width:5px;color:#FFF;font-weight:700}.steps-pane-container ul li.completed-step{color:#777;text-shadow:none}.steps-pane-container ul li.clickable-step-link{cursor:pointer}.steps-pane-container ul li.clickable-step-link:hover{color:#333}.steps-pane-container .logo{width:100%;text-align:left;padding:6px 0 0 15px;height:60px;border-bottom:1px solid #d2d2d2}.wizard-ext-container{overflow:hidden;box-sizing:border-box;box-shadow:0 0 4px rgba(0,0,0,.3)}.contents-pane-container{float:left;padding:15px;min-width:85%;width:auto;height:100vh;position:relative;box-sizing:border-box;background:#F8F8F8;border:none}.contents-pane{overflow:auto;position:absolute;left:15px;right:15px;top:15px;bottom:61px;border:none;padding-left:2px}.hidden-form-slide{display:none}.disabled-button{color:rgba(0,0,0,.3)}.token_items pre{background-color:#fff;overflow:hidden}.token_items,.token_items a{width:60%;float:left;margin:0;padding:0;outline:0}.token_items a:hover,.token_items a:visited{text-decoration:none}.key,.value{float:left}.token_items_descriptions{width:20%;margin-left:20px;margin-top:60px}.token_items_descriptions,p.description{padding:0;float:left} \ No newline at end of file diff --git a/fonts/28878a98-b041-4ebc-a448-f6d4b50c87b2.ttf b/public/fonts/28878a98-b041-4ebc-a448-f6d4b50c87b2.ttf similarity index 100% rename from fonts/28878a98-b041-4ebc-a448-f6d4b50c87b2.ttf rename to public/fonts/28878a98-b041-4ebc-a448-f6d4b50c87b2.ttf diff --git a/fonts/2b43682c-fbbf-4d2c-aa8f-53c5e9c07b89.woff b/public/fonts/2b43682c-fbbf-4d2c-aa8f-53c5e9c07b89.woff similarity index 100% rename from fonts/2b43682c-fbbf-4d2c-aa8f-53c5e9c07b89.woff rename to public/fonts/2b43682c-fbbf-4d2c-aa8f-53c5e9c07b89.woff diff --git a/fonts/3d3ae305-c5f8-44e9-a93f-68343ef13a1e.eot b/public/fonts/3d3ae305-c5f8-44e9-a93f-68343ef13a1e.eot similarity index 100% rename from fonts/3d3ae305-c5f8-44e9-a93f-68343ef13a1e.eot rename to public/fonts/3d3ae305-c5f8-44e9-a93f-68343ef13a1e.eot diff --git a/fonts/41a107ac-0cb7-4bdf-92fa-3953ffd3624e.woff b/public/fonts/41a107ac-0cb7-4bdf-92fa-3953ffd3624e.woff similarity index 100% rename from fonts/41a107ac-0cb7-4bdf-92fa-3953ffd3624e.woff rename to public/fonts/41a107ac-0cb7-4bdf-92fa-3953ffd3624e.woff diff --git a/fonts/53ead41e-c0ab-44c3-bb7c-74d70d2c7ed7.ttf b/public/fonts/53ead41e-c0ab-44c3-bb7c-74d70d2c7ed7.ttf similarity index 100% rename from fonts/53ead41e-c0ab-44c3-bb7c-74d70d2c7ed7.ttf rename to public/fonts/53ead41e-c0ab-44c3-bb7c-74d70d2c7ed7.ttf diff --git a/fonts/59939f92-3d8b-46f6-8852-3a0db259dea0.svg b/public/fonts/59939f92-3d8b-46f6-8852-3a0db259dea0.svg similarity index 100% rename from fonts/59939f92-3d8b-46f6-8852-3a0db259dea0.svg rename to public/fonts/59939f92-3d8b-46f6-8852-3a0db259dea0.svg diff --git a/fonts/5b426dca-cc4e-4627-9ff8-9f4dc55b0290.woff b/public/fonts/5b426dca-cc4e-4627-9ff8-9f4dc55b0290.woff similarity index 100% rename from fonts/5b426dca-cc4e-4627-9ff8-9f4dc55b0290.woff rename to public/fonts/5b426dca-cc4e-4627-9ff8-9f4dc55b0290.woff diff --git a/fonts/782849e5-a129-4cc1-8fa5-934ae2a82537.svg b/public/fonts/782849e5-a129-4cc1-8fa5-934ae2a82537.svg similarity index 100% rename from fonts/782849e5-a129-4cc1-8fa5-934ae2a82537.svg rename to public/fonts/782849e5-a129-4cc1-8fa5-934ae2a82537.svg diff --git a/fonts/7bf70546-8c62-412f-9a7f-ea4d750a97b9.svg b/public/fonts/7bf70546-8c62-412f-9a7f-ea4d750a97b9.svg similarity index 100% rename from fonts/7bf70546-8c62-412f-9a7f-ea4d750a97b9.svg rename to public/fonts/7bf70546-8c62-412f-9a7f-ea4d750a97b9.svg diff --git a/fonts/a02a57aa-1a49-4b8c-ab1d-08fbd790aabe.woff b/public/fonts/a02a57aa-1a49-4b8c-ab1d-08fbd790aabe.woff similarity index 100% rename from fonts/a02a57aa-1a49-4b8c-ab1d-08fbd790aabe.woff rename to public/fonts/a02a57aa-1a49-4b8c-ab1d-08fbd790aabe.woff diff --git a/fonts/a4c5f6d1-f02d-4144-aadf-10f97a718263.eot b/public/fonts/a4c5f6d1-f02d-4144-aadf-10f97a718263.eot similarity index 100% rename from fonts/a4c5f6d1-f02d-4144-aadf-10f97a718263.eot rename to public/fonts/a4c5f6d1-f02d-4144-aadf-10f97a718263.eot diff --git a/fonts/b88d89de-e476-4fd9-83a7-15f1178d78bd.eot b/public/fonts/b88d89de-e476-4fd9-83a7-15f1178d78bd.eot similarity index 100% rename from fonts/b88d89de-e476-4fd9-83a7-15f1178d78bd.eot rename to public/fonts/b88d89de-e476-4fd9-83a7-15f1178d78bd.eot diff --git a/fonts/c7502fea-5840-46ed-9666-3479a56bf828.ttf b/public/fonts/c7502fea-5840-46ed-9666-3479a56bf828.ttf similarity index 100% rename from fonts/c7502fea-5840-46ed-9666-3479a56bf828.ttf rename to public/fonts/c7502fea-5840-46ed-9666-3479a56bf828.ttf diff --git a/fonts/cba5f716-e0e3-43b2-accd-b5f4173e4695.svg b/public/fonts/cba5f716-e0e3-43b2-accd-b5f4173e4695.svg similarity index 100% rename from fonts/cba5f716-e0e3-43b2-accd-b5f4173e4695.svg rename to public/fonts/cba5f716-e0e3-43b2-accd-b5f4173e4695.svg diff --git a/fonts/da53b951-50dc-4a3c-a55a-932bdde8347e.ttf b/public/fonts/da53b951-50dc-4a3c-a55a-932bdde8347e.ttf similarity index 100% rename from fonts/da53b951-50dc-4a3c-a55a-932bdde8347e.ttf rename to public/fonts/da53b951-50dc-4a3c-a55a-932bdde8347e.ttf diff --git a/fonts/df888e01-3d42-4e4a-bbb8-7b8bbd7d55f0.eot b/public/fonts/df888e01-3d42-4e4a-bbb8-7b8bbd7d55f0.eot similarity index 100% rename from fonts/df888e01-3d42-4e4a-bbb8-7b8bbd7d55f0.eot rename to public/fonts/df888e01-3d42-4e4a-bbb8-7b8bbd7d55f0.eot diff --git a/fonts/ecb83bdf-e0aa-4a30-9394-c5a32be731ff.woff b/public/fonts/ecb83bdf-e0aa-4a30-9394-c5a32be731ff.woff similarity index 100% rename from fonts/ecb83bdf-e0aa-4a30-9394-c5a32be731ff.woff rename to public/fonts/ecb83bdf-e0aa-4a30-9394-c5a32be731ff.woff diff --git a/fonts/f317c23c-bff8-4972-b8d3-db5a0da45fdf.svg b/public/fonts/f317c23c-bff8-4972-b8d3-db5a0da45fdf.svg similarity index 100% rename from fonts/f317c23c-bff8-4972-b8d3-db5a0da45fdf.svg rename to public/fonts/f317c23c-bff8-4972-b8d3-db5a0da45fdf.svg diff --git a/fonts/f54382aa-da70-46c5-bb6f-735919625300.ttf b/public/fonts/f54382aa-da70-46c5-bb6f-735919625300.ttf similarity index 100% rename from fonts/f54382aa-da70-46c5-bb6f-735919625300.ttf rename to public/fonts/f54382aa-da70-46c5-bb6f-735919625300.ttf diff --git a/fonts/f5eeb9ee-aa7f-48ee-8450-4034d3587f6d.eot b/public/fonts/f5eeb9ee-aa7f-48ee-8450-4034d3587f6d.eot similarity index 100% rename from fonts/f5eeb9ee-aa7f-48ee-8450-4034d3587f6d.eot rename to public/fonts/f5eeb9ee-aa7f-48ee-8450-4034d3587f6d.eot diff --git a/img/ID_symbol.svg b/public/img/ID_symbol.svg similarity index 100% rename from img/ID_symbol.svg rename to public/img/ID_symbol.svg diff --git a/img/glyphicons-28-search-A6CE39.svg b/public/img/glyphicons-28-search-A6CE39.svg similarity index 100% rename from img/glyphicons-28-search-A6CE39.svg rename to public/img/glyphicons-28-search-A6CE39.svg diff --git a/img/glyphicons-31-pencil-A6CE39.svg b/public/img/glyphicons-31-pencil-A6CE39.svg similarity index 100% rename from img/glyphicons-31-pencil-A6CE39.svg rename to public/img/glyphicons-31-pencil-A6CE39.svg diff --git a/img/glyphicons-365-cloud-upload-A6CE39.svg b/public/img/glyphicons-365-cloud-upload-A6CE39.svg similarity index 100% rename from img/glyphicons-365-cloud-upload-A6CE39.svg rename to public/img/glyphicons-365-cloud-upload-A6CE39.svg diff --git a/img/glyphicons-433-plus-A6CE39.svg b/public/img/glyphicons-433-plus-A6CE39.svg similarity index 100% rename from img/glyphicons-433-plus-A6CE39.svg rename to public/img/glyphicons-433-plus-A6CE39.svg diff --git a/img/glyphicons-52-eye-open-A6CE39.svg b/public/img/glyphicons-52-eye-open-A6CE39.svg similarity index 100% rename from img/glyphicons-52-eye-open-A6CE39.svg rename to public/img/glyphicons-52-eye-open-A6CE39.svg diff --git a/img/glyphicons-86-repeat-A6CE39.svg b/public/img/glyphicons-86-repeat-A6CE39.svg similarity index 100% rename from img/glyphicons-86-repeat-A6CE39.svg rename to public/img/glyphicons-86-repeat-A6CE39.svg diff --git a/img/id-logo.png b/public/img/id-logo.png similarity index 100% rename from img/id-logo.png rename to public/img/id-logo.png diff --git a/img/orcid-logo.png b/public/img/orcid-logo.png similarity index 100% rename from img/orcid-logo.png rename to public/img/orcid-logo.png diff --git a/index.html b/public/index.html similarity index 100% rename from index.html rename to public/index.html diff --git a/js/app.js b/public/js/app.js similarity index 86% rename from js/app.js rename to public/js/app.js index 15f79de..97469d4 100644 --- a/js/app.js +++ b/public/js/app.js @@ -8,7 +8,7 @@ wizardNgModule.controller('stepsController', ['$scope','wizardSrvc','$location', $scope.steps = [ {'title' : 'Introduction'}, {'title' : 'Accessing the API'}, - {'title' : 'Technologies'}, + {'title' : 'Using the API'}, {'title' : 'Get access token'}, {'title' : 'Get token'}, {'title' : 'Show token'}, @@ -18,9 +18,12 @@ wizardNgModule.controller('stepsController', ['$scope','wizardSrvc','$location', $scope.init = function() { var code = $location.search()['code']; + if (code === undefined || code === null) { console.log('Nothing here'); } else { + //strip extra characters from code + code = code.substr(0,6); $scope.wizardSrvc.current = 4; } } @@ -64,12 +67,13 @@ wizardNgModule.controller('authorizationCodeController', ['$scope','$cookies', ' apiUri = apiUri.replace('[api_url]', 'sandbox.orcid.org'); apiUri = apiUri.replace('[client_id]', $scope.form.client_id); apiUri = apiUri.replace('[redirect_uri]', 'http://' + location.hostname + ':8000'); - apiUri = apiUri.replace('[scope]', $scope.form.scope); + apiUri = apiUri.replace('[scope]', '/activities/read-limited /activities/update /orcid-profile/read-limited'); console.log(apiUri); // Save values in cookies so we can use them later - $cookies.put('current', $scope.wizardSrvc.current); //Current Wizard location + //Current Wizard location + $cookies.put('current', $scope.wizardSrvc.current); $cookies.put('orcid_oauth2_client_id', $scope.form.client_id); $cookies.put('orcid_oauth2_redirect_uri', 'http://' + location.hostname+ ':8000'); @@ -79,8 +83,6 @@ wizardNgModule.controller('authorizationCodeController', ['$scope','$cookies', ' }, 125); }; - - }]); wizardNgModule.controller('tokenController', ['$scope','$location', '$cookies', '$http', function($scope, $location, $cookies, $http){ @@ -91,33 +93,38 @@ wizardNgModule.controller('tokenController', ['$scope','$location', '$cookies', $scope.orcid=false; $scope.scope=false; $scope.token_type=false; - - /* THIS CONTROLLER NEEDS TO BE UPDATED */ - + $scope.access_token=null; + $scope.user_orcid=null; + $scope.access_code = null; + $scope.client_id = null; + $scope.show_xml=false; + /* Only for dev environment */ if (location.hostname == 'localhost'){ $scope.client_secret = '8fa38bea-48e2-4238-9479-e55448ffa225'; } - - $scope.access_code = null; - $scope.client_id = null; - + $scope.getCode = function() { + $scope.access_code = $location.search()['code']; $scope.client_id = $cookies.get('orcid_oauth2_client_id'); // If the code is not specified, return the view // to the root view if ($scope.access_code === undefined || $scope.access_code === null) { $location.path("/"); + } else{ + //strip extra characters from code + var rawCode = $location.search()['code']; + $scope.access_code = rawCode.substr(0,6); } }; - $scope.exchangeCode = function() { + $scope.exchangeCode = function() { $http({ url:'http://pub.sandbox.orcid.org/oauth/token', method:'post', headers: {'Content-Type': 'application/x-www-form-urlencoded', - 'Accept': 'application/json', + 'Accept': 'application/json' }, transformRequest: function(obj) { var str = []; @@ -137,6 +144,8 @@ wizardNgModule.controller('tokenController', ['$scope','$location', '$cookies', .success (function(data){ $scope.wizardSrvc.current = 5; $scope.token = data; + $scope.access_token = data.access_token; + $scope.user_orcid = data.orcid; }) .error(function(data, status, headers, config){ console.log("***OOPS "+status + " H: "+ angular.toJson(data)); @@ -157,7 +166,7 @@ wizardNgModule.controller('tokenController', ['$scope','$location', '$cookies', break; case 'expiration': $scope.show_expires_in=true; - break; + break; case 'name': $scope.show_name=true; break; @@ -173,7 +182,44 @@ wizardNgModule.controller('tokenController', ['$scope','$location', '$cookies', } }; + + + + + + + + + + + + + + + + + $scope.readRecord = function() { + $scope.show_xml=true; + }; + + + + + + + + + + + + + + + + + + $scope.getCode(); }]); diff --git a/public/js/app.min.js b/public/js/app.min.js new file mode 100644 index 0000000..18f7300 --- /dev/null +++ b/public/js/app.min.js @@ -0,0 +1 @@ +var wizardNgModule=angular.module("wizardApp",["ngCookies","ngResource"]).config(["$locationProvider","$resourceProvider",function(e,o){e.html5Mode(!0),o.defaults.stripTrailingSlashes=!0}]);wizardNgModule.controller("stepsController",["$scope","wizardSrvc","$location",function(e,o,t){e.steps=[{title:"Introduction"},{title:"Accessing the API"},{title:"Using the API"},{title:"Get access token"},{title:"Get token"},{title:"Show token"},{title:"Read record"},{title:"Update record"}],e.init=function(){var o=t.search().code;void 0===o||null===o?console.log("Nothing here"):(o=o.substr(0,6),e.wizardSrvc.current=4)},e.wizardSrvc=o,e.init()}]),wizardNgModule.controller("controlsController",["$scope","wizardSrvc",function(e,o){e.wizardSrvc=o,e.next=function(){o.next()},e.finish=function(){o.finish()},e.back=function(){o.back()}}]),wizardNgModule.controller("authorizationCodeController",["$scope","$cookies","wizardSrvc",function(e,o,t){"localhost"==location.hostname&&(e.form={},e.form.client_id="APP-1X454QYQ66U6XW7X"),e.authString="http://[api_url]/oauth/authorize?client_id=[client_id]&response_type=code&redirect_uri=[redirect_uri]&scope=[scope]",e.wizardSrvc=t,e.getAuthorizationCode=function(){var t=e.authString;t=t.replace("[api_url]","sandbox.orcid.org"),t=t.replace("[client_id]",e.form.client_id),t=t.replace("[redirect_uri]","http://"+location.hostname+":8000"),t=t.replace("[scope]","/activities/read-limited /activities/update /orcid-profile/read-limited"),console.log(t),o.put("current",e.wizardSrvc.current),o.put("orcid_oauth2_client_id",e.form.client_id),o.put("orcid_oauth2_redirect_uri","http://"+location.hostname+":8000"),setTimeout(function(){window.location.href=t},125)}}]),wizardNgModule.controller("tokenController",["$scope","$location","$cookies","$http",function(e,o,t,c){e.show_access_token=!1,e.expires_in=!1,e.name=!1,e.orcid=!1,e.scope=!1,e.token_type=!1,e.access_token=null,e.user_orcid=null,e.access_code=null,e.client_id=null,e.show_xml=!1,"localhost"==location.hostname&&(e.client_secret="8fa38bea-48e2-4238-9479-e55448ffa225"),e.getCode=function(){if(e.access_code=o.search().code,e.client_id=t.get("orcid_oauth2_client_id"),void 0===e.access_code||null===e.access_code)o.path("/");else{var c=o.search().code;e.access_code=c.substr(0,6)}},e.exchangeCode=function(){c({url:"http://pub.sandbox.orcid.org/oauth/token",method:"post",headers:{"Content-Type":"application/x-www-form-urlencoded",Accept:"application/json"},transformRequest:function(e){var o=[];for(var t in e)o.push(encodeURIComponent(t)+"="+encodeURIComponent(e[t]));var c=o.join("&");return console.log("****RETURNING "+c),c},data:{client_id:e.client_id,client_secret:e.client_secret,grant_type:"authorization_code",redirect_uri:"http://localhost:8000",code:e.access_code}}).success(function(o){e.wizardSrvc.current=5,e.token=o,e.access_token=o.access_token,e.user_orcid=o.orcid}).error(function(e,o,t,c){console.log("***OOPS "+o+" H: "+angular.toJson(e))})},e.show=function(o){switch(e.show_access_token=!1,e.show_expires_in=!1,e.show_name=!1,e.show_orcid=!1,e.show_scope=!1,e.show_token_type=!1,console.log(o),o){case"token":e.show_access_token=!0;break;case"expiration":e.show_expires_in=!0;break;case"name":e.show_name=!0;break;case"orcid":e.show_orcid=!0;break;case"scope":e.show_scope=!0;break;case"type":e.show_token_type=!0}},e.readRecord=function(){e.show_xml=!0},e.getCode()}]),wizardNgModule.service("wizardSrvc",["$rootScope",function(e){var o={current:0,elements:document.getElementsByClassName("step"),back:function(){o.current>0&&o.current--},next:function(){o.current==o.elements.length-1?o.current=0:o.current++},finish:function(){o.current=0}};return o}]); \ No newline at end of file diff --git a/js/controllers.js b/public/js/controllers.js similarity index 100% rename from js/controllers.js rename to public/js/controllers.js diff --git a/readme.MD b/readme.MD deleted file mode 100644 index f423756..0000000 --- a/readme.MD +++ /dev/null @@ -1,34 +0,0 @@ -An step by step live demo to explain how the Oauth2 dance works in the ORCID API and how to use the access tokens to edit an ORCID record. - -#### Install NodeJS - -[Install it!](https://nodejs.org/) - -### Install dependencies - -``` -npm install gulp --save-dev -``` - -``` -npm install gulp-ruby-sass gulp-autoprefixer gulp-minify-css gulp-uglify gulp-rename gulp-concat gulp-notify gulp-cache gulp-livereload gulp-plumber --save-dev -``` - -### Run web server - -``` -python3 -m http.server 8000 - -or - -python -m SimpleHTTPServer 8000 - -``` - -### Run gulp - -``` -gulp -``` - -Source JavaScript and SCSS files are under /src folder, do not modify files that are in the root (/CSS and /JS) \ No newline at end of file diff --git a/src/.DS_Store b/src/.DS_Store deleted file mode 100644 index 43353c9..0000000 Binary files a/src/.DS_Store and /dev/null differ