From 57cd40803b0625cdbc3848a44390c53a09c15965 Mon Sep 17 00:00:00 2001 From: Alexander Bias Date: Sun, 10 Dec 2023 13:43:59 +0100 Subject: [PATCH] Feature: Allow the admin to hide the manual login form, solves #490. --- CHANGES.md | 1 + README.md | 10 +++++ classes/output/core_renderer.php | 42 +++++++++++++++++++ lang/en/theme_boost_union.php | 8 ++++ settings.php | 20 +++++++++ templates/core/loginform.mustache | 12 +++++- ...boost_union_looksettings_loginpage.feature | 39 +++++++++++++++++ version.php | 2 +- 8 files changed, 132 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index ad5897382b4..08c1c47250f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,6 +6,7 @@ Changes ### Unreleased +* 2023-12-10 - Feature: Allow the admin to hide the manual login form and the IDP login intro, solves #490. * 2023-12-10 - Improvement: Allow the admin to change the look of the course overview block, solves #204 ### v4.3-r3 diff --git a/README.md b/README.md index edcfbd41e26..f8d6be8a72f 100644 --- a/README.md +++ b/README.md @@ -185,6 +185,16 @@ With this setting, you can optimize the login form to fit to a greater variety o With this setting, you can make the login form slightly transparent to let the background image shine through even more. +#### Login providers + +##### Local login + +With this setting, you control if the local login form is shown on the login page or not. By default, the local login form is shown and users an login into the site as normal. If you disable this setting, the local login form is hidden. This allows you to just provide login buttons for external identity providers like OAuth2 or OIDC. + +##### IDP login intro + +With this setting, you control if the 'Log in using your account on' intro is shown above the IDP login buttons or not. By default, the intro is shown and users will be quickly informed what the IDP buttons are about. If you disable this setting, the IDP intro is hidden. This allows you to provide a clean user login interface if you just use external identity providers like OAuth2 or OIDC. + #### Tab "Dashboard / My courses" ##### Course overview block diff --git a/classes/output/core_renderer.php b/classes/output/core_renderer.php index 11b52fb4bed..88dbfb7a0ef 100644 --- a/classes/output/core_renderer.php +++ b/classes/output/core_renderer.php @@ -23,6 +23,7 @@ */ namespace theme_boost_union\output; +use context_course; use context_system; use moodle_url; @@ -484,4 +485,45 @@ public function block(\block_contents $bc, $region) { return $this->render_from_template('core/block', $context); } + + /** + * Renders the login form. + * + * This renderer function is copied and modified from /lib/outputrenderers.php + * + * @param \core_auth\output\login $form The renderable. + * @return string + */ + public function render_login(\core_auth\output\login $form) { + global $CFG, $SITE; + + $context = $form->export_for_template($this); + + $context->errorformatted = $this->error_text($context->error); + $url = $this->get_logo_url(); + if ($url) { + $url = $url->out(false); + } + $context->logourl = $url; + $context->sitename = format_string($SITE->fullname, true, + ['context' => context_course::instance(SITEID), "escape" => false]); + + // Check if the local login form is enabled. + $loginlocalloginsetting = get_config('theme_boost_union', 'loginlocalloginenable'); + $showlocallogin = isset($loginlocalloginsetting) ? $loginlocalloginsetting : THEME_BOOST_UNION_SETTING_SELECT_YES; + if ($showlocallogin == THEME_BOOST_UNION_SETTING_SELECT_YES) { + // Add marker to show the local login form to template context. + $context->showlocallogin = true; + } + + // Check if the IDP login intro is enabled. + $loginidpshowintrosetting = get_config('theme_boost_union', 'loginidpshowintro'); + $showidploginintro = isset($loginidpshowintrosetting) ? $loginidpshowintrosetting : THEME_BOOST_UNION_SETTING_SELECT_YES; + if ($showidploginintro == THEME_BOOST_UNION_SETTING_SELECT_YES) { + // Add marker to show the IDP login intro to template context. + $context->showidploginintro = true; + } + + return $this->render_from_template('core/loginform', $context); + } } diff --git a/lang/en/theme_boost_union.php b/lang/en/theme_boost_union.php index 2685437fd40..8fad7b49dda 100644 --- a/lang/en/theme_boost_union.php +++ b/lang/en/theme_boost_union.php @@ -193,6 +193,14 @@ // ... ... Setting: login form transparency. $string['loginformtransparencysetting'] = 'Login form transparency'; $string['loginformtransparencysetting_desc'] = 'With this setting, you can make the login form slightly transparent to let the background image shine through even more.'; +// ... Section: Login providers. +$string['loginprovidersheading'] = 'Login providers'; +// ... ... Setting: Local login form. +$string['loginlocalloginenablesetting'] = 'Local login'; +$string['loginlocalloginenablesetting_desc'] = 'With this setting, you control if the local login form is shown on the login page or not. By default, the local login form is shown and users an login into the site as normal. If you disable this setting, the local login form is hidden. This allows you to just provide login buttons for external identity providers like OAuth2 or OIDC.'; +// ... ... Setting: IDP login intro. +$string['loginidpshowintrosetting'] = 'IDP login intro'; +$string['loginidpshowintrosetting_desc'] = 'With this setting, you control if the \'{$a}\' intro is shown above the IDP login buttons or not. By default, the intro is shown and users will be quickly informed what the IDP buttons are about. If you disable this setting, the IDP intro is hidden. This allows you to provide a clean user login interface if you just use external identity providers like OAuth2 or OIDC.'; // Settings: Dashboard / My courses tab. $string['dashboardtab'] = 'Dashboard / My courses'; diff --git a/settings.php b/settings.php index dd9f6f10202..46df17c8c09 100644 --- a/settings.php +++ b/settings.php @@ -632,6 +632,26 @@ $setting = new admin_setting_configselect($name, $title, $description, THEME_BOOST_UNION_SETTING_SELECT_NO, $yesnooption); $tab->add($setting); + // Create login providers heading. + $name = 'theme_boost_union/loginprovidersheading'; + $title = get_string('loginprovidersheading', 'theme_boost_union', null, true); + $setting = new admin_setting_heading($name, $title, null); + $tab->add($setting); + + // Setting: Local login. + $name = 'theme_boost_union/loginlocalloginenable'; + $title = get_string('loginlocalloginenablesetting', 'theme_boost_union', null, true); + $description = get_string('loginlocalloginenablesetting_desc', 'theme_boost_union', null, true); + $setting = new admin_setting_configselect($name, $title, $description, THEME_BOOST_UNION_SETTING_SELECT_YES, $yesnooption); + $tab->add($setting); + + // Setting: IDP login intro. + $name = 'theme_boost_union/loginidpshowintro'; + $title = get_string('loginidpshowintrosetting', 'theme_boost_union', null, true); + $description = get_string('loginidpshowintrosetting_desc', 'theme_boost_union', get_string('potentialidps', 'auth'), true); + $setting = new admin_setting_configselect($name, $title, $description, THEME_BOOST_UNION_SETTING_SELECT_YES, $yesnooption); + $tab->add($setting); + // Add tab to settings page. $page->add($tab); diff --git a/templates/core/loginform.mustache b/templates/core/loginform.mustache index bafe779d407..db2d6f6839b 100644 --- a/templates/core/loginform.mustache +++ b/templates/core/loginform.mustache @@ -40,6 +40,8 @@ * sitename - Name of site., * logintoken - Random token to protect login request., * maintenance - Maintenance message + * showlocallogin - Should the local login form be shown? + * showidploginintro - Should the IDP login intro be shown? Example context (json): { @@ -91,7 +93,9 @@ "sitename": "Beer & Chips", "logintoken": "randomstring", "maintenance": "For full access to this site, you need to login in as an admin.", - "languagemenu": "Choose language" + "languagemenu": "Choose language", + "showlocallogin": true, + "showidploginintro": true } }} {{! @@ -99,6 +103,8 @@ Modifications compared to the original template: * Add btn-secondary class to identityprovider login buttons. + * Added the possibility to hide the local login form. + * Added the possibility to hide the IDP login intro. }}
@@ -127,6 +133,7 @@ {{#cansignup}} {{#str}} tocreatenewaccount {{/str}} {{/cansignup}} + {{#showlocallogin}}
+ {{/showlocallogin}} {{#hasidentityproviders}}
+ {{#showidploginintro}} + {{/showidploginintro}} {{#identityproviders}}