-
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.
Deserialize session using ember-data if installed
- Loading branch information
1 parent
e9d71ef
commit afea458
Showing
14 changed files
with
11,200 additions
and
11 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
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 |
---|---|---|
|
@@ -11,7 +11,14 @@ var Authenticator = Ember.Object.extend({ | |
passwordWillChange: function() { | ||
this.set("passwordInvalid", false); | ||
}.observesBefore("password"), | ||
setupSession: function(session) { | ||
setupSession: function(store, session) { | ||
|
||
if(store && typeof store.pushPayload === 'function') { | ||
var type = this.get("userModelType"); | ||
store.pushPayload(type, session); | ||
session = store.find(type, session[type].id); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
joefiorini
via email
Author
Contributor
|
||
} | ||
|
||
this.set("isSignedIn", true) | ||
.set("currentUser", session); | ||
return session; | ||
|
@@ -20,19 +27,20 @@ var Authenticator = Ember.Object.extend({ | |
this.set("isSignedIn", false) | ||
.set("currentUser", null); | ||
}, | ||
// store: ember-data store instance; how do we handle non-ember-data? | ||
// Options: skip: true|false // Doesn't make ajax request for session | ||
loadSession: function(storeOrFinder, options) { | ||
loadSession: function(store, options) { | ||
if(this.get("isSignedIn") && this.get("currentUser")) { | ||
return Ember.RSVP.resolve(this.get("currentUser")); | ||
} else if(options.skip) { | ||
return Ember.RSVP.resolve(null); | ||
} else { | ||
return this._loadSession(options); | ||
return this._loadSession(store, options); | ||
} | ||
}, | ||
_loadSession: function () { | ||
_loadSession: function (store) { | ||
var result, | ||
setup = this.setupSession.bind(this), | ||
setup = this.setupSession.bind(this, store), | ||
teardown = this.teardownSession.bind(this); | ||
|
||
return this.ajax("get", this.get("currentSessionPath")) | ||
|
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
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,9 @@ | ||
DeviseSimpleAuthExample.User = DS.Model.extend({ | ||
firstName: DS.attr('string'), | ||
lastName: DS.attr('string'), | ||
email: DS.attr('string'), | ||
fullName: function() { | ||
return [this.get('firstName'), | ||
this.get('lastName')].join(' '); | ||
}.property('firstName', 'lastName') | ||
}); |
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
3 changes: 2 additions & 1 deletion
3
examples/ember-rails/app/assets/javascripts/templates/dashboard.hbs
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,6 +1,7 @@ | ||
<h1>Dashboard</h1> | ||
|
||
<p><em>You are signed in as:</em> {{currentUser.email}}</p> | ||
<p><em>You are signed in as:</em> {{currentUser.fullName}} ({{currentUser.email}})</p> | ||
|
||
<p>This is your dashboard, where you might some some really interesting stuff.</p> | ||
|
||
<p>Actually, not really. We all know there is nothing <em>actually</em> interesting in this world.</p> |
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,3 @@ | ||
class UserSerializer < ActiveModel::Serializer | ||
attributes :id, :first_name, :last_name, :email | ||
end |
6 changes: 6 additions & 0 deletions
6
examples/ember-rails/db/migrate/20140319152327_add_name_to_users.rb
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,6 @@ | ||
class AddNameToUsers < ActiveRecord::Migration | ||
def change | ||
add_column :users, :first_name, :string | ||
add_column :users, :last_name, :string | ||
end | ||
end |
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.
s/session/currentUser ?