From 04778af18f542fb0cd0a150a8c53f315e2c7b762 Mon Sep 17 00:00:00 2001 From: Sylvain Lehmann Date: Tue, 9 Apr 2024 15:42:07 +0200 Subject: [PATCH] feat(loginsso): allow display initials instead of username on login modal --- CHANGELOG.md | 4 ++++ README.md | 2 ++ actions/LoginAction.php | 16 +++++++++++++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a09fda..8ddecfd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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, diff --git a/README.md b/README.md index 2e71f00..6f14c41 100644 --- a/README.md +++ b/README.md @@ -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' => [ [ diff --git a/actions/LoginAction.php b/actions/LoginAction.php index 760e0f6..9dd5571 100644 --- a/actions/LoginAction.php +++ b/actions/LoginAction.php @@ -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(), @@ -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);