diff --git a/admin/tool/mobile/classes/api.php b/admin/tool/mobile/classes/api.php index c111010b2ff..9653d45fa90 100644 --- a/admin/tool/mobile/classes/api.php +++ b/admin/tool/mobile/classes/api.php @@ -27,6 +27,7 @@ namespace tool_mobile; use core_component; use core_plugin_manager; use context_system; +use moodle_url; /** * API exposed by tool_mobile @@ -37,6 +38,13 @@ use context_system; */ class api { + /** @var int to identify the login via app. */ + const LOGIN_VIA_APP = 1; + /** @var int to identify the login via browser. */ + const LOGIN_VIA_BROWSER = 2; + /** @var int to identify the login via an embedded browser. */ + const LOGIN_VIA_EMBEDDED_BROWSER = 3; + /** * Returns a list of Moodle plugins supporting the mobile app. * @@ -111,6 +119,19 @@ class api { 'maintenanceenabled' => $CFG->maintenance_enabled, 'maintenancemessage' => format_text($CFG->maintenance_message), ); + + $typeoflogin = get_config('tool_mobile', 'typeoflogin'); + // Not found, edge case. + if ($typeoflogin === false) { + $typeoflogin = self::LOGIN_VIA_APP; // Defaults to via app. + } + $settings['typeoflogin'] = $typeoflogin; + + if ($typeoflogin == self::LOGIN_VIA_BROWSER or + $typeoflogin == self::LOGIN_VIA_EMBEDDED_BROWSER) { + $url = new moodle_url("/$CFG->admin/tool/mobile/launch.php"); + $settings['launchurl'] = $url->out(false); + } return $settings; } diff --git a/admin/tool/mobile/classes/external.php b/admin/tool/mobile/classes/external.php index 148f8a48016..4ab5e930139 100644 --- a/admin/tool/mobile/classes/external.php +++ b/admin/tool/mobile/classes/external.php @@ -140,6 +140,8 @@ class external extends external_api { 'enablemobilewebservice' => new external_value(PARAM_INT, 'Whether the Mobile service is enabled.'), 'maintenanceenabled' => new external_value(PARAM_INT, 'Whether site maintenance is enabled.'), 'maintenancemessage' => new external_value(PARAM_RAW, 'Maintenance message.'), + 'typeoflogin' => new external_value(PARAM_INT, 'The type of login. 1 for app, 2 for browser, 3 for embedded.'), + 'launchurl' => new external_value(PARAM_URL, 'SSO login launch URL. Empty if it won\'t be used.', VALUE_OPTIONAL), 'warnings' => new external_warnings(), ) ); diff --git a/admin/tool/mobile/lang/en/tool_mobile.php b/admin/tool/mobile/lang/en/tool_mobile.php index 56a13605089..ac4eeea90ab 100644 --- a/admin/tool/mobile/lang/en/tool_mobile.php +++ b/admin/tool/mobile/lang/en/tool_mobile.php @@ -22,4 +22,11 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +$string['forcedurlscheme'] = 'The URL scheme allows to open the mobile app from other apps like the browser. Use this setting if you want to allow only your custom branded app to be opened by the browser.'; +$string['forcedurlscheme_key'] = 'URL scheme'; +$string['loginintheapp'] = 'Via the app'; +$string['logininthebrowser'] = 'Via a browser window (for SSO plugins)'; +$string['loginintheembeddedbrowser'] = 'Via an embedded browser (for SSO plugins)'; $string['pluginname'] = 'Moodle Mobile tools'; +$string['typeoflogin'] = 'Type of login'; +$string['typeoflogin_desc'] = 'Choose the type of login.'; diff --git a/admin/tool/mobile/settings.php b/admin/tool/mobile/settings.php index 11aea8516b9..91bf63b18c1 100644 --- a/admin/tool/mobile/settings.php +++ b/admin/tool/mobile/settings.php @@ -43,5 +43,20 @@ if ($hassiteconfig) { $temp->add(new admin_setting_configtext('mobilecssurl', new lang_string('mobilecssurl', 'admin'), new lang_string('configmobilecssurl', 'admin'), '', PARAM_URL)); + + // Type of login. + $options = array( + tool_mobile\api::LOGIN_VIA_APP => new lang_string('loginintheapp', 'tool_mobile'), + tool_mobile\api::LOGIN_VIA_BROWSER => new lang_string('logininthebrowser', 'tool_mobile'), + tool_mobile\api::LOGIN_VIA_EMBEDDED_BROWSER => new lang_string('loginintheembeddedbrowser', 'tool_mobile'), + ); + $temp->add(new admin_setting_configselect('tool_mobile/typeoflogin', + new lang_string('typeoflogin', 'tool_mobile'), + new lang_string('typeoflogin_desc', 'tool_mobile'), 1, $options)); + + $temp->add(new admin_setting_configtext('tool_mobile/forcedurlscheme', + new lang_string('forcedurlscheme_key', 'tool_mobile'), + new lang_string('forcedurlscheme', 'tool_mobile'), '', PARAM_NOTAGS)); + $ADMIN->add('webservicesettings', $temp); } diff --git a/admin/tool/mobile/tests/externallib_test.php b/admin/tool/mobile/tests/externallib_test.php index 0ee8fc34b59..3d2c0edc517 100644 --- a/admin/tool/mobile/tests/externallib_test.php +++ b/admin/tool/mobile/tests/externallib_test.php @@ -31,6 +31,7 @@ global $CFG; require_once($CFG->dirroot . '/webservice/tests/helpers.php'); use tool_mobile\external; +use tool_mobile\api; /** * External learning plans webservice API tests. @@ -78,17 +79,21 @@ class tool_mobile_external_testcase extends externallib_advanced_testcase { 'enablemobilewebservice' => $CFG->enablemobilewebservice, 'maintenanceenabled' => $CFG->maintenance_enabled, 'maintenancemessage' => format_text($CFG->maintenance_message), + 'typeoflogin' => api::LOGIN_VIA_APP, 'warnings' => array() ); $this->assertEquals($expected, $result); - // Change a value. + // Change some values. set_config('registerauth', 'email'); $authinstructions = 'Something with html tags'; set_config('auth_instructions', $authinstructions); + set_config('typeoflogin', api::LOGIN_VIA_BROWSER, 'tool_mobile'); $expected['registerauth'] = 'email'; $expected['authinstructions'] = format_text($authinstructions); + $expected['typeoflogin'] = api::LOGIN_VIA_BROWSER; + $expected['launchurl'] = "$CFG->wwwroot/$CFG->admin/tool/mobile/launch.php";; $result = external::get_site_public_settings(); $result = external_api::clean_returnvalue(external::get_site_public_settings_returns(), $result); diff --git a/admin/tool/mobile/version.php b/admin/tool/mobile/version.php index 0c57e237651..1be04c390ad 100644 --- a/admin/tool/mobile/version.php +++ b/admin/tool/mobile/version.php @@ -23,6 +23,6 @@ */ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2016052301; // The current plugin version (Date: YYYYMMDDXX). +$plugin->version = 2016052302; // The current plugin version (Date: YYYYMMDDXX). $plugin->requires = 2016051900; // Requires this Moodle version. $plugin->component = 'tool_mobile'; // Full name of the plugin (used for diagnostics).