diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php
index 1c26943f8..8f850195d 100644
--- a/app/Http/Controllers/Auth/LoginController.php
+++ b/app/Http/Controllers/Auth/LoginController.php
@@ -45,15 +45,29 @@ class LoginController extends Controller
$this->middleware('guest')->except('logout');
}
+ /**
+ * Logout function
+ *
+ * @return void
+ */
public function logout(Request $request) {
Auth::logout();
return redirect('/');
}
+ /**
+ * Redirect to the provider's website
+ *
+ * @return Socialite
+ */
public function redirectToProvider() {
return Socialite::driver('eveonline')->setScopes(['publicData'])->redirect();
}
+ /**
+ * Get token from callback
+ * Redirect to the dashboard if logging in successfully.
+ */
public function handleProviderCallback() {
$ssoUser = Socialite::driver('eveonline')->user();
@@ -78,7 +92,7 @@ class LoginController extends Controller
} else {
//Get what type of account the user should have
$accountType = $this->getAccountType($eve_user->refreshToken, $eve_user->getId());
-
+ //Create a user account
return User::create([
'name' => $eve_user->getName(),
'email' => null,
@@ -92,7 +106,15 @@ class LoginController extends Controller
]);
}
}
-
+
+ /**
+ * Gets the appropriate account type the user should be assigned through ESI API
+ *
+ * @param refreshToken
+ * @param charId
+ *
+ * @return text
+ */
private function getAccountType($refreshToken, $charId) {
//Set caching to null
$configuration = Configuration::getInstance();
@@ -117,7 +139,7 @@ class LoginController extends Controller
$corp_info = $esi->invoke('get', '/corporations/{corporation_id}/', [
'corporation_id' => $character_info->corporation_id,
]);
-
+ //Send back the appropriate group
if($corp_info->alliance_id == '99004116') {
return 'W4RP';
} else if(in_array($alliance_info->alliance_id, array(99006297, 498125261, 99003214, 99004136, 9900237, 99001657, 99006069, 99001099, 99003838))) {
diff --git a/app/Http/Controllers/DashboardController.php b/app/Http/Controllers/DashboardController.php
index 75bd900ec..210c01ff9 100644
--- a/app/Http/Controllers/DashboardController.php
+++ b/app/Http/Controllers/DashboardController.php
@@ -4,8 +4,6 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Library;
-//use Illuminate\Foundation\Validation\ValidatesRequests;
-//use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
@@ -36,48 +34,7 @@ class DashboardController extends Controller
}
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() {
diff --git a/app/Library/EsiLogin.php b/app/Library/EsiLogin.php
deleted file mode 100644
index 294df6629..000000000
--- a/app/Library/EsiLogin.php
+++ /dev/null
@@ -1,306 +0,0 @@
-clientId = env('ESI_CLIENT_ID');
- $this->secretKey = env('ESI_SECRET_KEY');
- $this->useragent = env('ESI_USERAGENT');
- $this->scope = env('ESI_SCOPES');
- //$this->clientId = $fileEsi['client_id'];
- //$this->secretKey = $fileEsi['secret'];
- //$this->useragent = $fileEsi['useragent'];
- } else {
- $this->clientId = $client;
- $this->secretKey = $secret;
- $this->userAgent = $useragent;
- }
- }
-
- public function GetCharacterId() {
- return $this->characterId;
- }
-
- public function GetCharacterName() {
- return $this->characterName;
- }
-
- public function GetCorporationId() {
- return $this->corporationId;
- }
-
- public function GetCorporationName() {
- return $this->corporationName;
- }
-
- public function GetAllianceId() {
- return $this->allianceId;
- }
-
- public function GetAllianceName() {
- return $this->allianceName;
- }
-
- public function GetAccessToken() {
- return $this->accessToken;
- }
-
- public function GetRefreshToken() {
- return $this->refreshToken;
- }
-
- public function GetRefreskTokenExpiry() {
- return $this->refreshTokenExpiry;
- }
-
- public function SetAccessToken($access) {
- $this->accessToken = $access;
- }
-
- public function SetRefreshtoken($refresh) {
- $this->refreshToken = $refresh;
- }
-
- public function SetRefreshTokenExpiry($expire) {
- $this->refreshTokenExpiry = $expire;
- }
-
- public function ESIStateMachine($state) {
-
- switch($state) {
- case 'new':
- return $this->DisplayLoginButton();
- break;
- case 'eveonlinecallback':
- $this->VerifyCallback();
- if($this->logged == true) {
- return 'logged';
- } else {
- return 'notlogged';
- }
- break;
- default:
- $this->UnsetState();
- break;
- }
- }
-
- public function VerifyCallback() {
- if($this->CheckState() == 'okay') {
- $this->RetrieveAccessToken();
- $this->RetrieveCharacterId();
-
- //Get all the information we might need, and store it
- $char = $this->GetESIInfo($this->characterId, 'Character', $this->useragent);
- $this->characterName = $char['name'];
-
- $corp = $this->GetESIInfo($char['corporation_id'], 'Corporation', $this->useragent);
- $this->corporationId = $char['corporation_id'];
- $this->corporationName = $corp['name'];
-
- if(isset($corp['alliance_id'])) {
- $ally = $this->GetESIInfo($corp['alliance_id'], 'Alliance', $this->useragent);
- $this->allianceId = $corp['alliance_id'];
- $this->allianceName = $ally['name'];
- }
- } else {
- $this->logged = false;
- }
-
- if($this->characterId != null) {
- $this->logged = true;
- } else {
- $this->logged = false;
- }
- }
-
- public function DisplayLoginButton($state) {
- $html = "";
- $html .= "";
- $html .= "
";
- $html .= "
";
- $html .= "
";
- return $html;
- }
-
- public function CheckState($newState) {
- if($newState != session('state')) {
- $this->UnsetState();
- return false;
- } else {
- return true;
- }
- }
-
- public function UnsetState() {
- Session::forget('state');
- }
-
- public function RetrieveCharacterId() {
- $url = 'https://login.eveonline.com/oauth/verify';
- $header = 'Authorization: Bearer ' . $this->accessToken;
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_USERAGENT, $this->useragent);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array($header));
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
- $result = curl_exec($ch);
- $data = json_decode($result, true);
-
- $this->characterId = $data['CharacterID'];
- $this->characterName = $data['CharacterName'];
- $this->tokenType = $data['TokenType'];
- }
-
- public function RetrieveAccessToken() {
- Session::forget('key');
- $url = 'https://login.eveonline.com/oauth/token';
- $header = 'Authorization: Basic ' . base64_encode($this->clientId . ':' . $this->secretKey);
- $fields_string='';
- $fields = array(
- 'grant_type' => 'authorization_code',
- 'code' => $_GET['code']
- );
- foreach($fields as $key => $value) {
- $fields_string .= $key . '=' . $value . '&';
- }
- rtrim($fields_string . '&');
- //Initialize the curl channel
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_USERAGENT, $this->useragent);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array($header));
- curl_setopt($ch, CURLOPT_POST, count($fields));
- curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
- $result = curl_exec($ch);
- curl_close($ch);
- $data = json_decode($result, true);
- $this->accessToken = $data['access_token'];
- $this->refreshToken = $data['refresh_token'];
- $this->refreshTokenExpiry = time() + $data['expires_in'];
- }
-
- public function RefreshAccess() {
- $url = 'https://login.eveonline.com/oauth/token';
- $header = 'Authorization: Basic ' . base64_encode($this->clientId . ':' . $this->secretKey);
- $fields_string = '';
- $fields = array(
- 'grant_type' => 'refresh_token',
- 'refresh_token' => $this->refreshToken
- );
-
- foreach($fields as $key => $value) {
- $fields_string .= $key . '=' . $value . '&';
- }
- rtrim($fields_string, '&');
- //Initialize the cURL connection
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_USERAGENT, $this->userAgent);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array($header));
- curl_setopt($ch, CURLOPT_POST, count($fields));
- curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
- $result = curl_exec($ch);
- //Get the resultant data from the curl call in an array format
- $data = json_decode($result, true);
- //Modify the variables of the class
- $this->refreshToken = $data['refresh_token'];
- $this->refreshTokenExpiry = now() + $data['expires_in'];
- $this->accessToken = $data['access_token'];
- }
-
- public function GetESIInfo($id, $type, $useragent = null) {
- if($useragent == null) {
- $useragent = $this->useragent;
- }
- $url = $this->BuildSingleUrl($type, $id);
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json'));
- curl_setopt($ch, CURLOPT_HTTPGET, true);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
- $result = curl_exec($ch);
- //Check for a curl error
- if(curl_error($ch)) {
- return null;
- } else {
- curl_close($ch);
- $data = json_decode($result, true);
- return $data;
- }
- }
-
- private function BuildSingleUrl($type, $id) {
- $firstPart = 'https://esi.tech.ccp.is/latest/';
- $lastPart = '/?datasource=tranquility';
-
- if($type == 'Character') {
- $url = $firstPart . 'characters/' . $id . $lastPart;
- } else if ($type == 'Corporation') {
- $url = $firstPart . 'corporations/' . $id . $lastPart;
- } else if ($type == 'Alliance') {
- $url = $firstPart . 'alliances/' . $id . $lastPart;
- }
-
- return $url;
- }
-}
\ No newline at end of file
diff --git a/app/Library/MoonCalc.php b/app/Library/MoonCalc.php
index 8c2aaa217..0200c9c3e 100644
--- a/app/Library/MoonCalc.php
+++ b/app/Library/MoonCalc.php
@@ -9,6 +9,7 @@ namespace App\Library;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Session;
+use DB;
class MoonCalc {
@@ -21,7 +22,7 @@ class MoonCalc {
//Total pull size is 14,385,600 m3
$totalPull = 5.55 * (3600.00 * 24.00 * 30.00);
//Get the configuration for pricing calculations
- $config = $db->fetchRow('SELECT * FROM Config');
+ $config = DB::table('Config')->get();
if($firstQuan >= 1.00) {
$firstPerc = $firstQuan / 100.00;
} else {
@@ -43,52 +44,54 @@ class MoonCalc {
$fourthPerc = $fourthQuan;
}
if($firstOre != "None") {
- $m3Size = $db->fetchColumn('SELECT m3Size FROM ItemComposition WHERE Name= :name', array('name' => $firstOre));
+ $m3Size = DB::table('ItemComposition')->where('Name', $firstOre)->value('m3Size');
+ //$m3Size = $db->fetchColumn('SELECT m3Size FROM ItemComposition WHERE Name= :name', array('name' => $firstOre));
//Find the m3 value of the first ore
$firstActualm3 = floor($firstPerc * $totalPull);
//Calculate the units of the first ore
$firstUnits = floor($firstActualm3 / $m3Size);
//Get the unit price from the database
- $firstUnitPrice = $db->fetchColumn('SELECT UnitPrice FROM OrePrices WHERE Name= :name', array('name'=> $firstOre));
+ $firstUnitPrice = DB::table('OrePrices')->where('UnitPrice', $firstOre)->value('UnitPrice');
+ //$firstUnitPrice = $db->fetchColumn('SELECT UnitPrice FROM OrePrices WHERE Name= :name', array('name'=> $firstOre));
//Calculate the total price for the first ore
$firstTotal = $firstUnits * $firstUnitPrice;
} else {
$firstTotal = 0.00;
}
if($secondOre != "None") {
- $m3Size = $db->fetchColumn('SELECT m3Size FROM ItemComposition WHERE Name= :name', array('name' => $secondOre));
+ $m3Size = DB::table('ItemComposition')->where('Name', $secondOre)->value('m3Size');
//find the m3 value of the second ore
$secondActualm3 = floor($secondPerc * $totalPull);
//Calculate the units of the second ore
$secondUnits = floor($secondActualm3 / $m3Size);
//Get the unit price from the database
- $secondUnitPrice = $db->fetchColumn('SELECT UnitPrice FROM OrePrices WHERE Name= :name', array('name' => $secondOre));
+ $secondUnitPrice = DB::table('OrePrices')->where('UnitPrice', $secondOre)->value('UnitPrice');
//calculate the total price for the second ore
$secondTotal = $secondUnits * $secondUnitPrice;
} else {
$secondTotal = 0.00;
}
if($thirdOre != "None") {
- $m3Size = $db->fetchColumn('SELECT m3Size FROM ItemComposition WHERE Name= :name', array('name' => $thirdOre));
+ $m3Size = DB::table('ItemComposition')->where('Name', $thirdOre)->value('m3Size');
//find the m3 value of the third ore
$thirdActualm3 = floor($thirdPerc * $totalPull);
//calculate the units of the third ore
$thirdUnits = floor($thirdActualm3 / $m3Size);
//Get the unit price from the database
- $thirdUnitPrice = $db->fetchColumn('SELECT UnitPrice FROM OrePrices WHERE Name= :name', array('name' => $thirdOre));
+ $thirdUnitPrice = DB::table('OrePrices')->where('UnitPrice', $thirdOre)->value('UnitPrice');
//calculate the total price for the third ore
$thirdTotal = $thirdUnits * $thirdUnitPrice;
} else {
$thirdTotal = 0.00;
}
if($fourthOre != "None") {
- $m3Size = $db->fetchColumn('SELECT m3Size FROM ItemComposition WHERE Name= :name', array('name' => $fourthOre));
+ $m3Size = DB::table('ItemComposition')->where('Name', $fourthOre)->value('m3Size');
//Find the m3 value of the fourth ore
$fourthActualm3 = floor($fourthPerc * $totalPull);
//Calculate the units of the fourth ore
$fourthUnits = floor($fourthActualm3 / $m3Size);
//Get the unit price from the database
- $fourthUnitPrice = $db->fetchColumn('SELECT UnitPrice FROM OrePrices WHERE Name= :name', array('name' => $fourthOre));
+ $fourthUnitPrice = DB::table('OrePrices')->where('UnitPrice', $fourthOre)->value('UnitPrice');
//calculate the total price for the fourth ore
$fourthTotal = $fourthUnits * $fourthUnitPrice;
} else {
@@ -97,7 +100,7 @@ class MoonCalc {
//Calculate the total to price to be mined in one month
$totalPriceMined = $firstTotal + $secondTotal + $thirdTotal + $fourthTotal;
//Calculate the rental price. Refined rate is already included in the price from rental composition
- $rentalPrice = $totalPriceMined * ($config['RentalTax'] / 100.00);
+ $rentalPrice = $totalPriceMined * ($config->RentalTax / 100.00);
//Format the rental price to the appropriate number
$rentalPrice = number_format($rentalPrice, "2", ".", ",");
@@ -114,15 +117,15 @@ class MoonCalc {
$browser = false;
printf("Running price update from command line.\n");
}
- $db = DBOpen();
+
//Get the configuration from the config table
- $config = $db->fetchRow('SELECT * FROM Config');
+ $config = DB::table('Config')->get();
//Calculate refine rate
- $refineRate = $config['RefineRate'] / 100.00;
+ $refineRate = $config->RefineRate / 100.00;
//Calculate the current time
$time = time();
//Get the max time from the database
- $maxTime = $db->fetchColumn('SELECT MAX(Time) FROM Prices WHERE ItemId= :id', array('id' => 34));
+ $maxTime = DB::select('SELECT MAX(Time) FROM Prices WHERE ItemId = ?', [34]);
//Get the price of the basic minerals
$tritaniumPrice = $db->fetchColumn('SELECT Price FROM Prices WHERE ItemId= :id AND Time= :time', array('id' => 34, 'time' => $maxTime));
$pyeritePrice = $db->fetchColumn('SELECT Price FROM Prices WHERE ItemId= :id AND Time= :time', array('id' => 35, 'time' => $maxTime));