Created
December 3, 2012 07:42
Revisions
-
philcockfield revised this gist
Dec 3, 2012 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -23,7 +23,6 @@ do -> css tmpl.label = -> switch ns.signedIn() when true then 'Sign Out' when false then 'Sign In' -
philcockfield created this gist
Dec 3, 2012 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,35 @@ do -> # See: http://developers.facebook.com/docs/reference/javascript/ ns = APP.ns 'core.facebook' # ---------------------- Methods ---------------------- ns.login = (callback) -> FB.login -> callback?() ns.logout = (callback) -> FB.logout -> callback?() ns.signedIn = -> authStatus() is 'signed-in' authStatus = -> Session.get('auth-status') # ---------------------- Templates ---------------------- tmpl = Template['core-facebook-btn-login'] tmpl.class = -> css = '' css += 'hidden' if authStatus() is 'unknown' css tmpl.label = -> # return 'Loading...' if Session.get('fb-loading') is true switch ns.signedIn() when true then 'Sign Out' when false then 'Sign In' tmpl.events = 'click button.fb.login': -> switch ns.signedIn() when true then ns.logout() when false then ns.login() This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,4 @@ <template name='core-facebook-btn-login'> <button class='core btn fb login {{class}}'>{{ label }}</button> </template> This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,12 @@ Meteor.methods facebookLogin: (fbUser, accessToken) -> serviceData = id: fbUser.id accessToken: accessToken email: fbUser.email options = profile: name: fbUser.name userId = Accounts.updateOrCreateUserFromExternalService('facebook', serviceData, options).id This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,49 @@ do -> ns = APP.ns 'core.facebook' ### Monitors the Facebook SDK and provides a consistent set of status updates. ### ns._facebookAuthStatus = -> # Wire up events. FB.Event.subscribe 'auth.authResponseChange', (res) -> updateStatus() FB.getLoginStatus (res) -> updateStatus() getFacebookUser = (callback) -> if ns.user? callback?(ns.user) else FB.api '/me', (fbUser) -> ns.user = fbUser Session.set 'fb-user', fbUser callback?(fbUser) setStatus = (value) -> Session.set 'fb-auth-status', value updateStatus = -> authResponse = FB.getAuthResponse() if authResponse is undefined setStatus 'unknown' else if authResponse is null reset() setStatus 'signed-out' else Session.set 'fb-token', authResponse.accessToken if ns.user? setStatus 'signed-in' else setStatus 'pending-user' getFacebookUser -> updateStatus() reset = -> ns.user = null Session.set 'fb-user', null Session.set 'fb-auth-token', null This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ ### Manages the Meteor authentication status, which involves authenticating against the Meteor backend after the Facebook SDK has completed it's authentication steps. ### do -> ns = APP.ns 'core.facebook' setStatus = (value) -> Session.set 'auth-status', value setStatus 'unknown' SIGNED_IN = 'signed-in' SIGNED_OUT = 'signed-out' serverLogin = (callback) -> fbUser = Session.get('fb-user') token = Session.get('fb-token') Meteor.call 'facebookLogin', fbUser, token, (err, userId) -> # Hook into the core Meteor account system, and pop # the client into a state of being logged in. Accounts._makeClientLoggedIn userId, token callback?() Meteor.autorun -> switch Session.get( 'fb-auth-status' ) when SIGNED_IN serverLogin -> setStatus SIGNED_IN when SIGNED_OUT Meteor.logout -> setStatus SIGNED_OUT