mirrored from git://git.moodle.org/moodle.git
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-58090 oauth2: Move code from subclasses to config
Allow the behaviour of each oauth service to be customised by config instead of subclasses. Part of MDL-58220
- Loading branch information
Damyon Wiese
committed
Apr 3, 2017
1 parent
6023725
commit 8445556
Showing
21 changed files
with
961 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* This file contains the form add/update oauth2 endpoint. | ||
* | ||
* @package tool_oauth2 | ||
* @copyright 2017 Damyon Wiese | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
namespace tool_oauth2\form; | ||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
use stdClass; | ||
use core\form\persistent; | ||
|
||
/** | ||
* Issuer form. | ||
* | ||
* @package tool_oauth2 | ||
* @copyright 2017 Damyon Wiese | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class endpoint extends persistent { | ||
|
||
protected static $persistentclass = 'core\\oauth2\\endpoint'; | ||
|
||
protected static $fieldstoremove = array('submitbutton', 'action'); | ||
|
||
/** | ||
* Define the form - called by parent constructor | ||
*/ | ||
public function definition() { | ||
global $PAGE; | ||
|
||
$mform = $this->_form; | ||
$endpoint = $this->get_persistent(); | ||
|
||
$mform->addElement('header', 'generalhdr', get_string('general')); | ||
|
||
// Name. | ||
$mform->addElement('text', 'name', get_string('endpointname', 'tool_oauth2'), 'maxlength="255"'); | ||
$mform->addRule('name', null, 'required', null, 'client'); | ||
$mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); | ||
$mform->addHelpButton('name', 'endpointname', 'tool_oauth2'); | ||
|
||
// Url. | ||
$mform->addElement('text', 'url', get_string('endpointurl', 'tool_oauth2'), 'maxlength="1024"'); | ||
$mform->addRule('url', null, 'required', null, 'client'); | ||
$mform->addRule('url', get_string('maximumchars', '', 1024), 'maxlength', 1024, 'client'); | ||
$mform->addHelpButton('url', 'endpointurl', 'tool_oauth2'); | ||
|
||
$mform->addElement('hidden', 'action', 'edit'); | ||
$mform->setType('action', PARAM_RAW); | ||
|
||
$mform->addElement('hidden', 'issuerid', $endpoint->get('issuerid')); | ||
$mform->setType('issuerid', PARAM_INT); | ||
$mform->setConstant('issuerid', $this->_customdata['issuerid']); | ||
|
||
$mform->addElement('hidden', 'id', $endpoint->get('id')); | ||
$mform->setType('id', PARAM_INT); | ||
|
||
$this->add_action_buttons(true, get_string('savechanges', 'tool_oauth2')); | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* This file contains the form add/update oauth2 user_field_mapping. | ||
* | ||
* @package tool_oauth2 | ||
* @copyright 2017 Damyon Wiese | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
namespace tool_oauth2\form; | ||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
use stdClass; | ||
use core\form\persistent; | ||
|
||
/** | ||
* Issuer form. | ||
* | ||
* @package tool_oauth2 | ||
* @copyright 2017 Damyon Wiese | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class user_field_mapping extends persistent { | ||
|
||
protected static $persistentclass = 'core\\oauth2\\user_field_mapping'; | ||
|
||
protected static $fieldstoremove = array('submitbutton', 'action'); | ||
|
||
/** | ||
* Define the form - called by parent constructor | ||
*/ | ||
public function definition() { | ||
global $PAGE; | ||
|
||
$mform = $this->_form; | ||
$userfieldmapping = $this->get_persistent(); | ||
|
||
$mform->addElement('header', 'generalhdr', get_string('general')); | ||
|
||
// External. | ||
$mform->addElement('text', 'externalfield', get_string('userfieldexternalfield', 'tool_oauth2'), 'maxlength="255"'); | ||
$mform->addRule('externalfield', null, 'required', null, 'client'); | ||
$mform->addRule('externalfield', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); | ||
$mform->addHelpButton('externalfield', 'userfieldexternalfield', 'tool_oauth2'); | ||
|
||
// Internal. | ||
$choices = $userfieldmapping->get_internalfield_list(); | ||
$mform->addElement('select', 'internalfield', get_string('userfieldinternalfield', 'tool_oauth2'), $choices); | ||
$mform->addHelpButton('internalfield', 'userfieldinternalfield', 'tool_oauth2'); | ||
|
||
$mform->addElement('hidden', 'action', 'edit'); | ||
$mform->setType('action', PARAM_RAW); | ||
|
||
$mform->addElement('hidden', 'issuerid', $userfieldmapping->get('issuerid')); | ||
$mform->setConstant('issuerid', $this->_customdata['issuerid']); | ||
$mform->setType('issuerid', PARAM_INT); | ||
|
||
$mform->addElement('hidden', 'id', $userfieldmapping->get('id')); | ||
$mform->setType('id', PARAM_INT); | ||
|
||
$this->add_action_buttons(true, get_string('savechanges', 'tool_oauth2')); | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.