diff --git a/README.md b/README.md index 3900667a6..6529500f8 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ![Code Corps Ember Logo](https://d3pgew4wbk2vb1.cloudfront.net/images/github/code-corps-ember.png) -[![CircleCI](https://circleci.com/gh/code-corps/code-corps-ember.svg?style=svg)](https://circleci.com/gh/code-corps/code-corps-ember) [![Dependency Status](https://david-dm.org/code-corps/code-corps-ember.svg)](https://david-dm.org/code-corps/code-corps-ember) [![devDependency Status](https://david-dm.org/code-corps/code-corps-ember/dev-status.svg)](https://david-dm.org/code-corps/code-corps-ember#info=devDependencies) [![Inline docs](http://inch-ci.org/github/code-corps/code-corps-ember.svg?branch=develop&style=shields)](http://inch-ci.org/github/code-corps/code-corps-ember) [![Slack Status](http://slack.codecorps.org/badge.svg)](http://slack.codecorps.org) +[![CircleCI](https://circleci.com/gh/code-corps/code-corps-ember.svg?style=shield)](https://circleci.com/gh/code-corps/code-corps-ember) [![devDependency Status](https://david-dm.org/code-corps/code-corps-ember/dev-status.svg)](https://david-dm.org/code-corps/code-corps-ember#info=devDependencies) [![Inline docs](http://inch-ci.org/github/code-corps/code-corps-ember.svg?branch=develop&style=shields)](http://inch-ci.org/github/code-corps/code-corps-ember) [![Slack Status](http://slack.codecorps.org/badge.svg)](http://slack.codecorps.org) This Code Corps Ember application powers the front-end website for the Code Corps platform, consuming our Elixir JSON API. diff --git a/config/environment.js b/config/environment.js index c9a7fb0b4..96536b347 100644 --- a/config/environment.js +++ b/config/environment.js @@ -84,7 +84,8 @@ module.exports = function(environment) { // ENV.APP.LOG_VIEW_LOOKUPS = true; ENV.API_BASE_URL = 'http://api.lvh.me:49235'; - ENV.SERVER_TOKEN_ENDPOINT = 'http://api.lvh.me:49235/login'; + ENV.SERVER_TOKEN_ENDPOINT = 'http://api.lvh.me:49235/token'; + ENV.SERVER_TOKEN_REFRESH_ENDPOINT = 'http://api.lvh.me:49235/token/refresh'; ENV.WEB_BASE_URL = 'http://localhost:4200'; ENV.sentry.development = true; @@ -93,10 +94,6 @@ module.exports = function(environment) { enabled: false }; - ENV['ember-simple-auth-token'] = { - serverTokenEndpoint: '/login', - } - ENV.contentSecurityPolicy = { 'default-src': "'none'", 'script-src': [ @@ -131,7 +128,8 @@ module.exports = function(environment) { if (environment === 'remote-development') { ENV.API_BASE_URL = 'http://api.pbqrpbecf-qri.org'; - ENV.SERVER_TOKEN_ENDPOINT = 'http://api.pbqrpbecf-qri.org/login'; + ENV.SERVER_TOKEN_ENDPOINT = 'http://api.pbqrpbecf-qri.org/token'; + ENV.SERVER_TOKEN_REFRESH_ENDPOINT = 'http://api.pbqrpbecf-qri.org/token/refresh'; ENV.WEB_BASE_URL = 'http://www.pbqrpbecf-qri.org'; ENV.sentry.development = true; @@ -139,7 +137,8 @@ module.exports = function(environment) { if (environment === 'staging') { ENV.API_BASE_URL = 'http://api.pbqrpbecf.org'; - ENV.SERVER_TOKEN_ENDPOINT = 'http://api.pbqrpbecf.org/login'; + ENV.SERVER_TOKEN_ENDPOINT = 'http://api.pbqrpbecf.org/token'; + ENV.SERVER_TOKEN_REFRESH_ENDPOINT = 'http://api.pbqrpbecf.org/token/refresh'; ENV.WEB_BASE_URL = 'http://www.pbqrpbecf.org'; ENV.sentry.dsn = 'https://c494e4250972401e84b74526fdf1182b@app.getsentry.com/82742'; @@ -157,7 +156,8 @@ module.exports = function(environment) { ENV.APP.rootElement = '#ember-testing'; ENV.API_BASE_URL = ''; - ENV.SERVER_TOKEN_ENDPOINT = '/login'; + ENV.SERVER_TOKEN_ENDPOINT = '/token'; + ENV.SERVER_TOKEN_REFRESH_ENDPOINT = '/token/refresh'; ENV.WEB_BASE_URL = ''; ENV.sentry.development = true; @@ -173,12 +173,16 @@ module.exports = function(environment) { if (environment === 'production') { ENV.API_BASE_URL = 'https://api.codecorps.org'; - ENV.SERVER_TOKEN_ENDPOINT = 'https://api.codecorps.org/login'; + ENV.SERVER_TOKEN_ENDPOINT = 'https://api.codecorps.org/token'; + ENV.SERVER_TOKEN_REFRESH_ENDPOINT = 'https://api.codecorps.org/token/refresh'; ENV.WEB_BASE_URL = 'http://www.codecorps.org'; } ENV['ember-simple-auth-token'] = { serverTokenEndpoint: ENV.SERVER_TOKEN_ENDPOINT, + serverTokenRefreshEndpoint: ENV.SERVER_TOKEN_REFRESH_ENDPOINT, + refreshLeeway: 3000, // 5 minutes before expiry + timeFactor: 1000, }; return ENV; diff --git a/mirage/config.js b/mirage/config.js index 690da8af1..0c30c9bfe 100644 --- a/mirage/config.js +++ b/mirage/config.js @@ -77,7 +77,6 @@ export default function() { // GET /categories this.get('/categories'); - //////////////////////// // Comment user mentions //////////////////////// @@ -92,7 +91,6 @@ export default function() { return schema.commentUserMentions.where({ commentId: commentId }); }); - /////////// // Comments /////////// @@ -123,35 +121,6 @@ export default function() { return comment; }); - - //////// - // Login - //////// - - // POST /login - this.post('/login', (db, request) => { - let json = JSON.parse(request.requestBody); - - if(json.username === "josh@coderly.com" && json.password === "password") { - return { - // token encoded at https://jwt.io/ - token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwYXNzd29yZCI6InBhc3N3b3JkIiwidXNlcm5hbWUiOiJqb3NoQGNvZGVybHkuY29tIiwidXNlcl9pZCI6MSwiZXhwIjo3MjAwfQ.QVDyAznECIWL6DjDs9iPezvMmoPuzDqAl4bQ6CY-fCQ" - }; - } else { - return new Mirage.Response(400, {}, { - errors: [ - { - id: "INVALID_GRANT", - title: "Invalid grant", - detail: "The provided authorization grant is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client.", - status: 401 - } - ] - }); - } - }); - - /////////////////////////// // Organization memberships /////////////////////////// @@ -171,7 +140,6 @@ export default function() { // PATCH /organization-memberships/:id this.patch('/organization-memberships/:id'); - //////////////// // Organizations //////////////// @@ -180,65 +148,6 @@ export default function() { this.get('/organizations/:id'); - - ///////////////////// - // Task user mentions - ///////////////////// - - // GET /task-user-mentions - this.get('/task-user-mentions', (schema, request) => { - let taskId = request.queryParams.task_id; - let task = schema.tasks.find(taskId); - - generateTaskMentions(schema, task); - - return schema.taskUserMentions.where({ taskId: taskId }); - }); - - - //////// - // Tasks - //////// - - // POST /tasks - this.post('/tasks', function(schema) { - let attrs = this.normalizedRequestAttrs(); - - // the API takes takes markdown and renders body - attrs.body = `

${attrs.markdown}

`; - - // the API sets task number as an auto-incrementing value, scoped to project, - // so we need to simulate that here - attrs.number = schema.projects.find(attrs.projectId).tasks.models.length + 1; - - return schema.create('task', attrs); - }); - - // PATCH /tasks/:id - this.patch('/tasks/:id', function(schema) { - let attrs = this.normalizedRequestAttrs(); - - // the API takes takes markdown and renders body - attrs.body = `

${attrs.markdown}

`; - - let task = schema.tasks.find(attrs.id); - task.attrs = attrs; - - task.taskUserMentions.models.forEach((mention) => mention.destroy()); - task.save(); - - return task; - }); - - // GET tasks/:number/comments - this.get('/tasks/:taskId/comments', function(schema, request) { - let taskId = request.params.taskId; - let task = schema.tasks.find(taskId); - - return task.comments; - }); - - /////////// // Previews /////////// @@ -422,11 +331,92 @@ export default function() { // GET /skills/:id this.get('/skills/:id'); + ///////////////////// + // Task user mentions + ///////////////////// + + // GET /task-user-mentions + this.get('/task-user-mentions', (schema, request) => { + let taskId = request.queryParams.task_id; + let task = schema.tasks.find(taskId); + + generateTaskMentions(schema, task); + + return schema.taskUserMentions.where({ taskId: taskId }); + }); //////// - // Users + // Tasks //////// + // POST /tasks + this.post('/tasks', function(schema) { + let attrs = this.normalizedRequestAttrs(); + + // the API takes takes markdown and renders body + attrs.body = `

${attrs.markdown}

`; + + // the API sets task number as an auto-incrementing value, scoped to project, + // so we need to simulate that here + attrs.number = schema.projects.find(attrs.projectId).tasks.models.length + 1; + + return schema.create('task', attrs); + }); + + // PATCH /tasks/:id + this.patch('/tasks/:id', function(schema) { + let attrs = this.normalizedRequestAttrs(); + + // the API takes takes markdown and renders body + attrs.body = `

${attrs.markdown}

`; + + let task = schema.tasks.find(attrs.id); + task.attrs = attrs; + + task.taskUserMentions.models.forEach((mention) => mention.destroy()); + task.save(); + + return task; + }); + + // GET tasks/:number/comments + this.get('/tasks/:taskId/comments', function(schema, request) { + let taskId = request.params.taskId; + let task = schema.tasks.find(taskId); + + return task.comments; + }); + + //////// + // Token + //////// + + // POST /token + this.post('/token', (db, request) => { + let json = JSON.parse(request.requestBody); + + if(json.username === "josh@coderly.com" && json.password === "password") { + return { + // token encoded at https://jwt.io/ + token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwYXNzd29yZCI6InBhc3N3b3JkIiwidXNlcm5hbWUiOiJqb3NoQGNvZGVybHkuY29tIiwidXNlcl9pZCI6MSwiZXhwIjo3MjAwfQ.QVDyAznECIWL6DjDs9iPezvMmoPuzDqAl4bQ6CY-fCQ" + }; + } else { + return new Mirage.Response(400, {}, { + errors: [ + { + id: "INVALID_GRANT", + title: "Invalid grant", + detail: "The provided authorization grant is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client.", + status: 401 + } + ] + }); + } + }); + + //////// + // Users + //////// this.get('/users', { coalesce: true }); @@ -473,7 +463,6 @@ export default function() { return { available: true, valid: true }; }); - ////////////////// // User categories ////////////////// @@ -490,7 +479,6 @@ export default function() { // DELETE /user-categories/:id this.delete('/user-categories/:id'); - ///////////// // User roles ///////////// @@ -501,7 +489,6 @@ export default function() { // DELETE /user-roles this.delete('/user-roles/:id'); - ////////////// // User skills ////////////// diff --git a/package.json b/package.json index e51e71bab..3ff1a0321 100644 --- a/package.json +++ b/package.json @@ -76,7 +76,7 @@ "ember-page-title": "3.0.9", "ember-resolver": "^2.0.3", "ember-simple-auth": "1.1.0", - "ember-simple-auth-token": "git@github.com:digia/ember-simple-auth-token.git", + "ember-simple-auth-token": "^1.1.1", "ember-sinon": "0.5.1", "ember-tether": "0.3.1", "ember-tooltips": "2.0.1",