Skip to content

Commit

Permalink
Merge pull request #2 from YesWiki/username_initials
Browse files Browse the repository at this point in the history
Allow display initials instead of username on login modal
  • Loading branch information
mrflos authored Apr 9, 2024
2 parents 0996265 + 04778af commit d58801b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## V1.1.1

Allow display initials instead of username on login modal

## V1.1.0

This extension is a replacement for the yeswiki-extension-login-sso,
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ After installation, you must add the following configuration in your waka.config
* don't declare it, if you don't need to have bazar entries related to users
*/
'bazar_user_entry_id' => 1000,
// if true, the display the initials of the user name instead of the full name on login modal
'login_username_initials' => false,
// each entry here is an array corresponding to a SSO provider
'providers' => [
[
Expand Down
16 changes: 15 additions & 1 deletion actions/LoginAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,13 @@ private function renderDefault(): string
}

$user = $this->authController->getLoggedUser();
$username = $user["name"] ?? '';
if($this->wiki->config['sso_config']['login_username_initials'] ?? false) {
$username = $this->nameInitials($username);
}
return $this->render('@loginsso/modal.twig', [
"connected" => !empty($user),
"user" => $user["name"] ?? '',
"user" => $username,
"email" => $user["email"] ?? '',
"providers" => $this->wiki->config['sso_config']['providers'],
"incomingUrl" => $this->wiki->request->getUri(),
Expand All @@ -92,6 +96,16 @@ private function renderDefault(): string
]);
}

private function nameInitials(string $name)
{
$name = explode(' ', $name);
$initials = '';
foreach ($name as $n) {
$initials .= mb_strtoupper($n[0]??'') . ' ';
}
return trim($initials);
}

private function redirectOAuth(int $providerId)
{
$provider = $this->getService(OAuth2ProviderFactory::class)->createProvider($providerId);
Expand Down

0 comments on commit d58801b

Please sign in to comment.