在注册页面中,我为用户提供了填写大部分字段的选项,方法是让他使用 facebook 登录我的网站,以便我可以访问他的数据,然后他应该填写其他一些字段,然后注册到我的网站。
在登录页面上,用户可以选择使用用户名和密码登录,或者使用他们之前注册的 Facebook 帐户登录。
在登录页面上,我有以下代码:
if ($user){
try {
$loggedin= true;
$user_profile = $facebook->api('/me','GET');
$login_url = $facebook->getLoginUrl(
array(
'scope' => 'publish_stream,read_friendlists,email'
)
);
if(email_exists($user_profile['email'])){
$user = get_user_by('email', $user_profile['email']);
wp_set_auth_cookie( $user->id );
wp_redirect( site_url() ); exit;
}else{
wp_redirect( site_url('/register/') ); exit;
}
} catch (FacebookApiException $e) {
$login_url = $facebook->getLoginUrl(
array(
'scope' => 'publish_stream,read_friendlists,email'
)
);
$loggedin= false;
error_log($e->getType());
error_log($e->getMessage());
}
}else{
$login_url = $facebook->getLoginUrl(
array(
'scope' => 'publish_stream,read_friendlists,email'
)
);
$loggedin= false;
}
因此,如果用户使用 facebook 登录,代码会检查他是否是会员,如果是,则他已通过身份验证并重定向到主页,如果电子邮件不存在,则应将他重定向到注册页面。
The problem is that if a user logged in with facebook in the registration page, the login page code will recognize him as a logged in user and will give him access if he's a member or redirect him if he's not a member, but what if a user would like to login with another account?
What I need to do is to terminate the access token in the login page so that he should re-login with his facebook account. Is that possible?