Skip to content

Commit

Permalink
CIL-793 For the OAuth 1.0a flow, check for missing first_name or last…
Browse files Browse the repository at this point in the history
…_name. If so, use display_name to split on space like we used to.
  • Loading branch information
terrencegf committed Aug 24, 2020
1 parent ab7cdd6 commit 870b1ee
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/Service/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -1266,4 +1266,54 @@ public static function getLOAPort()
}
return $port;
}

/**
* getFirstAndLastName
*
* This function attempts to get the first and last name of a user
* extracted from the 'full name' (displayName) of the user.
* Simply pass in all name info (full, first, and last) and the
* function first tries to break up the full name into first/last.
* If this is not sufficient, the function checks first and last
* name. Finally, if either first or last is blank, the function
* duplicates first <=> last so both names have the same value.
* Note that even with all this, you still need to check if the
* returned (first,last) names are blank.
*
* @param string $full The 'full name' of the user
* @param string $first (Optional) The 'first name' of the user
* @param string $last (Optional) The 'last name' of the user
* @return array An array 'list(firstname,lastname)'
*/
public static function getFirstAndLastName($full, $first = '', $last = '')
{
$firstname = '';
$lastname = '';

# Try to split the incoming $full name into first and last names
if (strlen($full) > 0) {
$names = preg_split('/\s+/', $full, 2);
$firstname = @$names[0];
$lastname = @$names[1];
}

# If either first or last name blank, then use incoming $first and $last
if (strlen($firstname) == 0) {
$firstname = $first;
}
if (strlen($lastname) == 0) {
$lastname = $last;
}

# Finally, if only a single name, copy first name <=> last name
if (strlen($lastname) == 0) {
$lastname = $firstname;
}
if (strlen($firstname) == 0) {
$firstname = $lastname;
}

# Return both names as an array (i.e., use list($first,last)=...)
return array($firstname,$lastname);
}
}

0 comments on commit 870b1ee

Please sign in to comment.