Readme, quick bootstrapping, login, ember-data check
sdfsdf
This commit is contained in:
		
							parent
							
								
									978dacb16e
								
							
						
					
					
						commit
						0e16d2b0f4
					
				
					 22 changed files with 189 additions and 9 deletions
				
			
		
							
								
								
									
										5
									
								
								app/adapters/application.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								app/adapters/application.js
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,5 @@
 | 
			
		|||
import DS from 'ember-data';
 | 
			
		||||
 | 
			
		||||
export default DS.RESTAdapter.reopen({
 | 
			
		||||
  namespace: 'api'
 | 
			
		||||
});
 | 
			
		||||
							
								
								
									
										47
									
								
								app/authenticators/custom.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										47
									
								
								app/authenticators/custom.js
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -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();
 | 
			
		||||
      });
 | 
			
		||||
    });
 | 
			
		||||
  },
 | 
			
		||||
 | 
			
		||||
});
 | 
			
		||||
							
								
								
									
										10
									
								
								app/authorizers/custom.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								app/authorizers/custom.js
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -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'));
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
});
 | 
			
		||||
							
								
								
									
										14
									
								
								app/controllers/login.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								app/controllers/login.js
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -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);
 | 
			
		||||
      });
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
});
 | 
			
		||||
							
								
								
									
										10
									
								
								app/initializers/authentication.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								app/initializers/authentication.js
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -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);
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
							
								
								
									
										12
									
								
								app/models/genus.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								app/models/genus.js
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -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()
 | 
			
		||||
});
 | 
			
		||||
| 
						 | 
				
			
			@ -6,6 +6,9 @@ var Router = Ember.Router.extend({
 | 
			
		|||
});
 | 
			
		||||
 | 
			
		||||
Router.map(function() {
 | 
			
		||||
  this.route('login');
 | 
			
		||||
  this.route('about');
 | 
			
		||||
  this.resource('genera');
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
export default Router;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										4
									
								
								app/routes/about.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								app/routes/about.js
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,4 @@
 | 
			
		|||
import Ember from 'ember';
 | 
			
		||||
import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin';
 | 
			
		||||
 | 
			
		||||
export default Ember.Route.extend(AuthenticatedRouteMixin);
 | 
			
		||||
							
								
								
									
										4
									
								
								app/routes/application.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								app/routes/application.js
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,4 @@
 | 
			
		|||
import Ember from 'ember';
 | 
			
		||||
import ApplicationRouteMixin from 'simple-auth/mixins/application-route-mixin';
 | 
			
		||||
 | 
			
		||||
export default Ember.Route.extend(ApplicationRouteMixin);
 | 
			
		||||
							
								
								
									
										7
									
								
								app/routes/genera.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								app/routes/genera.js
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,7 @@
 | 
			
		|||
import Ember from 'ember';
 | 
			
		||||
 | 
			
		||||
export default Ember.Route.extend({
 | 
			
		||||
  model: function() {
 | 
			
		||||
    return this.store.find('genus');
 | 
			
		||||
  }
 | 
			
		||||
});
 | 
			
		||||
							
								
								
									
										4
									
								
								app/routes/index.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								app/routes/index.js
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,4 @@
 | 
			
		|||
import Ember from 'ember';
 | 
			
		||||
import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin';
 | 
			
		||||
 | 
			
		||||
export default Ember.Route.extend(AuthenticatedRouteMixin);
 | 
			
		||||
							
								
								
									
										7
									
								
								app/routes/login.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								app/routes/login.js
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,7 @@
 | 
			
		|||
import Ember from 'ember';
 | 
			
		||||
 | 
			
		||||
export default Ember.Route.extend({
 | 
			
		||||
  setupController: function(controller, model) {
 | 
			
		||||
    controller.set('errorMessage', null);
 | 
			
		||||
  }
 | 
			
		||||
});
 | 
			
		||||
| 
						 | 
				
			
			@ -1,3 +1,7 @@
 | 
			
		|||
html, body {
 | 
			
		||||
  margin: 20px;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
[data-ember-action] {
 | 
			
		||||
  cursor: pointer;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										3
									
								
								app/templates/about.hbs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								app/templates/about.hbs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,3 @@
 | 
			
		|||
<div class="about">
 | 
			
		||||
  <p>This is some information about hymenobacter.info</p>
 | 
			
		||||
</div>
 | 
			
		||||
| 
						 | 
				
			
			@ -1,3 +1,25 @@
 | 
			
		|||
<h2 id="title">Welcome to Ember.js</h2>
 | 
			
		||||
<div class="flakes-frame">
 | 
			
		||||
  <div class="flakes-navigation">
 | 
			
		||||
    <ul>
 | 
			
		||||
      {{#link-to 'genera' tagName='li' href=false}}
 | 
			
		||||
      {{#link-to 'genera'}}Genera{{/link-to}}
 | 
			
		||||
      {{/link-to}}
 | 
			
		||||
      {{#link-to 'about' tagName='li' href=false}}
 | 
			
		||||
      {{#link-to 'about'}}About{{/link-to}}
 | 
			
		||||
      {{/link-to}}
 | 
			
		||||
    </ul>
 | 
			
		||||
 | 
			
		||||
{{outlet}}
 | 
			
		||||
    <p class="foot">
 | 
			
		||||
      {{#if session.isAuthenticated}}
 | 
			
		||||
        <a {{ action 'invalidateSession' }}>Logout</a>
 | 
			
		||||
      {{else}}
 | 
			
		||||
        {{#link-to 'login'}}Login{{/link-to}}
 | 
			
		||||
      {{/if}}
 | 
			
		||||
    </p>
 | 
			
		||||
  </div>
 | 
			
		||||
  <div class="flakes-content">
 | 
			
		||||
    <div class="view-wrap">
 | 
			
		||||
      {{outlet}}
 | 
			
		||||
    </div>
 | 
			
		||||
  </div>
 | 
			
		||||
</div>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										7
									
								
								app/templates/genera.hbs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								app/templates/genera.hbs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,7 @@
 | 
			
		|||
<h1>Genera</h1>
 | 
			
		||||
 | 
			
		||||
<ul>
 | 
			
		||||
  {{#each}}
 | 
			
		||||
    <li>{{genusName}}</li>
 | 
			
		||||
  {{/each}}
 | 
			
		||||
</ul>
 | 
			
		||||
							
								
								
									
										1
									
								
								app/templates/index.hbs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								app/templates/index.hbs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1 @@
 | 
			
		|||
Welcome
 | 
			
		||||
							
								
								
									
										13
									
								
								app/templates/login.hbs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								app/templates/login.hbs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,13 @@
 | 
			
		|||
{{#if loggedIn}}
 | 
			
		||||
  <p>You are already logged in!</p>
 | 
			
		||||
{{else}}
 | 
			
		||||
  <form {{action "authenticate" on="submit"}}>
 | 
			
		||||
    <h2>Log In</h2>
 | 
			
		||||
    {{input value=identification type="text" placeholder="Username"}}
 | 
			
		||||
    {{input value=password type="password" placeholder="Password"}}
 | 
			
		||||
    {{input class="button-gray" type="submit" value="Log In"}}
 | 
			
		||||
  </form>
 | 
			
		||||
  {{#if errorMessage}}
 | 
			
		||||
    <div class="flakes-message error">{{errorMessage}}</div>
 | 
			
		||||
  {{/if}}
 | 
			
		||||
{{/if}}
 | 
			
		||||
		Reference in a new issue