-
Notifications
You must be signed in to change notification settings - Fork 312
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #243 from lisamcho/fb_refactor
Facebook refactor with email and photo saving
- Loading branch information
Showing
16 changed files
with
221 additions
and
365 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,100 @@ | ||
const web_app_config = require("../config"); | ||
import Dispatcher from "../dispatcher/Dispatcher"; | ||
import VoterActions from "../actions/VoterActions"; | ||
import FacebookConstants from "../constants/FacebookConstants"; | ||
const cookies = require("../utils/cookies"); | ||
|
||
module.exports = { | ||
|
||
initFacebook: function () { | ||
window.fbAsyncInit = function () { | ||
window.FB.init({ | ||
appId: web_app_config.FACEBOOK_APP_ID, | ||
xfbml: true, | ||
version: "v2.5" | ||
}); | ||
}; | ||
|
||
(function (d, s, id){ | ||
var js, fjs = d.getElementsByTagName(s)[0]; | ||
if (d.getElementById(id)) {return;} | ||
js = d.createElement(s); js.id = id; | ||
js.src = "//connect.facebook.net/en_US/sdk.js"; | ||
fjs.parentNode.insertBefore(js, fjs); | ||
}(document, "script", "facebook-jssdk")); | ||
}, | ||
|
||
facebookSignIn: function (facebook_id, facebook_email){ | ||
Dispatcher.loadEndpoint("facebookSignIn", { | ||
facebook_id: facebook_id, | ||
facebook_email: facebook_email | ||
}); | ||
}, | ||
|
||
facebookDisconnect: function (){ | ||
Dispatcher.loadEndpoint("facebookDisconnect"); | ||
}, | ||
|
||
appLogout: function (){ | ||
cookies.setItem("voter_device_id", "", -1, "/"); | ||
VoterActions.signOut(); | ||
VoterActions.retrieveVoter(); | ||
}, | ||
|
||
login: function () { | ||
window.FB.getLoginStatus(function (response) { | ||
if (response.status === "connected") { | ||
Dispatcher.dispatch({ | ||
type: FacebookConstants.FACEBOOK_LOGGED_IN, | ||
data: response | ||
}); | ||
} else { | ||
window.FB.login( (res) =>{ | ||
Dispatcher.dispatch({ | ||
type: FacebookConstants.FACEBOOK_LOGGED_IN, | ||
data: res | ||
}); | ||
}, {scope: "public_profile,email"}); | ||
} | ||
}); | ||
}, | ||
|
||
logout: function () { | ||
window.FB.logout((response) => { | ||
Dispatcher.dispatch({ | ||
type: FacebookConstants.FACEBOOK_LOGGED_OUT, | ||
data: response | ||
}); | ||
}); | ||
}, | ||
|
||
disconnectFromFacebook: function () { | ||
// Removing connection between We Vote and Facebook | ||
Dispatcher.dispatch({ | ||
type: FacebookConstants.FACEBOOK_SIGN_IN_DISCONNECT, | ||
data: true | ||
}); | ||
}, | ||
|
||
getFacebookProfilePicture: function (userId) { | ||
window.FB.api(`/${userId}/picture?type=large`, (response) => { | ||
Dispatcher.dispatch({ | ||
type: FacebookConstants.FACEBOOK_RECEIVED_PICTURE, | ||
data: response | ||
}); | ||
}); | ||
}, | ||
|
||
getFacebookEmail: function (){ | ||
window.FB.api("/me?fields=id,email", (response) => { | ||
Dispatcher.dispatch({ | ||
type: FacebookConstants.FACEBOOK_RECEIVED_EMAIL, | ||
data: response | ||
}); | ||
}); | ||
}, | ||
|
||
savePhoto: function (url){ | ||
Dispatcher.loadEndpoint("voterPhotoSave", { facebook_profile_image_url_https: url } ); | ||
}, | ||
}; |
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
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
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.