Skip to content

Commit

Permalink
#238 Fix VATUSA external users login to realops
Browse files Browse the repository at this point in the history
  • Loading branch information
iccowan committed Dec 30, 2022
1 parent ee63aaa commit 317ebd2
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions app/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,19 @@ protected function verifyLogin(Request $request) {

protected function vatusaAuth($resourceOwner, $accessToken) {
$client = new Client();
$result = $client->request('GET', 'https://api.vatusa.net/v2/user/' . $resourceOwner->data->cid . '?apikey=' . Config::get('vatusa.api_key'));
$result = $client->request('GET', 'https://api.vatusa.net/v2/user/' . $resourceOwner->data->cid . '?apikey=' . Config::get('vatusa.api_key'), ['http_errors' => false]);
$realops_toggle_enabled = toggleEnabled('realops');

if (! $result || $result->getStatusCode() != 200) {
if ($realops_toggle_enabled) {
return $this->externalRealopsLogin(
$resourceOwner->data->cid,
$resourceOwner->data->personal->name_first,
$resourceOwner->data->personal->name_last,
$resourceOwner->data->personal->email
);
}

if (! $result) {
return redirect('/')->with('error', 'We are unable to verify your access at this time. Please try again in a few minutes.');
}

Expand All @@ -82,13 +92,12 @@ protected function vatusaAuth($resourceOwner, $accessToken) {
$res = $resu['data'];
$userstatuscheck = User::find($res['cid']);

$realops_toggle_enabled = toggleEnabled('realops');
if (! $realops_toggle_enabled && ! $userstatuscheck) {
return redirect('/')->with('error', 'You have not been found on the roster. If you have recently joined, please allow up to an hour for the roster to update.');
} elseif (! $realops_toggle_enabled && $userstatuscheck->status == 2) {
return redirect('/')->with('error', 'You have not been found on the roster. If you have recently joined, please allow up to an hour for the roster to update.');
} elseif (! $userstatuscheck || $userstatuscheck->status == 2) {
return $this->externalRealopsLogin($res);
return $this->externalRealopsLogin($res['cid'], $res['fname'], $res['lname'], $res['email']);
}

$userstatuscheck->fname = $res['fname'];
Expand Down Expand Up @@ -163,16 +172,16 @@ public function realopsLogin() {
return $this->completeRealopsLogin($realops_pilot);
}

private function externalRealopsLogin($data) {
$realops_pilot = RealopsPilot::find($data['cid']);
private function externalRealopsLogin($cid, $fname, $lname, $email) {
$realops_pilot = RealopsPilot::find($cid);

if (! $realops_pilot) {
$realops_pilot = new RealopsPilot;
}

$realops_pilot->fname = $data['fname'];
$realops_pilot->lname = $data['lname'];
$realops_pilot->email = $data['email'];
$realops_pilot->fname = $fname;
$realops_pilot->lname = $lname;
$realops_pilot->email = $email;
$realops_pilot->save();

return $this->completeRealopsLogin($realops_pilot);
Expand Down

0 comments on commit 317ebd2

Please sign in to comment.