middleware('auth'); } /** * Show the application dashboard. * * @return \Illuminate\Http\Response */ public function index() { return view('dashboard'); } public function addMoon() { return view('dashboard.addmoon'); } public function profile() { /** * Check to see if the user has a valid esi token */ $user = Auth::user(); //Try to find the user's ESI token. $token = DB::table('esitokens')->where('CharacterId', $user['character_id'])->first(); if($token != null) { $html = '

ESI Token Already Stored

'; } else { //Setup the display button if the user doesn't have an ESI registered $state = uniqid(); session(['state' => $state]); $esiLogin = new \App\Library\EsiLogin(); $html = $esiLogin->DisplayLoginButton($state); } return view('dashboard.profile')->with('html', $html); } public function callback(Request $request) { $esiLogin = new \App\Library\EsiLogin(); //Pull the old session state from the session, and delete the key $oldState = $request->session()->pull('state'); //Check the state to make sure it matches if($oldState == $request->input('state')) { $esiLogin->RetrieveAccessToken(); $esiLogin->RetrieveCharacterId(); //Store the token in the database $token = new \App\EsiToken; $token->CharacterId = $esiLogin->GetCharacterId(); $token->AccessToken = $esiLogin->GetAccessToken(); $token->RefreshToken = $esiLogin->GetRefreshToken(); $token->ExpiresIn = $esiLogin->GetRefreskTokenExpiry(); $token->save(); //Return view back to profile with success message return view('dashboard')->with('message', 'Success!'); } else { //Return view with error message back to the dashboard return view('dashboard')->with('message', 'Error!'); } } public function displayMoons() { $moons = DB::table('moons')->get(); return 'Moons Display Table'; } }