Last active
May 1, 2017 07:35
-
-
Save pollingj/61e621f4c06c1f475d31 to your computer and use it in GitHub Desktop.
Ember Torri - PhoneGap Facebook Plugin
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
import Ember from "ember"; | |
export default Ember.Object.extend({ | |
open: function(authentication){ | |
var userId = authentication.userId; | |
var token = authentication.accessToken; | |
var store = this.get('store'); | |
return new Ember.RSVP.Promise(function(resolve, reject){ | |
Ember.$.ajax({ | |
type: "POST", | |
url: window.getURL('/users/sign_in.json'), | |
data: { 'facebookid': userId, 'token': token }, | |
dataType: 'json', | |
success: Ember.run.bind(null, resolve), | |
error: Ember.run.bind(null, reject) | |
}); | |
}).then(function(user){ | |
localStorage.setItem("auth_token", user.auth_token); | |
localStorage.setItem("auth_user", user.user.user.id); | |
var userRecord; | |
store.filter('user', function(record) { | |
if (record.get('id') === user.user.user.id) { | |
return userRecord = record; | |
} | |
}); | |
if (!userRecord) { | |
store.pushPayload('user', user.user); | |
} | |
return { | |
currentUser: store.find('user', user.user.user.id) | |
}; | |
}); | |
} | |
}); |
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
import Ember from "ember"; | |
export default Ember.Object.extend({ | |
// create a new authorization | |
open: function(options) { | |
return new Ember.RSVP.Promise(function(resolve, reject){ | |
facebookConnectPlugin.login(["email", "public_profile"], | |
function(response) { Ember.run(null, resolve, response.authResponse); }, | |
function(response) { Ember.run(null, reject, response.status); }); | |
}).then(function(response){ | |
return { | |
userId: response.userID, | |
accessToken: response.accessToken | |
} | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
does this wtill working with latest ember and torii ?