Google、Facebook登录密码问题

bug问题 · eden · 于 7年前 发布 · 2818 次阅读

文件路径:vendor\fancyecommerce\fecshop\app\apphtml5\modules\Customer\controllers\GoogleController.php 在GoogleController代码中$user没有password字段

 /**
     * google账户登录.
     */
    public function accountLogin($full_name, $email)
    {
        $name_arr = explode(' ', $full_name);
        $first_name = $name_arr[0];
        $last_name = $name_arr[1];
        $user = [
            'first_name'    =>$first_name,
            'last_name'    =>$last_name,
            'email'        =>$email,
        ];
        Yii::$service->customer->registerThirdPartyAccountAndLogin($user, 'google');
        echo '<script>
					window.close();
					window.opener.location.reload();
				</script>';
        exit;
    }

所以在vendor\fancyecommerce\fecshop\services\Customer.php 中每次都会getRandomPassword(),在登录的时候login($user)就会每次都用新密码去验证

 protected function actionRegisterThirdPartyAccountAndLogin($user, $type)
    {
        if (!(isset($user['password']) && $user['password'])) {
            $user['password'] = $this->getRandomPassword();
        }
        // 查看邮箱是否存在
        $email = $user['email'];
        $customer_one = Yii::$service->customer->getUserIdentityByEmail($email);
        Yii::info($customer_one,'fecshop_debug');
        if ($customer_one) {
            $loginStatus = Yii::$service->customer->login($user);
            Yii::info($loginStatus,'fecshop_debug');
            if ($loginStatus) {
                return true;
            }
        // 不存在,注册。
        } else {
            $registerData = [
                'email'    => $email,
                'firstname' => $user['first_name'],
                'lastname'    => $user['last_name'],
                'password'    => $user['password'],
                'type'        => $type,
            ];
            $registerStatus = Yii::$service->customer->register($registerData);
            if ($registerStatus) {
                $loginStatus = Yii::$service->customer->login($registerData);
                if ($loginStatus) {
                    return true;
                }
            }
        }

        return false;
    }
共收到 1 条回复
water#17年前 0 个赞

你没有仔细看代码,上面生成了代码,如果是老用户,生成的密码,下面没有用到

当然,这个地方肯定是存在问题的,我借了个国外服务器进行测试了一下,google登录的问题已经解决,详细参看提交的代码修改:

https://github.com/fecshop/yii2_fecshop/commit/29dd94d4b90b4c95954635bd615b8086c2af4e95

注意:app/apphtml5/modules/Customer/controllers/GoogleController.php 和 app/appfront/modules/Customer/controllers/GoogleController.php 都需要添加下面的global变量。

app/appfront/modules/Customer/controllers/GoogleController.php 在昨天上次已经提交了。因此这次的提交看不到,但是您也需要添加global这行代码

搞完这三个文件的修改,就可以了,google 登录我测试通过,你测试一下,是否已经没有问题了。

剩下的就是修改这个文件代码: services/Customer.php

添加回复 (需要登录)
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册
Your Site Analytics