Created
April 24, 2012 23:39
-
-
Save tathagata/2484627 to your computer and use it in GitHub Desktop.
Facebook login example
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 characters
| @if(Request.IsAuthenticated) { | |
| <text><img src="http://graph.facebook.com/@User.Identity.Name/picture" alt=""/> <strong>@User.Identity.Name</strong>! | |
| [ @Html.ActionLink("Log Off", "LogOff", "Account") ]</text> | |
| } | |
| else | |
| { | |
| <text>Login using Facebook:@User.Identity.Name </text> | |
| <fb:login-button scope="email,user_checkins" onlogin="afterFacebookConnect();" | |
| autologoutlink="false" ></fb:login-button> | |
| <div id="fb-root" style="display:inline; margin-left:20px;"></div> | |
| <text>OR </text> | |
| @:[ @Html.ActionLink("Log On", "LogOn", "Account") ] | |
| } | |
| <script language="javascript" type="text/javascript"> | |
| window.fbAsyncInit = function () { | |
| FB.init({ appId: 144248845702538, | |
| status: true, cookie: false, xfbml: true | |
| }); | |
| }; | |
| function afterFacebookConnect() { | |
| FB.getLoginStatus(function (response) { | |
| if (response.authResponse) { | |
| console.log("Calling controller"); | |
| window.location = "../Account/FacebookLogin?token=" + | |
| response.authResponse.accessToken; | |
| } else { | |
| // user clicked Cancel | |
| console.log("response.session did not come true"); | |
| } | |
| }); | |
| }; | |
| $(document).ready(function () { | |
| if (document.getElementById('fb-root') != undefined) { | |
| var e = document.createElement('script'); | |
| e.type = 'text/javascript'; | |
| e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js'; | |
| e.async = true; | |
| document.getElementById('fb-root').appendChild(e); | |
| } | |
| }); | |
| </script> | |
| @if(Request.IsAuthenticated) { | |
| <text>Welcome <strong>@User.Identity.Name</strong>! | |
| [ @Html.ActionLink("Log Off", "LogOff", "Account") ]</text> | |
| } | |
| else { | |
| @:[ @Html.ActionLink("Log On", "LogOn", "Account") ] | |
| } |
Author
tathagata
commented
Apr 24, 2012
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment