我正在开发一个网站,在用户首次通过Hybridauth(Facebook或Twitter)登录后,他/她需要填写更多信息。这是通过将用户通过回调URL重定向到' welcome.php'来完成的。页。在填写剩余的细节之后,然后将用户插入DB中。
问题在于,每次用户通过Hybridauth登录时,回叫都会将他发送给“欢迎”。页面,因为所有需要的信息已经存储,所以不再需要了。我尝试通过执行查询并返回用户电子邮件来解决此问题,如果与存储在数据库中的电子邮件匹配,则用户存在并且应该发送到'索引'页。
不知怎的,我不认为回调网址是最好的方法,但我想避免在欢迎页面中检查以将用户重定向到索引。
有没有办法通过Hybridauth标记首次登录?
PS:关于Vanilla PHP,我没有使用任何网络框架。
use Hybridauth\Hybridauth;
$callback_url = 'http://localhost/welcome.php';
//First step is to build a configuration array to pass to `Hybridauth\Hybridauth`
$config = [
//Location where to redirect users once they authenticate with a provider
'callback' => $callback_url,
//Providers specifics
'providers' => [
'Twitter' => ['enabled' => true, 'keys' => ['key' => 'U9MCuHyvFaHMVPmNcndFnWez7', 'secret' => 'emWZLMq5HiVL7iXs5OycHqTzRfWMLtBt0ckjuP4I6WDmUMKzlk']],
'Facebook' => ['enabled' => true, 'keys' => [ 'id' => '125169101446634', 'secret' => '55c35b473621a9e7822f0bcd40cec8d7'], "scope" => ['email']]
]
];
try{
//Feed configuration array to Hybridauth
$hybridauth = new Hybridauth($config);
//Attempt to authenticate users with a provider by name
$adapter = $hybridauth->authenticate('Facebook');
//Returns a boolean of whether the user is connected
$isConnected = $adapter->isConnected();
//Retrieve the user's profile
$userProfile = $adapter->getUserProfile();
// Setup user profile to welcome screen
$userFirstName = $userProfile->firstName;
$userLastName = $userProfile->lastName;
$userEmail = $userProfile->email;
$userImg = $userProfile->photoURL;
// Query user to select callback URL
$database = connectDB();
define('USER_AUTH_VALIDATION',"SELECT users.email FROM `users` WHERE users.email = :email");
$insert_user = $database->prepare(USER_AUTH_VALIDATION);
$insert_user->execute([
'email' => $userEmail
]);
if ($insert_user->rowCount() > 0) {
$callback_url = 'http://localhost/index.php';
} else {
$callback_url = 'http://localhost/welcome.php';
}
//Disconnect the adapter
$adapter->disconnect();
}