Differences Between: [Versions 311 and 401] [Versions 311 and 402] [Versions 311 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 * Class for loading/storing oauth2 endpoints from the DB. 19 * 20 * @package core 21 * @copyright 2017 Damyon Wiese 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 namespace core\oauth2; 25 26 defined('MOODLE_INTERNAL') || die(); 27 28 use core\persistent; 29 use lang_string; 30 /** 31 * Class for loading/storing oauth2 user field mappings from the DB 32 * 33 * @copyright 2017 Damyon Wiese 34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 35 */ 36 class user_field_mapping extends persistent { 37 38 const TABLE = 'oauth2_user_field_mapping'; 39 40 /** 41 * Return the list of valid internal user fields. 42 * 43 * @return array 44 */ 45 private static function get_user_fields() { 46 return array_merge(\core_user::AUTHSYNCFIELDS, ['picture', 'username']); 47 } 48 49 /** 50 * Return the definition of the properties of this model. 51 * 52 * @return array 53 */ 54 protected static function define_properties() { 55 return array( 56 'issuerid' => array( 57 'type' => PARAM_INT 58 ), 59 'externalfield' => array( 60 'type' => PARAM_RAW_TRIMMED, 61 ), 62 'internalfield' => array( 63 'type' => PARAM_ALPHANUMEXT, 64 'choices' => self::get_user_fields() 65 ) 66 ); 67 } 68 69 /** 70 * Return the list of internal fields 71 * in a format they can be used for choices in a select menu 72 * @return array 73 */ 74 public function get_internalfield_list() { 75 return array_combine(self::get_user_fields(), self::get_user_fields()); 76 } 77 78 /** 79 * Ensures that no HTML is saved to externalfield field 80 * but preserves all special characters that can be a part of the claim 81 * @return boolean true if validation is successful, string error if externalfield is not validated 82 */ 83 protected function validate_externalfield($value){ 84 // This parameter type is set to PARAM_RAW_TRIMMED and HTML check is done here. 85 if (clean_param($value, PARAM_NOTAGS) !== $value){ 86 return new lang_string('userfieldexternalfield_error', 'tool_oauth2'); 87 } 88 return true; 89 } 90 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body