drugs3550 2015-11-28 10:05
浏览 20

数据库使用社交登录(Facebook)生成完全相同的用户条目

I have a social login (Facebook) in my app (made with Ionic) in order to provide a simple way to log into my app. But I got a weird problem.

Some users (I can't reproduce it, because I can't see a pattern) are getting registered into my database multiple times (as often as they open the app). And some users miss an email address. However, the only API connection with the app and my server script is the following:

<?php
error_reporting(0);
include_once('../lib/database_connect.php');
include_once('../lib/clean.php');

if(empty($_GET['fbID'])){
    $resultFlag = false;
} else {
    $fbId = clean($_GET['fbID']);
    $fbEmail = clean($_GET['fbEmail']);
    if(!empty($_GET['password'])){
        $password = md5(clean($_GET['password']));
    } else {
        $password = "";
    }
    $fbFirstName = clean($_GET['fbFirstName']);
    $fbLastName = clean($_GET['fbLastName']);
    $fbGender = clean($_GET['fbGender']);
    $fbLink = clean($_GET['fbLink']);
    $fbLocale = clean($_GET['fbLocale']);
    $fbAccessToken = clean($_GET['fbAccessToken']);
    $resultFlag = false;

    $sql = "SELECT * FROM user WHERE fb_id = $fbId";
    $result = mysql_query($sql);
    if(mysql_num_rows($result) > 0 && $fbId != 1){
        while($info = mysql_fetch_assoc($result)){
            $userID = $info['id'];
            $resultFlag = true;
        }
        $sql = "UPDATE user SET fb_id = '".$fbId."', email = '".$fbEmail."', password = '".$password."', first_name = '".$fbFirstName."', last_name = '".$fbLastName."', gender = '".$fbGender."', fb_link = '".$fbLink."', locale = '".$fbLocale."', fb_token = '".$fbAccessToken."', last_active = NOW() WHERE email = '".$fbEmail."'";
        mysql_query($sql);
    } else {
        $sql = "INSERT INTO user (fb_id, email, password, first_name, last_name, gender, fb_link, locale, fb_token, last_active, created) VALUES ('".$fbId."', '".$fbEmail."', '".$password."', '".$fbFirstName."', '".$fbLastName."', '".$fbGender."', '".$fbLink."', '".$fbLocale."', '".$fbAccessToken."', NOW(), NOW())";
        mysql_query($sql);
        $userID = mysql_insert_id();
        $resultFlag = true;
    }

    $response = 
        array(
            'userID' => $userID,
            'userFirstName' => $fbFirstName,
            'userLastName' => $fbLastName
        );
}

if($resultFlag == true){
    $response = array('result' => $resultFlag, 'user' => $response);
} else if ($resultFlag == false) {
    $response = array('result' => $resultFlag);
}

echo $_GET['callback']."(".json_encode($response).")";
?>

The script checks with the unique Facebook User ID if the user is already registered, if not, it generates a new record. Funny thing is that with multiple user records, the records are exactly the same, there is no different Facebook User ID or something else.

Does someone else had a problem like this?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 R语言Rstudio突然无法启动
    • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
    • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
    • ¥15 用windows做服务的同志有吗
    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值