Readme, quick bootstrapping, login, ember-data check

sdfsdf
This commit is contained in:
Matthew Dillon 2015-01-12 16:41:36 -09:00
parent 978dacb16e
commit 0e16d2b0f4
22 changed files with 189 additions and 9 deletions

View file

@ -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/)

View file

@ -0,0 +1,5 @@
import DS from 'ember-data';
export default DS.RESTAdapter.reopen({
namespace: 'api'
});

View 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
View 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
View 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);
});
}
}
});

View 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
View 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()
});

View file

@ -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
View file

@ -0,0 +1,4 @@
import Ember from 'ember';
import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin';
export default Ember.Route.extend(AuthenticatedRouteMixin);

View 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
View 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
View 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
View file

@ -0,0 +1,7 @@
import Ember from 'ember';
export default Ember.Route.extend({
setupController: function(controller, model) {
controller.set('errorMessage', null);
}
});

View file

@ -1,3 +1,7 @@
html, body {
margin: 20px;
}
[data-ember-action] {
cursor: pointer;
}

3
app/templates/about.hbs Normal file
View file

@ -0,0 +1,3 @@
<div class="about">
<p>This is some information about hymenobacter.info</p>
</div>

View file

@ -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>
<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
View file

@ -0,0 +1,7 @@
<h1>Genera</h1>
<ul>
{{#each}}
<li>{{genusName}}</li>
{{/each}}
</ul>

1
app/templates/index.hbs Normal file
View file

@ -0,0 +1 @@
Welcome

13
app/templates/login.hbs Normal file
View 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}}

View file

@ -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"
}
}

View file

@ -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') {

View file

@ -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",