From aaa5d32f6d29a191055e92b6ad62dc599d0b6d84 Mon Sep 17 00:00:00 2001 From: Denis Chenu Date: Wed, 3 Jul 2024 16:25:52 +0200 Subject: [PATCH] Feature: show a button for OAuth login --- AuthOAuth2.php | 34 +++++++++++++++++-- .../authentication/Oauth2LoginButton.php | 8 +++++ 2 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 views/admin/authentication/Oauth2LoginButton.php diff --git a/AuthOAuth2.php b/AuthOAuth2.php index 7cf4709..6f554f4 100644 --- a/AuthOAuth2.php +++ b/AuthOAuth2.php @@ -103,6 +103,20 @@ public function __construct(PluginManager $manager, $id) { 'help' => $this->gT('If enabled users that do not exist yet will be created in LimeSurvey after successfull login.'), 'default' => false, ], + 'introduction_text' => [ + 'type' => 'string', + 'htmlOptions' => [ + 'placeholder' => $this->gT('Login with Oauth2'), + ], + 'label' => $this->gT('Introduction to the OAuth login button.'), + ], + 'button_text' => [ + 'type' => 'string', + 'htmlOptions' => [ + 'placeholder' => $this->gT('Login'), + ], + 'label' => $this->gT('Text on login button.'), + ], ]; if (method_exists(Permissiontemplates::class, 'applyToUser')) { @@ -193,8 +207,24 @@ public function init() { } public function newLoginForm() { - // we need to add content to be added to the auth method selection - $this->getEvent()->getContent($this)->addContent(''); + $oEvent = $this->getEvent(); + $introductionText = viewHelper::purified(trim($this->get('introduction_text'))); + if (empty($introductionText)) { + $introductionText = $this->gT("Login with Oauth2"); + } + $buttonText = viewHelper::purified(trim($this->get('button_text'))); + if (empty($buttonText)) { + $buttonText = $this->gT("Login"); + } + $aData = [ + 'introductionText' => $introductionText, + 'buttonText' => $buttonText, + ]; + $authContent = $content = $this->renderPartial('admin.authentication.Oauth2LoginButton', $aData, true); + $allFromsContent = $oEvent->getAllContent(); + foreach($allFromsContent as $plugin => $content) { + $oEvent->getContent($plugin)->addContent($authContent, 'prepend'); + } } public function beforeLogin() { diff --git a/views/admin/authentication/Oauth2LoginButton.php b/views/admin/authentication/Oauth2LoginButton.php new file mode 100644 index 0000000..0c239ec --- /dev/null +++ b/views/admin/authentication/Oauth2LoginButton.php @@ -0,0 +1,8 @@ +
+
+
+ +
+