Sorry for the delay(again....) I accidentally deleted some live customer data from the cloud(windows azure)!!!!! and spent almost a whole week writing scripts to recover some data.. so the lesson i learned is 1. don't run some tool that you are not familiar with(that's how the data got wiped out) 2. Data should always have backup..
Ok. back to the topic!
As you can see from the previous post, onlogin="
Facebook._CheckLogin(getQuerystring('returnurl'));">
Apparently, we need some javascript function here.
Again, I will just paste my js file here. put it under NopCommerceStore\Scripts\Facebook.js and be sure to add the reference in \NopCommerceStore\Modules\CustomerLoginWithFacebook.ascx.cs like the following:
protected override void OnPreRender(EventArgs e)
{
//java-script
string facebookJS = CommonHelper.GetStoreLocation() + "Scripts/facebook.js";
Page.ClientScript.RegisterClientScriptInclude(facebookJS, facebookJS);
base.OnPreRender(e);
}
So here is facebook.js:
function getQuerystring(key, default_) {
if (default_ == null) default_ = "";
key = key.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regex = new RegExp("[\\?&]" + key + "=([^&#]*)");
var qs = regex.exec(window.location.href);
if (qs == null)
return default_;
else
return qs[1];
}
var Facebook = new function () {
this._CheckLogin = function (returnUrl) {
if (FB) {
FB.getLoginStatus(function (response) {
if (response.session) {
var uid = response.session["uid"];
var access_token = response.session["access_token"];
jQuery.ajax({
type: "POST",
url: "/FBUtils.aspx/UserIDExists",
data: "{ uid: '" + uid + "', accesstoken: '" + access_token + "', returnurl: '" + returnUrl + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
var obj = jQuery.parseJSON(data.d);
if (obj['result'] == "true") {
response.session["isfacebooklogin"] = "true";
window.location = obj['returnUrl'];
}
}
});
} else {
// The user has logged out, and the cookie has been cleared
}
});
}
};
};
I am not going to explain line by line here, but its pretty straightforward: when user clicks facebook login,
it use ajax to call a webservice /FBUtils.aspx/UserIDExists and I will explain FBUtils.aspx and UserIDExists in my next post.