Skip to content

Commit

Permalink
Merge pull request #1 from martinic/db-emit
Browse files Browse the repository at this point in the history
Beta.2
  • Loading branch information
broerse authored Sep 15, 2016
2 parents 49e3660 + 767525b commit 18bd3d3
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 83 deletions.
59 changes: 0 additions & 59 deletions addon/adapters/user.js

This file was deleted.

43 changes: 31 additions & 12 deletions addon/authenticators/pouch.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,55 @@ import Ember from 'ember';
const { getOwner } = Ember;

export default Base.extend({
store: Ember.inject.service(),

init() {
this._super(...arguments);

let config = getOwner(this).resolveRegistration('config:environment');
this.db = this.getDb();
},

getDb() {
let config = getOwner(this).resolveRegistration('config:environment');

//let the user override the default adapter
let pouchAdapterName = config.emberPouch.authAdapter || 'user';
let pouchAdapterName = config.authAdapter || 'application';

let pouchAdapter = getOwner(this).lookup(`adapter:${pouchAdapterName}`);
let pouchAdapter = this.get('store').adapterFor(pouchAdapterName);

Ember.assert('You must have an ember-pouch adapter setup for authentication', pouchAdapter);

this.db = pouchAdapter.db;
return pouchAdapter.db;
},

restore(data) {
return this.db.getUser(data.name).then(function() { return data; });
let self = this;
return this.db.getSession().then(function(resp) {
let result = null;
if (!Ember.isEmpty(data.name) && resp.userCtx.name === data.name) {
result = data;
self.db.emit('loggedin');
}
else {
result = Ember.RSVP.reject("Not logged in or incorrect user in cookie");
}

return result;
});
},

authenticate(username, password) {
return this.db.login(username, password, {
ajax: {
headers: {
'X-Hello': 'World'
}
}
let self = this;
return this.db.login(username, password).then(function() {
return self.db.getSession().then(function(resp) {
self.db.emit('loggedin');
return resp.userCtx;
});
});
},

invalidate() {
this.db.emit('loggedout');
return this.db.logout();
}
});
6 changes: 0 additions & 6 deletions addon/models/user.js

This file was deleted.

1 change: 0 additions & 1 deletion app/adapters/user.js

This file was deleted.

1 change: 0 additions & 1 deletion app/models/user.js

This file was deleted.

2 changes: 1 addition & 1 deletion blueprints/ember-cli-simple-auth-pouch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = {

afterInstall: function(options) {
return this.addBowerPackagesToProject([
{ name: "pouchdb-authentication", target: "^0.4.1" }
{ name: "pouchdb-authentication", target: "^0.5.3" }
]);
}
};
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ember-simple-auth-pouch",
"version": "0.1.0-beta.1",
"version": "0.1.0-beta.2",
"description": "Ember Simple Auth Authenticator for Pouch.",
"directories": {
"doc": "doc",
Expand All @@ -11,7 +11,7 @@
"start": "ember server",
"test": "ember try:testall"
},
"repository": "",
"repository": "https://github.com/martinic/ember-simple-auth-pouch",
"engines": {
"node": ">= 0.10.0"
},
Expand All @@ -36,7 +36,7 @@
"ember-export-application-global": "^1.0.4",
"ember-pouch": "3.0.0",
"ember-resolver": "^2.0.3",
"ember-simple-auth": "1.0.1",
"ember-simple-auth": "1.1.0",
"ember-try": "~0.0.8"
},
"keywords": [
Expand Down

0 comments on commit 18bd3d3

Please sign in to comment.