Skip to content

Commit

Permalink
remodel the auth process using sendLoginReponse() like on VMT Dashb…
Browse files Browse the repository at this point in the history
…oard
  • Loading branch information
fredbradley committed Apr 11, 2024
1 parent 6d61c2f commit 91dcadd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
6 changes: 3 additions & 3 deletions app/Domains/SelfReflection/Http/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,22 @@ public function callbackSuccess(Request $request): RedirectResponse

$secret = $request->get('ffauth_secret');

$this->getUserData($secret);
return $this->getUserData($secret);

return redirect()->route('selfreflection.home');
}

/**
* @throws RequestException
*/
public function getUserData(string $secret): Authenticatable
public function getUserData(string $secret): RedirectResponse
{
$response = Http::get($this->url.'/login/api/sso', [
'ffauth_secret' => $secret,
'ffauth_device_id' => config('services.firefly.selfreflections.app'),
]);

$this->findOrCreateUserAndLogin($response->throw()->body());
return $this->findOrCreateUserAndLogin($response->throw()->body(), request());

return auth()->user();
}
Expand Down
6 changes: 3 additions & 3 deletions app/Http/Controllers/Auth/FireflyAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private function convertXmlToObject(string $xmlString): object
return json_decode($json);
}

private function findOrCreateUserAndLogin(string $xmlString): void
private function findOrCreateUserAndLogin(string $xmlString, Request $request): RedirectResponse
{
$obj = $this->convertXmlToObject($xmlString);

Expand All @@ -61,10 +61,10 @@ private function findOrCreateUserAndLogin(string $xmlString): void
}

// log them in
session()->flush();
Auth::login($existingUser, true);
$this->guard()->login($existingUser);
// Update db with login time
auth()->user()->update(['updated_at' => now()]);
return $this->sendLoginResponse($request);

// Let them know they've logged in
session()->flash('alert-success', 'You have logged in as: '.auth()->user()->name);
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ public function callbackSuccess(Request $request, string $school): RedirectRespo
'ffauth_secret' => $request->get('ffauth_secret'),
])->throw()->body();

$this->findOrCreateUserAndLogin($output);
return $this->findOrCreateUserAndLogin($output, $request);

return $this->sendLoginResponse($request);
return redirect('/submit');
}

Expand Down

0 comments on commit 91dcadd

Please sign in to comment.