public function callback() { $code = Input::get('code'); if (strlen($code) == 0) { return \Redirect::to('/'); } $facebook = new Facebook(\Config::get('facebook')); $uid = $facebook->getUser(); if ($uid == 0) { return \Redirect::to('/'); } $me = $facebook->api('/me'); $profile = User::where('user_id', $uid)->first(); if (empty($profile)) { $user = new User(); $user->username = $me['name']; $user->photo = 'https://graph.facebook.com/' . $me['id'] . '/picture?type=large'; $user->user_id = $uid; $user->save(); $x = new leaderboard(); $x->user_id = $uid; $x->user_name = $me['name']; $x->round_id = 1; $x->save(); } $user = User::where('user_id', $uid)->select('user_id', 'username', 'photo')->first(); session()->put(['user_id' => $uid, 'name' => $user['username']]); return redirect('/'); }
public function start() { $x = leaderboard::where('user_id', session('user_id'))->select('round_id')->first(); $x = $x['round_id']; return redirect(url('/round/' . $x)); }
return Redirect::to($facebook->getLoginUrl($params)); }); Route::get('login/fb/callback', function () { $code = Input::get('code'); if (strlen($code) == 0) { return \Redirect::to('/'); } $facebook = new Facebook(\Config::get('facebook')); $uid = $facebook->getUser(); if ($uid == 0) { return \Redirect::to('/'); } $me = $facebook->api('/me'); $profile = User::where('user_id', $uid)->first(); if (empty($profile)) { $user = new User(); $user->username = $me['name']; $user->photo = 'https://graph.facebook.com/' . $me['id'] . '/picture?type=large'; $user->user_id = $uid; $user->save(); $x = new leaderboard(); $x->user_id = $uid; $x->user_name = $me['name']; $x->round_id = 1; $x->save(); } $user = User::where('user_id', $uid)->select('user_id', 'username', 'photo')->first(); session()->put(['user_id' => $uid, 'name' => $user['username']]); return redirect('/'); }); });
public function nextround(Request $request, $id) { if ($id > $this->mxround) { return 'Congrats !! you have completed the quiz'; } $rans = roundans::where('round_id', $id)->first(); $ans = $request->input('ansr'); $utoken = session('user_id'); if (strcasecmp($rans['answer'], $ans) == 0) { $id++; leaderboard::where('user_id', $utoken)->update(['round_id' => $id]); return redirect(url('/round/' . $id)); } else { return redirect(url('/round/' . $id)); } }