<commit_before><?php

namespace App\Http\Controllers\Home;

use App\User;
use App\UserLogin\OtherLogin;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Overtrue\Socialite\SocialiteManager;

class LoginController extends Controller
{
    protected $login;

    public function __construct(OtherLogin $login)
    {
        $this->login = $login;
    }

    protected $config = [
        'weibo' => [
            'client_id' => '2630420162',
            'client_secret' => 'caa3a434be7ca19afe80197eea1d9db1',
            'redirect' => 'https://kobeman.com/weibo/login'
        ],
        'qq' => [
            'client_id' => '1105724901',
            'client_secret' => '<KEY>',
            'redirect' => 'http://localhost:8000/qq/login'
        ],
        'github' => [
            'client_id' => '81ef36deca1d9eb5298b',
            'client_secret' => '<KEY>',
            'redirect' => 'http://localhost:8000/github/login'
        ],
        'weixin' => [
            'client_id' => '81ef36deca1d9eb5298b',
            'client_secret' => '<KEY>',
            'redirect' => 'http://localhost:8000/weixin/login'
        ],
    ];

    public function driver($style)
    {
        $socialite = new SocialiteManager($this->config);
        return $socialite->driver($style)->redirect();
    }

    public function githubLogin()
    {
//        $this->login->githubLogin($this->config);

        $socialite = new SocialiteManager($this->config);
        $githubUser = $socialite->driver('github')->user();//user就可以拿到igthub的公共信息

        //第一次用户登录
        $loginUser = User::where('social_type', 'github')->where('social_id', $githubUser->getId())->first();
        //如果没有查到这个用户 重定向到首页
        if (!is_null($loginUser)) {
            \Auth::loginUsingId($loginUser->id);
            return redirect('/');
        }
        $user = [
            'name' => $githubUser->getNickName(),
            'email' => $githubUser->getEmail(),
            'password' => <PASSWORD>(<PASSWORD>_<PASSWORD>(16)),
            'social_type' => 'github',
            'social_id' => $githubUser->getId()
        ];
        $data = [
            'is_confirmed' => 1,
            'confirm_code' => str_random(48),
            'avatar' => $githubUser->getAvatar(),
        ];
        $newUser = User::create(array_merge($user, $data));
        \Auth::loginUsingId($newUser->id);
        return redirect('/');
    }

    public function weiboLogin()
    {
        $socialite = new SocialiteManager($this->config);
        $githubUser = $socialite->driver('weibo')->user();//user就可以拿到igthub的公共信息

        //第一次用户登录
        $loginUser = User::where('social_type', 'weibo')->where('social_id', $githubUser->getId())->first();
        //如果没有查到这个用户 重定向到首页
        if (!is_null($loginUser)) {
            \Auth::loginUsingId($loginUser->id);
            return redirect('/');
        }
        $user = [
            'name' => $githubUser->getNickName(),
            'email' => $githubUser->getEmail(),
            'password' => <PASSWORD>(<PASSWORD>(16)),
            'social_type' => 'weibo',
            'social_id' => $githubUser->getId()
        ];
        $data = [
            'is_confirmed' => 1,
            'confirm_code' => str_random(48),
            'avatar' => $githubUser->getAvatar(),
        ];
        $newUser = User::create(array_merge($user, $data));
        \Auth::loginUsingId($newUser->id);
        return redirect('/');
    }<commit_msg>otherlogin<commit_after><?php

namespace App\Http\Controllers\Home;

use App\User;
use App\UserLogin\OtherLogin;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Overtrue\Socialite\SocialiteManager;

class LoginController extends Controller
{
    protected $login;

    public function __construct(OtherLogin $login)
    {
        $this->login = $login;
    }

    protected $config = [
        'weibo' => [
            'client_id' => '2630420162',
            'client_secret' => 'caa3a434be7ca19afe80197eea1d9db1',
            'redirect' => 'https://kobeman.com/weibo/login'
        ],
        'qq' => [
            'client_id' => '1105724901',
            'client_secret' => '<KEY>',
            'redirect' => 'http://localhost:8000/qq/login'
        ],
        'github' => [
            'client_id' => '81ef36deca1d9eb5298b',
            'client_secret' => '<KEY>',
            'redirect' => 'http://localhost:8000/github/login'
        ],
        'weixin' => [
            'client_id' => '81ef36deca1d9eb5298b',
            'client_secret' => '<KEY>',
            'redirect' => 'http://localhost:8000/weixin/login'
        ],
    ];

    public function driver($style)
    {
        $socialite = new SocialiteManager($this->config);
        return $socialite->driver($style)->redirect();
    }

    public function githubLogin()
    {
//        $this->login->githubLogin($this->config);

        $socialite = new SocialiteManager($this->config);
        $githubUser = $socialite->driver('github')->user();//user就可以拿到igthub的公共信息

        //第一次用户登录
        $loginUser = User::where('social_type', 'github')->where('social_id', $githubUser->getId())->first();
        //如果没有查到这个用户 重定向到首页
        if (!is_null($loginUser)) {
            \Auth::loginUsingId($loginUser->id);
            return redirect('/');
        }
        $user = [
            'name' => $githubUser->getNickName(),
            'email' => $githubUser->getEmail(),
            'password' => <PASSWORD>(<PASSWORD>)),
            'social_type' => 'github',
            'social_id' => $githubUser->getId()
        ];
        $data = [
            'is_confirmed' => 1,
            'confirm_code' => str_random(48),
            'avatar' => $githubUser->getAvatar(),
        ];
        $newUser = User::create(array_merge($user, $data));
        \Auth::loginUsingId($newUser->id);
        return redirect('/');
    }

    public function weiboLogin()
    {
        $socialite = new SocialiteManager($this->config);
        $githubUser = $socialite->driver('weibo')->user();//user就可以拿到igthub的公共信息

        //第一次用户登录
        $loginUser = User::where('social_type', 'weibo')->where('social_id', $githubUser->getId())->first();
        //如果没有查到这个用户 重定向到首页
        if (!is_null($loginUser)) {
            \Auth::loginUsingId($loginUser->id);
            return redirect('/');
        }
        $user = [
            'name' => $githubUser->getNickName(),
            'email' =>'<EMAIL>',
            'password' => <PASSWORD>(<PASSWORD>)),
            'social_type' => 'weibo',
            'social_id' => $githubUser->getId()
        ];
        $data = [
            'is_confirmed' => 1,
            'confirm_code' => str_random(48),
            'avatar' => $githubUser->getAvatar(),
        ];
        $newUser = User::create(array_merge($user, $data));
        \Auth::loginUsingId($newUser->id);
        return redirect('/');
    }
{'fraction_non_alphanumeric': 0.17490882567469002, 'fraction_numerical': 0.02188183807439825, 'mean_word_length': 2.1550851357570178, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 144, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7580070', 'n_tokens_mistral': 2273, 'n_tokens_neox': 2188, 'n_words': 304}