*/ Route::get('/google/authorize', function () { return SocialAuth::authorize('google'); }); Route::get('/google/login', function () { try { SocialAuth::login('google', function ($user, $userDetails) { // is "host domain" correct? if ($userDetails->raw['hd'] == 'cognize.org') { // is user staff? if ($staffCheck = \ATC\Staff::where('external_id', '=', $userDetails->email)->first()) { $user->email = $userDetails->email; $user->name = $userDetails->full_name; $user->role = 'staff'; $user->save(); } elseif ($studentCheck = \ATC\Student::where('external_id', '=', $userDetails->email)->first()) { $user->email = $userDetails->email; $user->name = $userDetails->full_name; $user->role = 'student'; $user->save(); } else { Session::flash('http_status', 'No such user'); abort(403, 'Forbbiden'); } } else { Session::flash('http_status', 'Domain not allowed'); abort(403, 'Forbbiden'); } }); } catch (ApplicationRejectedException $e) { // User rejected application
/** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function showStudentCourse($id) { // get id of logged in student $studentId = \ATC\Student::where('external_id', '=', \Auth::user()->email)->get()->first()->id; return $this->show($studentId, $id); }