Differences Between: [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 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 * Login renderable. 19 * 20 * @package core_auth 21 * @copyright 2016 Frédéric Massart - FMCorz.net 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 namespace core_auth\output; 26 defined('MOODLE_INTERNAL') || die(); 27 28 require_once($CFG->libdir . '/externallib.php'); 29 30 use context_system; 31 use help_icon; 32 use moodle_url; 33 use renderable; 34 use renderer_base; 35 use stdClass; 36 use templatable; 37 38 /** 39 * Login renderable class. 40 * 41 * @package core_auth 42 * @copyright 2016 Frédéric Massart - FMCorz.net 43 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 44 */ 45 class login implements renderable, templatable { 46 47 /** @var bool Whether to auto focus the form fields. */ 48 public $autofocusform; 49 /** @var bool Whether we can login as guest. */ 50 public $canloginasguest; 51 /** @var bool Whether we can login by e-mail. */ 52 public $canloginbyemail; 53 /** @var bool Whether we can sign-up. */ 54 public $cansignup; 55 /** @var help_icon The cookies help icon. */ 56 public $cookieshelpicon; 57 /** @var string The error message, if any. */ 58 public $error; 59 /** @var moodle_url Forgot password URL. */ 60 public $forgotpasswordurl; 61 /** @var array Additional identify providers, contains the keys 'url', 'name' and 'icon'. */ 62 public $identityproviders; 63 /** @var string Login instructions, if any. */ 64 public $instructions; 65 /** @var moodle_url The form action login URL. */ 66 public $loginurl; 67 /** @var bool Whether the username should be remembered. */ 68 public $rememberusername; 69 /** @var moodle_url The sign-up URL. */ 70 public $signupurl; 71 /** @var string The user name to pre-fill the form with. */ 72 public $username; 73 /** @var string The csrf token to limit login to requests that come from the login form. */ 74 public $logintoken; 75 /** @var string Maintenance message, if Maintenance is enabled. */ 76 public $maintenance; 77 78 /** 79 * Constructor. 80 * 81 * @param array $authsequence The enabled sequence of authentication plugins. 82 * @param string $username The username to display. 83 */ 84 public function __construct(array $authsequence, $username = '') { 85 global $CFG; 86 87 $this->username = $username; 88 89 $this->canloginasguest = $CFG->guestloginbutton and !isguestuser(); 90 $this->canloginbyemail = !empty($CFG->authloginviaemail); 91 $this->cansignup = $CFG->registerauth == 'email' || !empty($CFG->registerauth); 92 if ($CFG->rememberusername == 0) { 93 $this->cookieshelpicon = new help_icon('cookiesenabledonlysession', 'core'); 94 $this->rememberusername = false; 95 } else { 96 $this->cookieshelpicon = new help_icon('cookiesenabled', 'core'); 97 $this->rememberusername = true; 98 } 99 100 $this->autofocusform = !empty($CFG->loginpageautofocus); 101 102 $this->forgotpasswordurl = new moodle_url('/login/forgot_password.php'); 103 $this->loginurl = new moodle_url('/login/index.php'); 104 $this->signupurl = new moodle_url('/login/signup.php'); 105 106 // Authentication instructions. 107 $this->instructions = $CFG->auth_instructions; 108 if (is_enabled_auth('none')) { 109 $this->instructions = get_string('loginstepsnone'); 110 } else if ($CFG->registerauth == 'email' && empty($this->instructions)) { 111 $this->instructions = get_string('loginsteps', 'core', 'signup.php'); 112 } 113 114 if ($CFG->maintenance_enabled == true && !empty($CFG->maintenance_message)) { 115 $this->maintenance = $CFG->maintenance_message; 116 } 117 118 // Identity providers. 119 $this->identityproviders = \auth_plugin_base::get_identity_providers($authsequence); 120 $this->logintoken = \core\session\manager::get_login_token(); 121 } 122 123 /** 124 * Set the error message. 125 * 126 * @param string $error The error message. 127 */ 128 public function set_error($error) { 129 $this->error = $error; 130 } 131 132 public function export_for_template(renderer_base $output) { 133 134 $identityproviders = \auth_plugin_base::prepare_identity_providers_for_output($this->identityproviders, $output); 135 136 $data = new stdClass(); 137 $data->autofocusform = $this->autofocusform; 138 $data->canloginasguest = $this->canloginasguest; 139 $data->canloginbyemail = $this->canloginbyemail; 140 $data->cansignup = $this->cansignup; 141 $data->cookieshelpicon = $this->cookieshelpicon->export_for_template($output); 142 $data->error = $this->error; 143 $data->forgotpasswordurl = $this->forgotpasswordurl->out(false); 144 $data->hasidentityproviders = !empty($this->identityproviders); 145 $data->hasinstructions = !empty($this->instructions) || $this->cansignup; 146 $data->identityproviders = $identityproviders; 147 list($data->instructions, $data->instructionsformat) = external_format_text($this->instructions, FORMAT_MOODLE, 148 context_system::instance()->id); 149 $data->loginurl = $this->loginurl->out(false); 150 $data->rememberusername = $this->rememberusername; 151 $data->signupurl = $this->signupurl->out(false); 152 $data->username = $this->username; 153 $data->logintoken = $this->logintoken; 154 $data->maintenance = format_text($this->maintenance, FORMAT_MOODLE); 155 156 return $data; 157 } 158 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body