See Release Notes
Long Term Support Release
Differences Between: [Versions 39 and 311] [Versions 39 and 400] [Versions 39 and 401] [Versions 39 and 402] [Versions 39 and 403]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * This file contains the form add/update oauth2 issuer. 19 * 20 * @package tool_oauth2 21 * @copyright 2017 Damyon Wiese 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 namespace tool_oauth2\form; 26 defined('MOODLE_INTERNAL') || die(); 27 28 use stdClass; 29 use core\form\persistent; 30 31 /** 32 * Issuer form. 33 * 34 * @package tool_oauth2 35 * @copyright 2017 Damyon Wiese 36 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 37 */ 38 class issuer extends persistent { 39 40 /** @var string $persistentclass */ 41 protected static $persistentclass = 'core\\oauth2\\issuer'; 42 43 /** @var array $fieldstoremove */ 44 protected static $fieldstoremove = array('type', 'submitbutton', 'action'); 45 46 /** @var string $type */ 47 protected $type; 48 49 /** @var boolean $showrequireconfirm Whether to show the require confirmation email checkbox or not. */ 50 protected $showrequireconfirm; 51 52 /** 53 * Constructor. 54 * 55 * The 'persistent' has to be passed as custom data when 'editing'. 56 * If a standard issuer is created the type can be passed as custom data, which alters the form according to the 57 * type. 58 * 59 * Note that in order for your persistent to be reloaded after form submission you should 60 * either override the URL to include the ID to your resource, or add the ID to the form 61 * fields. 62 * 63 * @param mixed $action 64 * @param mixed $customdata 65 * @param string $method 66 * @param string $target 67 * @param mixed $attributes 68 * @param bool $editable 69 * @param array $ajaxformdata 70 */ 71 public function __construct($action = null, $customdata = null, $method = 'post', $target = '', $attributes = null, 72 $editable = true, array $ajaxformdata = null) { 73 // The type variable defines, if we are in the creation process of a standard issuer. 74 if (array_key_exists('type', $customdata)) { 75 $this->type = $customdata['type']; 76 } 77 $this->showrequireconfirm = !empty($customdata['showrequireconfirm']); 78 parent::__construct($action, $customdata, $method, $target, $attributes, $editable, $ajaxformdata); 79 } 80 81 /** 82 * Define the form - called by parent constructor 83 */ 84 public function definition() { 85 global $PAGE, $OUTPUT; 86 87 $mform = $this->_form; 88 $issuer = $this->get_persistent(); 89 90 $docslink = optional_param('docslink', '', PARAM_ALPHAEXT); 91 if ($docslink) { 92 $name = s($issuer->get('name')); 93 $mform->addElement('html', $OUTPUT->doc_link($docslink, get_string('issuersetuptype', 'tool_oauth2', $name))); 94 } else { 95 $mform->addElement('html', $OUTPUT->page_doc_link(get_string('issuersetup', 'tool_oauth2'))); 96 } 97 98 // Name. 99 $mform->addElement('text', 'name', get_string('issuername', 'tool_oauth2')); 100 $mform->addRule('name', null, 'required', null, 'client'); 101 $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); 102 $mform->addHelpButton('name', 'issuername', 'tool_oauth2'); 103 104 // Client ID. 105 $mform->addElement('text', 'clientid', get_string('issuerclientid', 'tool_oauth2')); 106 $mform->addRule('clientid', null, 'required', null, 'client'); 107 $mform->addRule('clientid', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); 108 $mform->addHelpButton('clientid', 'issuerclientid', 'tool_oauth2'); 109 110 // Client Secret. 111 $mform->addElement('text', 'clientsecret', get_string('issuerclientsecret', 'tool_oauth2')); 112 $mform->addRule('clientsecret', null, 'required', null, 'client'); 113 $mform->addRule('clientsecret', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); 114 $mform->addHelpButton('clientsecret', 'issuerclientsecret', 'tool_oauth2'); 115 116 // Use basic authentication. 117 $mform->addElement('checkbox', 'basicauth', get_string('usebasicauth', 'tool_oauth2')); 118 $mform->addHelpButton('basicauth', 'usebasicauth', 'tool_oauth2'); 119 120 // Login scopes. 121 $mform->addElement('text', 'loginscopes', get_string('issuerloginscopes', 'tool_oauth2')); 122 $mform->addRule('loginscopes', null, 'required', null, 'client'); 123 $mform->addRule('loginscopes', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); 124 $mform->addHelpButton('loginscopes', 'issuerloginscopes', 'tool_oauth2'); 125 126 // Login scopes offline. 127 $mform->addElement('text', 'loginscopesoffline', get_string('issuerloginscopesoffline', 'tool_oauth2')); 128 $mform->addRule('loginscopesoffline', null, 'required', null, 'client'); 129 $mform->addRule('loginscopesoffline', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); 130 $mform->addHelpButton('loginscopesoffline', 'issuerloginscopesoffline', 'tool_oauth2'); 131 132 // Login params. 133 $mform->addElement('text', 'loginparams', get_string('issuerloginparams', 'tool_oauth2')); 134 $mform->addRule('loginparams', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); 135 $mform->addHelpButton('loginparams', 'issuerloginparams', 'tool_oauth2'); 136 137 // Login params offline. 138 $mform->addElement('text', 'loginparamsoffline', get_string('issuerloginparamsoffline', 'tool_oauth2')); 139 $mform->addRule('loginparamsoffline', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); 140 $mform->addHelpButton('loginparamsoffline', 'issuerloginparamsoffline', 'tool_oauth2'); 141 142 // Base Url. 143 $mform->addElement('text', 'baseurl', get_string('issuerbaseurl', 'tool_oauth2')); 144 $mform->addRule('baseurl', get_string('maximumchars', '', 1024), 'maxlength', 1024, 'client'); 145 $mform->addHelpButton('baseurl', 'issuerbaseurl', 'tool_oauth2'); 146 if ($this->type && $this->type == 'nextcloud') { 147 $mform->addRule('baseurl', null, 'required', null, 'client'); 148 } 149 150 // Allowed Domains. 151 $mform->addElement('text', 'alloweddomains', get_string('issueralloweddomains', 'tool_oauth2')); 152 $mform->addRule('alloweddomains', get_string('maximumchars', '', 1024), 'maxlength', 1024, 'client'); 153 $mform->addHelpButton('alloweddomains', 'issueralloweddomains', 'tool_oauth2'); 154 155 // Image. 156 $mform->addElement('text', 'image', get_string('issuerimage', 'tool_oauth2'), 'maxlength="1024"'); 157 $mform->addRule('image', get_string('maximumchars', '', 1024), 'maxlength', 1024, 'client'); 158 $mform->addHelpButton('image', 'issuername', 'tool_oauth2'); 159 160 // Show on login page. 161 $mform->addElement('checkbox', 'showonloginpage', get_string('issuershowonloginpage', 'tool_oauth2')); 162 $mform->addHelpButton('showonloginpage', 'issuershowonloginpage', 'tool_oauth2'); 163 164 if ($this->showrequireconfirm) { 165 // Require confirmation email for new accounts. 166 $mform->addElement('advcheckbox', 'requireconfirmation', get_string('issuerrequireconfirmation', 'tool_oauth2')); 167 $mform->addHelpButton('requireconfirmation', 'issuerrequireconfirmation', 'tool_oauth2'); 168 } 169 170 $mform->addElement('hidden', 'sortorder'); 171 $mform->setType('sortorder', PARAM_INT); 172 173 if ($this->type) { 174 $mform->addElement('hidden', 'action', 'savetemplate'); 175 $mform->setType('action', PARAM_ALPHA); 176 177 $mform->addElement('hidden', 'type', $this->_customdata['type']); 178 $mform->setType('type', PARAM_ALPHA); 179 } else { 180 $mform->addElement('hidden', 'action', 'edit'); 181 $mform->setType('action', PARAM_ALPHA); 182 } 183 184 $mform->addElement('hidden', 'enabled', $issuer->get('enabled')); 185 $mform->setType('enabled', PARAM_BOOL); 186 187 $mform->addElement('hidden', 'id', $issuer->get('id')); 188 $mform->setType('id', PARAM_INT); 189 190 $this->add_action_buttons(true, get_string('savechanges', 'tool_oauth2')); 191 } 192 193 } 194
title
Description
Body
title
Description
Body
title
Description
Body
title
Body