diff --git a/README.md b/README.md index 274dbc4..16e11f0 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ -# Hymenobacterdotinfo +# hymenobacterdotinfo + +Detailed information to come --- for now see the ember-cli boilerplate below. This README outlines the details of collaborating on this Ember application. A short introduction of this app could easily go here. @@ -50,4 +52,3 @@ Specify what it takes to deploy your app. * Development Browser Extensions * [ember inspector for chrome](https://chrome.google.com/webstore/detail/ember-inspector/bmdblncegkenkacieihfhpjfppoconhi) * [ember inspector for firefox](https://addons.mozilla.org/en-US/firefox/addon/ember-inspector/) - diff --git a/app/adapters/application.js b/app/adapters/application.js new file mode 100644 index 0000000..2c5e29d --- /dev/null +++ b/app/adapters/application.js @@ -0,0 +1,5 @@ +import DS from 'ember-data'; + +export default DS.RESTAdapter.reopen({ + namespace: 'api' +}); diff --git a/app/authenticators/custom.js b/app/authenticators/custom.js new file mode 100644 index 0000000..1b08656 --- /dev/null +++ b/app/authenticators/custom.js @@ -0,0 +1,47 @@ +import Ember from 'ember'; +import Base from 'simple-auth/authenticators/base'; + +export default Base.extend({ + tokenEndpoint: '/api/authenticate', + + restore: function(data) { + return new Ember.RSVP.Promise(function(resolve, reject) { + if (!Ember.isEmpty(data.token)) { + resolve(data); + } else { + reject(); + } + }); + }, + + authenticate: function(credentials) { + var _this = this; + return new Ember.RSVP.Promise(function(resolve, reject) { + Ember.$.ajax({ + url: _this.tokenEndpoint, + type: 'POST', + data: {username: credentials.identification, password: credentials.password}, + contentType: 'application/x-www-form-urlencoded' + }).then(function(response) { + Ember.run(function() { + resolve({ token: response.token }); + }); + }, function(xhr, status, error) { + var response = JSON.parse(xhr.responseText); + Ember.run(function() { + reject(response.error); + }); + }); + }); + }, + + invalidate: function(data) { + var _this = this; + return new Ember.RSVP.Promise(function(resolve) { + Ember.$.ajax({ url: _this.tokenEndpoint, type: 'DELETE' }).always(function() { + resolve(); + }); + }); + }, + +}); diff --git a/app/authorizers/custom.js b/app/authorizers/custom.js new file mode 100644 index 0000000..897b82e --- /dev/null +++ b/app/authorizers/custom.js @@ -0,0 +1,10 @@ +import Ember from 'ember'; +import Base from 'simple-auth/authorizers/base'; + +export default Base.extend({ + authorize: function(jqXHR, requestOptions) { + if (this.get('session.isAuthenticated') && !Ember.isEmpty(this.get('session.token'))) { + jqXHR.setRequestHeader('Authorization', 'Bearer ' + this.get('session.token')); + } + } +}); diff --git a/app/controllers/login.js b/app/controllers/login.js new file mode 100644 index 0000000..1cb83f5 --- /dev/null +++ b/app/controllers/login.js @@ -0,0 +1,14 @@ +import Ember from 'ember'; +import LoginControllerMixin from 'simple-auth/mixins/login-controller-mixin'; + +export default Ember.Controller.extend(LoginControllerMixin, { + authenticator: 'authenticators:custom', + actions: { + authenticate: function() { + var _this = this; + this._super().then(null, function(message) { + _this.set('errorMessage', message); + }); + } + } +}); diff --git a/app/initializers/authentication.js b/app/initializers/authentication.js new file mode 100644 index 0000000..bf7b139 --- /dev/null +++ b/app/initializers/authentication.js @@ -0,0 +1,10 @@ +import Authenticator from './../authenticators/custom'; +import Authorizer from './../authorizers/custom'; + +export default { + name: 'bling', + initialize: function(container) { + container.register('authenticators:custom', Authenticator); + container.register('authorizers:custom', Authorizer); + } +}; diff --git a/app/models/genus.js b/app/models/genus.js new file mode 100644 index 0000000..7860531 --- /dev/null +++ b/app/models/genus.js @@ -0,0 +1,12 @@ +import DS from 'ember-data'; +import Ember from 'ember'; + +var inflector = Ember.Inflector.inflector; +inflector.irregular('genus', 'genera'); + +export default DS.Model.extend({ + genusName: DS.attr(), + createdAt: DS.attr(), + updatedAt: DS.attr(), + deletedAt: DS.attr() +}); diff --git a/app/router.js b/app/router.js index cef554b..3a9816c 100644 --- a/app/router.js +++ b/app/router.js @@ -6,6 +6,9 @@ var Router = Ember.Router.extend({ }); Router.map(function() { + this.route('login'); + this.route('about'); + this.resource('genera'); }); export default Router; diff --git a/app/routes/about.js b/app/routes/about.js new file mode 100644 index 0000000..5b14286 --- /dev/null +++ b/app/routes/about.js @@ -0,0 +1,4 @@ +import Ember from 'ember'; +import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin'; + +export default Ember.Route.extend(AuthenticatedRouteMixin); diff --git a/app/routes/application.js b/app/routes/application.js new file mode 100644 index 0000000..8a864b5 --- /dev/null +++ b/app/routes/application.js @@ -0,0 +1,4 @@ +import Ember from 'ember'; +import ApplicationRouteMixin from 'simple-auth/mixins/application-route-mixin'; + +export default Ember.Route.extend(ApplicationRouteMixin); diff --git a/app/routes/genera.js b/app/routes/genera.js new file mode 100644 index 0000000..d975380 --- /dev/null +++ b/app/routes/genera.js @@ -0,0 +1,7 @@ +import Ember from 'ember'; + +export default Ember.Route.extend({ + model: function() { + return this.store.find('genus'); + } +}); diff --git a/app/routes/index.js b/app/routes/index.js new file mode 100644 index 0000000..5b14286 --- /dev/null +++ b/app/routes/index.js @@ -0,0 +1,4 @@ +import Ember from 'ember'; +import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin'; + +export default Ember.Route.extend(AuthenticatedRouteMixin); diff --git a/app/routes/login.js b/app/routes/login.js new file mode 100644 index 0000000..e772f01 --- /dev/null +++ b/app/routes/login.js @@ -0,0 +1,7 @@ +import Ember from 'ember'; + +export default Ember.Route.extend({ + setupController: function(controller, model) { + controller.set('errorMessage', null); + } +}); diff --git a/app/styles/app.css b/app/styles/app.css index 9adb5ad..a1a141f 100644 --- a/app/styles/app.css +++ b/app/styles/app.css @@ -1,3 +1,7 @@ html, body { margin: 20px; } + +[data-ember-action] { + cursor: pointer; +} diff --git a/app/templates/about.hbs b/app/templates/about.hbs new file mode 100644 index 0000000..2b95e93 --- /dev/null +++ b/app/templates/about.hbs @@ -0,0 +1,3 @@ +
This is some information about hymenobacter.info
+You are already logged in!
+{{else}} + + {{#if errorMessage}} + + {{/if}} +{{/if}} diff --git a/bower.json b/bower.json index a505ea9..b87c5af 100644 --- a/bower.json +++ b/bower.json @@ -13,7 +13,6 @@ "ember-qunit": "0.1.8", "ember-qunit-notifications": "0.0.4", "qunit": "~1.15.0", - "flakes": "~1.0.0", - "ember-simple-auth": "0.7.2" + "flakes": "~1.0.0" } } diff --git a/config/environment.js b/config/environment.js index 15f1378..40c3219 100644 --- a/config/environment.js +++ b/config/environment.js @@ -22,9 +22,12 @@ 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_TRANSITIONS = true; + ENV.APP.LOG_TRANSITIONS_INTERNAL = true; // ENV.APP.LOG_VIEW_LOOKUPS = true; + ENV['simple-auth'] = { + authorizer: 'authorizers:custom' + } } if (environment === 'test') { diff --git a/package.json b/package.json index e710ce4..9acbc40 100644 --- a/package.json +++ b/package.json @@ -22,9 +22,9 @@ "broccoli-asset-rev": "^2.0.0", "broccoli-ember-hbs-template-compiler": "^1.6.1", "ember-cli": "0.1.7", - "ember-cli-6to5": "0.2.1", "ember-cli-content-security-policy": "0.3.0", "ember-cli-dependency-checker": "0.0.7", + "ember-cli-6to5": "0.2.1", "ember-cli-ic-ajax": "0.1.1", "ember-cli-inject-live-reload": "^1.3.0", "ember-cli-qunit": "0.1.2",