• laravel 中使用tinker 验证驱动加载是否成功


    在验证laravel 中   InvalidArgumentException Driver [WeiBo] not supported.

     public function weibo()
        {
            return Socialite::driver('weibo')->redirect();
            // return \Socialite::with('WeiBo')->scopes(array('email'))->redirect();
        }
    public function callback()
        {
            /*$code=request('code');
            dd($code);*/
            $oauthUser = Socialite::driver('weibo')->user();
    //        dd($oauthUser);
            $sina_id = (int)$oauthUser->getId();
            $name = $oauthUser->getName();
            $nickname = $oauthUser->getNickname();
            $email = $oauthUser->getEmail();
            $sina_avatar = $oauthUser->getAvatar();
    
            /* //从 Token(OAuth2)中获取用户信息
             $token = $oauthUser->token;
             $user = Socialite::driver('WeiBo')->userFromToken($token);
             dd($user);*/
    
            $where['sina_id'] = $sina_id;
            $userDetail = ThirdLogin::where($where)->first();
            //若sina_id用户不存在,向third_login表中添加用户信息的同时,向user表中也添加条信息,
            //将user信息与third_login,方便前台登录查询
            if (empty($userDetail)) {
                $user = ThirdLogin::create(compact('sina_id', 'name', 'nickname', 'email', 'sina_avatar'));
    
                $name = $user->nickname;
                $avatar = $user->sina_avatar;
                $email = $user->email;
                $third_id = $user->sina_id;
                $password = 0;
                User::create(compact('name', 'password', 'email', 'avatar', 'third_id'));
    
                //使用Auth::login(实例,true)授权登录  ,这部分代码不能拿出去优化
                $is_user = user::where('third_id', $user->sina_id)->first();
                Auth::login($is_user, $remember = false);
                if (\Auth::check()) {//授权成功
                    return \redirect('/posts');
                } else {
                    return \Redirect::back()->withErrors('授权失败');
                }
    //            User::third_login($user);
            } else {
    
                $is_user = user::where('third_id', $userDetail->sina_id)->first();
                Auth::login($is_user, $remember = false);
                if (\Auth::check()) {//授权成功
                    return \redirect('/posts');
                } else {
                    return \Redirect::back()->withErrors('授权失败');
                }
    
    //            User::third_login($userDetail);
    //          return Redirect::back()->withErrors('微博用户'.$userDetail->nickname.'已存在');
            }
    
    
        }
    

  • 相关阅读:
    TCP四种定时器--学习笔记
    Python魔术师--self
    python的socket里 gethostbyname 与 gethostbyname_ex 的区别
    用python查看URL编码的中文
    基于linux 的2048
    用灵活的指针访问类私有变量
    ie8无法拉伸背景图
    图片的onerror 事件解析
    stream.js
    Promise
  • 原文地址:https://www.cnblogs.com/lxwphp/p/15454068.html
Copyright © 2020-2023  润新知