This repository has been archived by the owner on Sep 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5954830
commit 43c17ec
Showing
34 changed files
with
208 additions
and
380 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,4 +15,3 @@ | |
/libpeerconnection.log | ||
npm-debug.log | ||
testem.log | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"predef": [ | ||
"server", | ||
"document", | ||
"window", | ||
"-Promise" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,26 @@ | ||
# ember-simple-token | ||
# Simple-token | ||
|
||
This README outlines the details of collaborating on this Ember addon. | ||
|
||
## Installation | ||
|
||
`ember install ember-simple-token` | ||
* `git clone` this repository | ||
* `npm install` | ||
* `bower install` | ||
|
||
## Running | ||
|
||
### Code to put in your component | ||
* `ember server` | ||
* Visit your app at http://localhost:4200. | ||
|
||
```javascript | ||
import Ember from 'ember'; | ||
## Running Tests | ||
|
||
const { service } = Ember.inject; | ||
* `npm test` (Runs `ember try:testall` to test your addon against multiple Ember versions) | ||
* `ember test` | ||
* `ember test --server` | ||
|
||
export default Ember.Component.extend({ | ||
session: service(), | ||
## Building | ||
|
||
actions: { | ||
authenticate() { | ||
let credentials = this.getProperties('identification', 'password'); | ||
this.get('session').authenticate('authenticator:token', credentials).catch((reason) => { | ||
this.set('errorMessage', reason.error); | ||
}); | ||
} | ||
} | ||
}); | ||
``` | ||
* `ember build` | ||
|
||
### Code for the template | ||
|
||
```html | ||
<form {{action 'authenticate' on='submit'}}> | ||
<div class="form-group"> | ||
<label for="identification">Login</label> | ||
{{input value=identification placeholder='Enter Login' class='form-control'}} | ||
</div> | ||
<div class="form-group"> | ||
<label for="password">Password</label> | ||
{{input value=password placeholder='Enter Password' class='form-control' type='password'}} | ||
</div> | ||
<button type="submit" class="btn btn-default">Login</button> | ||
</form> | ||
``` | ||
|
||
### Ember-Data usage | ||
|
||
```javascript | ||
import DS from 'ember-data'; | ||
import DataAdapterMixin from 'ember-simple-auth/mixins/data-adapter-mixin'; | ||
|
||
export default DS.JSONAPIAdapter.extend(DataAdapterMixin, { | ||
authorizer: 'authorizer:token' | ||
}); | ||
``` | ||
### Change Configuration | ||
|
||
```javascript | ||
ENV['ember-simple-token'] = { | ||
serverTokenEndpoint: "/another-token", | ||
identificationAttributeName: "email" | ||
}; | ||
``` | ||
|
||
### Generators | ||
`ember g login-scaffold <name>` | ||
|
||
Will generate all the code seen above in pod structure in a component | ||
|
||
### TODO: | ||
- [] Test | ||
For more information on using ember-cli, visit [http://ember-cli.com/](http://ember-cli.com/). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,35 @@ | ||
import Ember from 'ember'; | ||
import BaseAuthenticator from 'ember-simple-auth/authenticators/base'; | ||
import Base from 'ember-simple-auth/authenticators/base'; | ||
import Configuration from '../configuration'; | ||
|
||
const { get, isEmpty, inject: { service }, RSVP } = Ember; | ||
const { resolve, reject } = RSVP; | ||
const { get, isEmpty, inject: { service }, RSVP: { resolve, reject } } = Ember; | ||
|
||
export default BaseAuthenticator.extend({ | ||
export default Base.extend({ | ||
ajax: service(), | ||
|
||
serverTokenEndpoint: '/token', | ||
serverTokenEndpoint: Configuration.serverTokenEndpoint, | ||
|
||
tokenAttributeName: 'token', | ||
tokenAttributeName: Configuration.tokenAttributeName, | ||
|
||
identificationAttributeName: 'email', | ||
identificationAttributeName: Configuration.identificationAttributeName, | ||
|
||
init() { | ||
this._super(...arguments); | ||
const config = Ember.getOwner(this).resolveRegistration('config:environment')['ember-simple-token']; | ||
if (config !== undefined) { | ||
this.serverTokenEndpoint = config.serverTokenEndpoint; | ||
this.tokenAttributeName = config.tokenAttributeName; | ||
this.identificationAttributeName = config.identificationAttributeName; | ||
restore(data) { | ||
const token = get(data, this.tokenAttributeName); | ||
if (!isEmpty(token)) { | ||
return resolve(data); | ||
} else { | ||
return reject(); | ||
} | ||
}, | ||
|
||
authenticate(data) { | ||
return get(this, 'ajax').post(this.serverTokenEndpoint, { | ||
data: JSON.stringify(data) | ||
}).then((response) => { | ||
return response.json().then((json) => { | ||
if (response.status >= 200 && response.status < 300) { | ||
return resolve(json); | ||
} else { | ||
return reject(json); | ||
} | ||
}); | ||
}); | ||
}, | ||
|
||
restore(data) { | ||
const token = get(data, this.tokenAttributeName); | ||
if (isEmpty(token)) { | ||
return resolve(response); | ||
}).catch((error) => { | ||
Ember.Logger.warn(error); | ||
return reject(); | ||
} else { | ||
return resolve(data); | ||
} | ||
}, | ||
|
||
invalidate() { | ||
return resolve(); | ||
}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import Ember from 'ember'; | ||
|
||
const { getWithDefault } = Ember; | ||
|
||
const DEFAULTS = { | ||
serverTokenEndpoint: '/token', | ||
tokenAttributeName: 'token', | ||
identificationAttributeName: 'email' | ||
}; | ||
|
||
export default { | ||
serverTokenEndpoint: DEFAULTS.serverTokenEndpoint, | ||
|
||
tokenAttributeName: DEFAULTS.tokenAttributeName, | ||
|
||
identificationAttributeName: DEFAULTS.identificationAttributeName, | ||
|
||
load(config) { | ||
for (let property in this) { | ||
if (this.hasOwnProperty(property) && Ember.typeOf(property) !== 'function') { | ||
this[property] = getWithDefault(config, property, DEFAULTS[property]); | ||
} | ||
} | ||
} | ||
}; |
7 changes: 1 addition & 6 deletions
7
addon/initializers/simple-token.js → addon/initializers/setup-registry.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,7 @@ | ||
import TokenAuthenticator from '../authenticators/token'; | ||
import TokenAuthorizer from '../authorizers/token'; | ||
|
||
export function initialize(application) { | ||
export default function setupRegistry(application) { | ||
application.register('authenticator:token', TokenAuthenticator); | ||
application.register('authorizer:token', TokenAuthorizer); | ||
} | ||
|
||
export default { | ||
name: 'simple-token', | ||
initialize | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from 'simple-token/authenticators/token'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from 'simple-token/authorizers/token'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,12 @@ | ||
export { default, initialize } from 'ember-simple-token/initializers/simple-token'; | ||
import ENV from '../config/environment'; | ||
import setupRegistry from 'simple-token/initializers/setup-registry'; | ||
import Configuration from 'simple-token/configuration'; | ||
|
||
export default { | ||
name: 'simple-token', | ||
initialize(registry) { | ||
const config = ENV['simple-auth'] || {}; | ||
Configuration.load(config); | ||
setupRegistry(registry); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
8 changes: 4 additions & 4 deletions
8
blueprints/login-scaffold/files/__root__/app/components/__name__/component.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,4 @@ module.exports = { | |
} | ||
}; | ||
} | ||
}; | ||
};; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/*jshint node:true*/ | ||
module.exports = { | ||
description: '', | ||
|
||
// locals: function(options) { | ||
// // Return custom template variables here. | ||
// return { | ||
// foo: options.entity.options.foo | ||
// }; | ||
// } | ||
|
||
afterInstall() { | ||
return this.addPackagesToProject([ | ||
{ name: 'ember-simple-auth', target: '1.1.0' } | ||
]); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
{ | ||
"name": "ember-simple-token", | ||
"name": "simple-token", | ||
"dependencies": { | ||
"ember": "~2.5.0", | ||
"ember-cli-shims": "0.1.1", | ||
"ember-cli-test-loader": "0.2.2", | ||
"ember-qunit-notifications": "0.1.0" | ||
"ember-qunit-notifications": "0.1.0", | ||
"pretender": "~1.1.0", | ||
"Faker": "~3.1.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,6 @@ | ||
/*jshint node:true*/ | ||
'use strict'; | ||
|
||
module.exports = function(environment, appConfig) { | ||
appConfig['ember-simple-token'] = { | ||
serverTokenEndpoint: 'token', | ||
identificationAttributeName: 'email' | ||
}; | ||
module.exports = function(/* environment, appConfig */) { | ||
return { }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.