Skip to content

Commit

Permalink
Stop assuming "full name" in OAuth
Browse files Browse the repository at this point in the history
Per a bug report, if an OAuth account name doesn't use a real name,
CDash will 500 if a space doesn't exist in the name.

Check for the space before trying to separate into first and last names.
If no space, use the whole string as the first name.

Fixes: Kitware#2435
  • Loading branch information
josephsnyder committed Sep 9, 2024
1 parent 368303b commit 6edaf92
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion app/Http/Controllers/OAuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,14 @@ public function callback(string $service): RedirectResponse|Redirector
};

$email = $authUser->getEmail();
[$fname, $lname] = explode(" ", $authUser->getName() ?? '');
$name = $authUser->getName() ?? '';

// Check if name has space. Avoid issue where username = "Real" name
if(str_contains(" ", $name)) {
[$fname, $lname] = explode(" ", $name);
} else {
[$fname, $lname] = [$name, ""];
}

// TODO: What if, for whatever reason, there is more than one user found?
$user = User::firstWhere('email', $email);
Expand Down

0 comments on commit 6edaf92

Please sign in to comment.