Esempio n. 1
0
 public function getCallback()
 {
     $type = $this->request()->segment(3);
     $info = Socialite::driver($type)->user();
     dd($info);
     //已经在本站注册
     if ($bind = UserBind::openId($info->getId())->first()) {
         $user = User::find($bind->user_id);
         //更新accessToken和过期时间
         $bind->update(array('access_token' => $info->token));
         //登录成功,跳转到登录前页面
         Auth::login($user);
         return $this->redirect()->intended('/');
     } else {
         //还没有在本站注册,跳转到账号绑定页面
         $info->from = $type;
         Session::put('social-info', $info);
         return $this->redirect('/socialite/bind');
     }
 }
Esempio n. 2
0
 public function postLogin()
 {
     //验证字段有效性
     $this->validate($this->request(), $rules = array('mobile' => 'required|digits:11|exists:users', 'password' => 'required|min:6'), $message = ['mobile.exists' => '该手机号不存在', 'mobile.required' => '手机号不能为空', 'mobile.digits' => '手机号格式不正确', 'password.required' => '密码不能为空', 'password.min' => '密码最少6位'], $customAttributes = []);
     $credentials = $this->request()->only(['mobile', 'password']);
     $bindinfo = $this->request()->only('openid');
     if (Auth::attempt($credentials)) {
         $bindinfo['user_id'] = Auth::user()->user_id;
         $user_id = UserBind::where('user_id', $bindinfo['user_id'])->exists();
         //判断用户是否已经绑定,绑定更新openid,未绑定创建绑定
         if ($user_id) {
             $bind = UserBind::where('user_id', '=', $bindinfo['user_id'])->first();
             $bind->openid = $bindinfo['openid'];
             $bind->save();
         } else {
             UserBind::create($bindinfo);
         }
         return "<script>alert('绑定成功,请关闭当前页面');\n\t\t\t\t//</script>";
     }
     return $this->error('手机号或密码不正确');
 }