Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: show a button for OAuth login #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions AuthOAuth2.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand Down Expand Up @@ -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() {
Expand Down
8 changes: 8 additions & 0 deletions views/admin/authentication/Oauth2LoginButton.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div class="saml-container">
<div class="text-center"><?= $introductionText ?></div>
<div class="text-center">
<button type="submit" name="authMethod" value="AuthOAuth2" class="btn btn-primary">
<?= $buttonText ?>
</button>
</div>
</div>