我能够顺利地将用户登录到我的网站并从 facebook 获取他的详细信息,但我无法将他注销。在登录时,我将用户登陆到会员的内页。从那里他按下从我的网站注销。按下后,他将被送回首页,当然会重新加载。
我猜想登录的用户发生了什么,当他按下注销按钮时,他被重定向到首页。但是会自动触发登录事件并且他再次登录。
我正在使用以下代码。
<script type="text/javascript">
$(function(){
var button;
if(document.cookie.indexOf("fbsr_myappid") > 0){// I am checking if the cookie value is set I am making status in FB.init() false.
var fb_status = false;
}
else{
var fb_status = true;
}
window.fbAsyncInit = function(){
FB.init({ appId : 'myappid',
status : fb_status,
cookie : true,
xfbml : true,
oauth : true
});
showLoader(true);
function updateButton(response) {
button = document.getElementById('fb-auth');
if(response.authResponse) {
FB.api('/me', function(info){
$.post("/web/register/faceBookRegistration",{data:info}).done(function(data){
if(typeof(data) != undefined){
window.location = "/web/login/loadFaceLogin"; // I am doing an ajax post to my login controller having loadFaceMember function.
}
});
login(response, info);
});
button.onclick = function(){
// I think I should use the folowing code somewhere else
FB.logout(function(response){
logout(response);
});
};
} else {
button.onclick = function(){
showLoader(true);
FB.login(function(response){
if(response.authResponse) {
FB.api('/me', function(info){
login(response, info);
});
} else {
showLoader(false);
}
}, {scope:'email, user_birthday,user_about_me' });
}
}
}
FB.getLoginStatus(updateButton);
FB.Event.subscribe('auth.statusChange', updateButton);
};
(function() {
var e = document.createElement('script');
e.async = true;
e.type = 'text/javascript';
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
function login(response, info){
if (response.authResponse) {
var accessToken = response.authResponse.accessToken;
showLoader(false);
}
}
function logout(response){
FB.logout(function(response){
console.log("User is now logged out.");
});
showLoader(false);
}
function showLoader(status){
if (status)
console.log("Yes showLoader.");
else
console.log("Yes dont showLoader.");
}
});
在服务器端按下注销按钮时,将在注销控制器中调用以下函数。
function index(){
$isSessionExp = true;
if( $this->session->userdata('is_sess') )
$isSessionExp=false;
$login_session_id = $this->session->userdata('login_session_id');
$this->login_model->updateLogoutTime($login_session_id);
$this->session->sess_destroy();
if($isSessionExp)
redirect($this->url."/logout/session_expired");
else
redirect($this->url."/login");
}
我想我是否能够将注销控制器中的上述函数与以下 javascript 代码行链接起来。
FB.logout(function(response){
logout(response);
}
我的工作会完成的。
任何帮助将不胜感激。