1 |
efrain |
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 |
|
|
|
27 |
use context_system;
|
|
|
28 |
use help_icon;
|
|
|
29 |
use moodle_url;
|
|
|
30 |
use renderable;
|
|
|
31 |
use renderer_base;
|
|
|
32 |
use stdClass;
|
|
|
33 |
use templatable;
|
|
|
34 |
|
|
|
35 |
/**
|
|
|
36 |
* Login renderable class.
|
|
|
37 |
*
|
|
|
38 |
* @package core_auth
|
|
|
39 |
* @copyright 2016 Frédéric Massart - FMCorz.net
|
|
|
40 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
41 |
*/
|
|
|
42 |
class login implements renderable, templatable {
|
|
|
43 |
|
|
|
44 |
/** @var bool Whether to auto focus the form fields. */
|
|
|
45 |
public $autofocusform;
|
|
|
46 |
/** @var bool Whether we can login as guest. */
|
|
|
47 |
public $canloginasguest;
|
|
|
48 |
/** @var bool Whether we can login by e-mail. */
|
|
|
49 |
public $canloginbyemail;
|
|
|
50 |
/** @var bool Whether we can sign-up. */
|
|
|
51 |
public $cansignup;
|
|
|
52 |
/** @var help_icon The cookies help icon. */
|
|
|
53 |
public $cookieshelpicon;
|
|
|
54 |
/** @var string The error message, if any. */
|
|
|
55 |
public $error;
|
|
|
56 |
/** @var string The info message, if any. */
|
|
|
57 |
public $info;
|
|
|
58 |
/** @var moodle_url Forgot password URL. */
|
|
|
59 |
public $forgotpasswordurl;
|
|
|
60 |
/** @var array Additional identify providers, contains the keys 'url', 'name' and 'icon'. */
|
|
|
61 |
public $identityproviders;
|
|
|
62 |
/** @var string Login instructions, if any. */
|
|
|
63 |
public $instructions;
|
|
|
64 |
/** @var moodle_url The form action login URL. */
|
|
|
65 |
public $loginurl;
|
|
|
66 |
/** @var moodle_url The sign-up URL. */
|
|
|
67 |
public $signupurl;
|
|
|
68 |
/** @var string The user name to pre-fill the form with. */
|
|
|
69 |
public $username;
|
|
|
70 |
/** @var string The language selector menu. */
|
|
|
71 |
public $languagemenu;
|
|
|
72 |
/** @var string The csrf token to limit login to requests that come from the login form. */
|
|
|
73 |
public $logintoken;
|
|
|
74 |
/** @var string Maintenance message, if Maintenance is enabled. */
|
|
|
75 |
public $maintenance;
|
|
|
76 |
/** @var string ReCaptcha element HTML. */
|
|
|
77 |
public $recaptcha;
|
|
|
78 |
/** @var bool Toggle the password visibility icon. */
|
|
|
79 |
public $togglepassword;
|
|
|
80 |
/** @var bool Toggle the password visibility icon for small screens only. */
|
|
|
81 |
public $smallscreensonly;
|
|
|
82 |
|
|
|
83 |
/**
|
|
|
84 |
* Constructor.
|
|
|
85 |
*
|
|
|
86 |
* @param array $authsequence The enabled sequence of authentication plugins.
|
|
|
87 |
* @param string $username The username to display.
|
|
|
88 |
*/
|
|
|
89 |
public function __construct(array $authsequence, $username = '') {
|
|
|
90 |
global $CFG, $OUTPUT, $PAGE;
|
|
|
91 |
|
|
|
92 |
$this->username = $username;
|
|
|
93 |
|
|
|
94 |
$languagedata = new \core\output\language_menu($PAGE);
|
|
|
95 |
|
|
|
96 |
$this->languagemenu = $languagedata->export_for_action_menu($OUTPUT);
|
|
|
97 |
$this->canloginasguest = $CFG->guestloginbutton && !isguestuser();
|
|
|
98 |
$this->canloginbyemail = !empty($CFG->authloginviaemail);
|
|
|
99 |
$this->cansignup = $CFG->registerauth == 'email' || !empty($CFG->registerauth);
|
|
|
100 |
if ($CFG->rememberusername == 0) {
|
|
|
101 |
$this->cookieshelpicon = new help_icon('cookiesenabledonlysession', 'core');
|
|
|
102 |
} else {
|
|
|
103 |
$this->cookieshelpicon = new help_icon('cookiesenabled', 'core');
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
$this->autofocusform = !empty($CFG->loginpageautofocus);
|
|
|
107 |
|
|
|
108 |
$this->forgotpasswordurl = new moodle_url('/login/forgot_password.php');
|
|
|
109 |
$this->loginurl = new moodle_url('/login/index.php');
|
|
|
110 |
$this->signupurl = new moodle_url('/login/signup.php');
|
|
|
111 |
|
|
|
112 |
// Authentication instructions.
|
|
|
113 |
$this->instructions = $CFG->auth_instructions;
|
|
|
114 |
if (is_enabled_auth('none')) {
|
|
|
115 |
$this->instructions = get_string('loginstepsnone');
|
|
|
116 |
} else if ($CFG->registerauth == 'email' && empty($this->instructions)) {
|
|
|
117 |
$this->instructions = get_string('loginsteps', 'core', 'signup.php');
|
|
|
118 |
}
|
|
|
119 |
|
|
|
120 |
if ($CFG->maintenance_enabled == true) {
|
|
|
121 |
if (!empty($CFG->maintenance_message)) {
|
|
|
122 |
$this->maintenance = $CFG->maintenance_message;
|
|
|
123 |
} else {
|
|
|
124 |
$this->maintenance = get_string('sitemaintenance', 'admin');
|
|
|
125 |
}
|
|
|
126 |
}
|
|
|
127 |
|
|
|
128 |
// Identity providers.
|
|
|
129 |
$this->identityproviders = \auth_plugin_base::get_identity_providers($authsequence);
|
|
|
130 |
$this->logintoken = \core\session\manager::get_login_token();
|
|
|
131 |
|
|
|
132 |
// ReCaptcha.
|
|
|
133 |
if (login_captcha_enabled()) {
|
|
|
134 |
require_once($CFG->libdir . '/recaptchalib_v2.php');
|
|
|
135 |
$this->recaptcha = recaptcha_get_challenge_html(RECAPTCHA_API_URL, $CFG->recaptchapublickey);
|
|
|
136 |
}
|
|
|
137 |
|
|
|
138 |
// Toggle password visibility icon.
|
|
|
139 |
$this->togglepassword = get_config('core', 'loginpasswordtoggle') == TOGGLE_SENSITIVE_ENABLED ||
|
|
|
140 |
get_config('core', 'loginpasswordtoggle') == TOGGLE_SENSITIVE_SMALL_SCREENS_ONLY;
|
|
|
141 |
$this->smallscreensonly = get_config('core', 'loginpasswordtoggle') == TOGGLE_SENSITIVE_SMALL_SCREENS_ONLY;
|
|
|
142 |
}
|
|
|
143 |
|
|
|
144 |
/**
|
|
|
145 |
* Set the error message.
|
|
|
146 |
*
|
|
|
147 |
* @param string $error The error message.
|
|
|
148 |
*/
|
|
|
149 |
public function set_error($error) {
|
|
|
150 |
$this->error = $error;
|
|
|
151 |
}
|
|
|
152 |
|
|
|
153 |
/**
|
|
|
154 |
* Set the info message.
|
|
|
155 |
*
|
|
|
156 |
* @param string $info The info message.
|
|
|
157 |
*/
|
|
|
158 |
public function set_info(string $info): void {
|
|
|
159 |
$this->info = $info;
|
|
|
160 |
}
|
|
|
161 |
|
|
|
162 |
public function export_for_template(renderer_base $output) {
|
|
|
163 |
|
|
|
164 |
$identityproviders = \auth_plugin_base::prepare_identity_providers_for_output($this->identityproviders, $output);
|
|
|
165 |
|
|
|
166 |
$data = new stdClass();
|
|
|
167 |
$data->autofocusform = $this->autofocusform;
|
|
|
168 |
$data->canloginasguest = $this->canloginasguest;
|
|
|
169 |
$data->canloginbyemail = $this->canloginbyemail;
|
|
|
170 |
$data->cansignup = $this->cansignup;
|
|
|
171 |
$data->cookieshelpicon = $this->cookieshelpicon->export_for_template($output);
|
|
|
172 |
$data->error = $this->error;
|
|
|
173 |
$data->info = $this->info;
|
|
|
174 |
$data->forgotpasswordurl = $this->forgotpasswordurl->out(false);
|
|
|
175 |
$data->hasidentityproviders = !empty($this->identityproviders);
|
|
|
176 |
$data->hasinstructions = !empty($this->instructions) || $this->cansignup;
|
|
|
177 |
$data->identityproviders = $identityproviders;
|
|
|
178 |
list($data->instructions, $data->instructionsformat) = \core_external\util::format_text($this->instructions, FORMAT_MOODLE,
|
|
|
179 |
context_system::instance()->id);
|
|
|
180 |
$data->loginurl = $this->loginurl->out(false);
|
|
|
181 |
$data->signupurl = $this->signupurl->out(false);
|
|
|
182 |
$data->username = $this->username;
|
|
|
183 |
$data->logintoken = $this->logintoken;
|
|
|
184 |
$data->maintenance = format_text($this->maintenance, FORMAT_MOODLE);
|
|
|
185 |
$data->languagemenu = $this->languagemenu;
|
|
|
186 |
$data->recaptcha = $this->recaptcha;
|
|
|
187 |
$data->togglepassword = $this->togglepassword;
|
|
|
188 |
$data->smallscreensonly = $this->smallscreensonly;
|
|
|
189 |
|
|
|
190 |
return $data;
|
|
|
191 |
}
|
|
|
192 |
}
|