跳转到内容
登录关注  
洛汐

Chevereto也能用QQ、GitHub、微博登陆啦

已推荐帖子

简要介绍(Introduction)

此文介绍如何为您的Chevereto添加QQ登陆方式,试验性教程,造成的损失由您自己负责!!!

1583424110-998597568.png

支持环境(Requirement)

  • PHP >= 7.0
  • Chevereto >= 3.13.0

在执行所有操作前,请先做好数据备份工作,以免造成不必要的损失!!!

食用指南(Usage)

1. 安装社会化登陆库(Install support Library)

站点根目录执行,安装社会化登陆库(需环境支持Composer
https://github.com/overtrue/socialite

composer require "overtrue/socialite" -vvv

2. 添加QQ登陆方式(Add QQ login method)

修改class.login.php文件

// app\lib\classes\class.login.php:30

     public static $social_services = [
        'facebook' => 'Facebook',
        'twitter' => 'Twitter',
        'google' => 'Google',
        'vk' => 'VK',
    ];
// 修改为以下内容
     public static $social_services = [
        'facebook' => 'Facebook',
        'twitter' => 'Twitter',
        'google' => 'Google',
        'vk' => 'VK',
        'qq' => 'QQ',
    ];

3. 载入社会化登陆库(Load support library)

引入社会化登陆库,增加QQ登陆方式

// app\routes\overrides\route.connect.php:18/19

use Overtrue\Socialite\SocialiteManager;
// app\routes\overrides\route.connect.php:24/25

        if (!in_array($doing, ['google', 'facebook', 'twitter', 'vk'])) {
            return $handler->issue404();
        }
//修改为以下内容
        if (!in_array($doing, ['google', 'facebook', 'twitter', 'vk', 'qq'])) {
            return $handler->issue404();
        }

// 添加以下内容

// app\routes\overrides\route.connect.php:277~279

            case 'qq':
                $config = [
                    'qq' => [
                        'client_id' => CHV\getSetting('qq_client_id'),
                        'client_secret' => CHV\getSetting('qq_client_secret'),
                        'redirect' => G\get_base_url('connect/qq'),
                    ],
                ];

                $client = new SocialiteManager($config);
    
                if (isset($_GET['code'])) {
                    $get_user = $client->driver('qq')->user();
                    $_SESSION['qq']['token'] = $get_user->getAccessToken();
                }else{
                    $response =$client->driver('qq')->redirect();
                    $response->send();
                    $get_user = $client->driver('qq')->user();
                }
    
                if ($_SESSION['qq']['token']) {
                    $get_user->setToken($_SESSION['qq']['token']);
                }
    
                if ($get_user->getAccessToken()) {
                    if ($get_user) {
                        $social_pictures = [
                            'avatar'        => $get_user->getAvatar(),
                            'background'    => null
                        ];
                        $connect_user = [
                            'id'        => $get_user->getId(),
                            'username'  => G\sanitize_string(G\unaccent_string($get_user->getName()), true, true),
                            'name'      => $get_user->getName(),
                            'avatar'    => $get_user->getAvatar(),
                            'url'       => null
                        ];
                        $connect_tokens = [
                            'secret'    => $get_user->getAccessToken(),
                            'token_hash'=> null
                        ];
                        $do_connect = true;
                    }
                } else {
                    G\redirect(G\get_base_url('connect/qq'));
                }
            break;

4. 添加QQ登陆验证方式(Validate social networks)

添加QQ登陆方式,以便过社交登陆验证

// app\routes\overrides\route.dashboard.php:1049~1054 

                    $social_validate = [
                        'facebook'    => ['facebook_app_id', 'facebook_app_secret'],
                        'twitter'    => ['twitter_api_key', 'twitter_api_secret'],
                        'google'    => ['google_client_id', 'google_client_secret'],
                    ];
//修改为以下内容
                    $social_validate = [
                        'facebook'    => ['facebook_app_id', 'facebook_app_secret'],
                        'twitter'    => ['twitter_api_key', 'twitter_api_secret'],
                        'google'    => ['google_client_id', 'google_client_secret'],
                        'qq'        => ['qq_client_id', 'qq_client_secret'],
                    ];

5. 仪表盘添加社交网络(Add Social Network)

添加QQ互联设置界面

//app\themes\Peafowl\overrides\views\dashboard.php:2818 

            <div class="input-label">
                <label for="qq">QQ</label>
                <div class="c5 phablet-c1"><select type="text" name="qq" id="qq" class="text-input" data-combo="qq-combo">
                    <?php
                        echo CHV\Render\get_select_options_html([1 => _s('Enabled'), 0 => _s('Disabled')], get_safe_post() ? get_safe_post()['qq'] : CHV\Settings::get('qq')); ?>
                </select></div>
                <div class="input-below"><?php _se('You need a <a href="https://connect.qq.com/manage.html" target="_blank">QQ app</a> for this.'); ?></div>
            </div>
            <div id="qq-combo">
                <div data-combo-value="1" class="switch-combo c9 phablet-c1<?php if (!(get_safe_post() ? get_safe_post()['qq'] : CHV\Settings::get('qq'))) {
                            echo ' soft-hidden';
                        } ?>">
                    <div class="input-label">
                        <label for="qq_client_id"><?php _se('QQ client id'); ?></label>
                        <input type="text" name="qq_client_id" id="qq_client_id" class="text-input" value="<?php echo get_safe_post() ? get_safe_post()['qq_client_id'] : CHV\Settings::get('qq_client_id', true); ?>">
                        <div class="input-warning red-warning"><?php echo get_input_errors()['qq_client_id']; ?></div>
                    </div>
                    <div class="input-label">
                        <label for="qq_client_secret"><?php _se('QQ client secret'); ?></label>
                        <input type="text" name="qq_client_secret" id="qq_client_secret" class="text-input" value="<?php echo get_safe_post() ? get_safe_post()['qq_client_secret'] : CHV\Settings::get('qq_client_secret', true); ?>">
                        <div class="input-warning red-warning"><?php echo get_input_errors()['qq_client_secret']; ?></div>
                    </div>
                </div>
            </div>    

6. 添加CSS样式文件(Adding style.css)

// app\themes\Peafowl\custom_hooks\
添加 style.css

7. 【重要】升级数据库(Upgrade database)

升级数据库

执行http://yourwebsite.com/install-qq 升级数据库,更新QQ登陆方式!

文件下载(Download)

隐藏内容

    点赞或回复此主题以查看隐藏的内容。

 

## Hash校验
MD5: FE7BD8CC6B6A3E4F7455A70C205FC568
SHA1: 354F49D7469BBCEF6AC1FAB0F6144D97CE7E8CC5
CRC32: D72A42DD

致谢(Thanks)

转自 松鼠博客

  • Like 1

分享这篇帖子


链接帖子

参与讨论

你现在可以发表并稍后注册。 如果你有帐户,现在就登录参与讨论。

游客
回复主题...

×   粘贴为富文本.   粘贴为纯文本来代替

  只允许使用75个表情符号.

×   你的链接已自动嵌入.   显示为链接来代替

×   你之前的内容已恢复.   清除编辑器

×   你无法直接粘贴图片。要从网址上传或插入图片。

登录关注  

×
×
  • 创建新的...