diff --git a/app/adapters/application.js b/app/adapters/application.js index 3850d21..4be319d 100644 --- a/app/adapters/application.js +++ b/app/adapters/application.js @@ -5,6 +5,8 @@ import { inject as service } from '@ember/service'; export default class ApplicationAdapter extends JSONAPIAdapter { @service session; + namespace = 'api/v1'; + @computed('session.{data.authenticated.access_token,isAuthenticated}') get headers() { let headers = {}; @@ -15,4 +17,10 @@ export default class ApplicationAdapter extends JSONAPIAdapter { return headers; } + + handleResponse(status) { + if (status === 401 && this.session.isAuthenticated) { + this.session.invalidate(); + } + } } diff --git a/app/authenticators/jwt.js b/app/authenticators/jwt.js index c0bd0c2..3b1d724 100644 --- a/app/authenticators/jwt.js +++ b/app/authenticators/jwt.js @@ -1,14 +1,8 @@ import RSVP from 'rsvp'; import fetch from 'fetch'; -import { - run, later, cancel -} from '@ember/runloop'; -import { - isEmpty -} from '@ember/utils'; -import { - warn -} from '@ember/debug'; +import { run, later, cancel } from '@ember/runloop'; +import { isEmpty } from '@ember/utils'; +import { warn } from '@ember/debug'; import BaseAuthenticator from 'ember-simple-auth/authenticators/base'; export default BaseAuthenticator.extend({ @@ -248,7 +242,7 @@ export default BaseAuthenticator.extend({ const serverRefreshTokenEndpoint = this.get('serverRefreshTokenEndpoint'); return new RSVP.Promise((resolve, reject) => { - this.makeRequest(serverRefreshTokenEndpoint, data) + this.makeRequest(serverRefreshTokenEndpoint, data, { Authorization:data["access_token"] }) .then((response) => { return this._validateTokenAndScheduleRefresh(response); }) diff --git a/app/models/edition.js b/app/models/edition.js new file mode 100644 index 0000000..962a71a --- /dev/null +++ b/app/models/edition.js @@ -0,0 +1,9 @@ +import Model, { attr } from "@ember-data/model"; + +export default class EditionModel extends Model { + @attr name; + @attr theme; + @attr status; + @attr startDate; + @attr endDate; +} diff --git a/app/models/person.js b/app/models/person.js new file mode 100644 index 0000000..07a1a65 --- /dev/null +++ b/app/models/person.js @@ -0,0 +1,7 @@ +import Model, { attr } from "@ember-data/model"; + +export default class PersonModel extends Model { + @attr("string") firstname; + @attr("string") lastname; + @attr("date") birthday; +} diff --git a/app/models/venue.js b/app/models/venue.js new file mode 100644 index 0000000..afbef77 --- /dev/null +++ b/app/models/venue.js @@ -0,0 +1,6 @@ +import Model, { attr } from "@ember-data/model"; + +export default class VenueModel extends Model { + @attr name; + @attr location; +} diff --git a/app/router.js b/app/router.js index 95d5333..c50806d 100644 --- a/app/router.js +++ b/app/router.js @@ -8,4 +8,10 @@ export default class Router extends EmberRouter { Router.map(function() { this.route('login'); + this.route('authenticated', { path: '' }, function() { + // all routes that require the session to be authenticated + this.route('index', { path: '' }); + this.route('editions'); + this.route('venues'); + }); }); diff --git a/app/routes/application.js b/app/routes/application.js new file mode 100644 index 0000000..603e7d9 --- /dev/null +++ b/app/routes/application.js @@ -0,0 +1,10 @@ +import Route from '@ember/routing/route'; +import { inject } from '@ember/service'; + +export default class ApplicationRoute extends Route { + @inject session; + + async beforeModel() { + await this.session.setup(); + } +} \ No newline at end of file diff --git a/app/routes/authenticated/editions.js b/app/routes/authenticated/editions.js new file mode 100644 index 0000000..6d6dbd9 --- /dev/null +++ b/app/routes/authenticated/editions.js @@ -0,0 +1,10 @@ +import Route from '../authenticated'; +import { service } from '@ember/service'; + +export default class EditionsRoute extends Route { + @service store; + + model() { + return this.store.findAll('edition'); + } +} diff --git a/app/routes/authenticated/venues.js b/app/routes/authenticated/venues.js new file mode 100644 index 0000000..3b56122 --- /dev/null +++ b/app/routes/authenticated/venues.js @@ -0,0 +1,10 @@ +import Route from '../authenticated'; +import { service } from '@ember/service'; + +export default class VenuesRoute extends Route { + @service store; + + model() { + return this.store.findAll('venue'); + } +} diff --git a/app/routes/login.js b/app/routes/login.js new file mode 100644 index 0000000..d104f33 --- /dev/null +++ b/app/routes/login.js @@ -0,0 +1,10 @@ +import Route from '@ember/routing/route'; +import { inject as service } from '@ember/service'; + +export default class LoginRoute extends Route { + @service session; + + beforeModel(transition) { + this.get('session').prohibitAuthentication('index'); + } +} diff --git a/app/templates/authenticated/editions.hbs b/app/templates/authenticated/editions.hbs new file mode 100644 index 0000000..07c3d53 --- /dev/null +++ b/app/templates/authenticated/editions.hbs @@ -0,0 +1,5 @@ +{{#each @model as |edition|}} +
+ {{edition.name}} +
+{{/each}} diff --git a/app/templates/authenticated/index.hbs b/app/templates/authenticated/index.hbs new file mode 100644 index 0000000..5750f90 --- /dev/null +++ b/app/templates/authenticated/index.hbs @@ -0,0 +1,5 @@ +

Liste des pages

+ + diff --git a/config/environment.js b/config/environment.js index 9a50183..4f5bbde 100644 --- a/config/environment.js +++ b/config/environment.js @@ -21,11 +21,11 @@ module.exports = function (environment) { }; if (environment === 'development') { - // ENV.APP.LOG_RESOLVER = true; - // ENV.APP.LOG_ACTIVE_GENERATION = true; - // ENV.APP.LOG_TRANSITIONS = true; - // ENV.APP.LOG_TRANSITIONS_INTERNAL = true; - // ENV.APP.LOG_VIEW_LOOKUPS = true; + ENV.APP.LOG_RESOLVER = true; + ENV.APP.LOG_ACTIVE_GENERATION = true; + ENV.APP.LOG_TRANSITIONS = true; + ENV.APP.LOG_TRANSITIONS_INTERNAL = true; + ENV.APP.LOG_VIEW_LOOKUPS = true; } if (environment === 'test') { @@ -44,5 +44,10 @@ module.exports = function (environment) { // here you can enable a production-specific feature } + ENV['ember-simple-auth'] = { + routeAfterAuthentication: 'authenticated.index', + routeAfterInvalidation: 'login', + }; + return ENV; }; diff --git a/package-lock.json b/package-lock.json index 751e74a..f10cea6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1921,9 +1921,9 @@ } }, "node_modules/@ember-data/model/node_modules/inflection": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/inflection/-/inflection-3.0.1.tgz", - "integrity": "sha512-EpyF+TLa3xZPClbkp9pDJZtJFYPHouWuFYsfAQI8AfjnaPVOpmRV6GSzCs+QGelj2eZ7oQllcK23aI1vHhPVVg==", + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/inflection/-/inflection-3.0.2.tgz", + "integrity": "sha512-+Bg3+kg+J6JUWn8J6bzFmOWkTQ6L/NHfDRSYU+EVvuKHDxUDHAXgqixHfVlzuBQaPOTac8hn43aPhMNk6rMe3g==", "dev": true, "engines": { "node": ">=18.0.0"