Proyectos de Subversion Moodle

Rev

Rev 1391 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1391 Rev 1441
Línea 1... Línea 1...
1
<?php
1
<?php
Línea 2... Línea 2...
2
 
2
 
3
// Este archivo es parte de Moodle - http://moodle.org/
3
// This file is part of Moodle - http://moodle.org/
4
//
4
//
5
// Moodle es software libre: puedes redistribuirlo y/o modificarlo
5
// Moodle is free software: you can redistribute it and/or modify
6
// bajo los términos de la Licencia Pública General GNU publicada por
6
// it under the terms of the GNU General Public License as published by
7
// la Free Software Foundation, ya sea la versión 3 de la Licencia, o
7
// the Free Software Foundation, either version 3 of the License, or
8
// (a tu elección) cualquier versión posterior.
8
// (at your option) any later version.
9
//
9
//
10
// Moodle se distribuye con la esperanza de que sea útil,
10
// Moodle is distributed in the hope that it will be useful,
11
// pero SIN NINGUNA GARANTÍA; sin siquiera la garantía implícita de
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// COMERCIABILIDAD o IDONEIDAD PARA UN PROPÓSITO PARTICULAR. Ver la
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
// Licencia Pública General GNU para más detalles.
13
// GNU General Public License for more details.
14
//
14
//
15
// Deberías haber recibido una copia de la Licencia Pública General GNU
15
// You should have received a copy of the GNU General Public License
Línea 16... Línea 16...
16
// junto con Moodle. Si no, ve <http://www.gnu.org/licenses/>.
16
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
17
 
-
 
18
/**
-
 
19
 * Página principal de inicio de sesión de Moodle.
-
 
20
 * Este archivo maneja todo el proceso de autenticación de usuarios,
17
 
21
 * incluyendo la validación de credenciales, manejo de sesiones,
18
/**
22
 * redirecciones y mensajes de error.
19
 * Main login page.
23
 *
20
 *
24
 * @package    core
21
 * @package    core
25
 * @subpackage auth
22
 * @subpackage auth
26
 * @copyright  1999 onwards Martin Dougiamas  http://dougiamas.com
23
 * @copyright  1999 onwards Martin Dougiamas  http://dougiamas.com
Línea 27... Línea -...
27
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
-
 
28
 */
24
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
29
 
25
 */
Línea 30... Línea -...
30
// Incluir archivos de configuración y librerías necesarias
-
 
31
require('../config.php');
-
 
32
require_once('lib.php');
26
 
Línea 33... Línea -...
33
 
-
 
34
// Verificar si se requiere una actualización mayor del sistema
-
 
35
// Si es así, redirigir al usuario a la página de actualización
-
 
36
redirect_if_major_upgrade_required();
-
 
37
 
-
 
38
// ============================================================================
27
require('../config.php');
39
// PARÁMETROS DE LA PÁGINA DE INICIO DE SESIÓN
28
require_once('lib.php');
40
// ============================================================================
29
 
-
 
30
redirect_if_major_upgrade_required();
41
 
31
 
42
// Parámetros opcionales que controlan el comportamiento del inicio de sesión
32
$testsession = optional_param('testsession', 0, PARAM_INT); // test session works properly
43
$testsession = optional_param('testsession', 0, PARAM_INT);     // Verifica el funcionamiento correcto de la sesión
33
$anchor      = optional_param('anchor', '', PARAM_RAW);     // Used to restore hash anchor to wantsurl.
44
$anchor = optional_param('anchor', '', PARAM_RAW);              // Mantiene la posición del ancla en la URL de destino
34
$loginredirect = optional_param('loginredirect', 1, PARAM_BOOL);   // Used to bypass alternateloginurl.
-
 
35
 
-
 
36
$resendconfirmemail = optional_param('resendconfirmemail', false, PARAM_BOOL);
45
$loginredirect = optional_param('loginredirect', 1, PARAM_BOOL); // Controla la redirección a URL de login alternativo
37
 
46
$resendconfirmemail = optional_param('resendconfirmemail', false, PARAM_BOOL); // Permite reenviar email de confirmación
38
// It might be safe to do this for non-Behat sites, or there might
47
 
39
// be a security risk. For now we only allow it on Behat sites.
48
// Verificación especial para sitios Behat (entorno de pruebas)
40
// If you wants to do the analysis, you may be able to remove the
49
// Esto podría ser seguro para sitios no-Behat, pero por ahora solo lo permitimos en sitios Behat
41
// if (BEHAT_SITE_RUNNING).
50
if (defined('BEHAT_SITE_RUNNING') && BEHAT_SITE_RUNNING) {
42
if (defined('BEHAT_SITE_RUNNING') && BEHAT_SITE_RUNNING) {
Línea 51... Línea -...
51
    $wantsurl = optional_param('wantsurl', '', PARAM_LOCALURL);   // Sobrescribe $SESSION->wantsurl si se proporciona
-
 
52
    if ($wantsurl !== '') {
43
    $wantsurl    = optional_param('wantsurl', '', PARAM_LOCALURL);   // Overrides $SESSION->wantsurl if given.
53
        $SESSION->wantsurl = (new moodle_url($wantsurl))->out(false);
44
    if ($wantsurl !== '') {
54
    }
45
        $SESSION->wantsurl = (new moodle_url($wantsurl))->out(false);
55
}
46
    }
-
 
47
}
Línea 56... Línea -...
56
 
-
 
57
// Configuración del contexto y la página
-
 
58
$context = context_system::instance();
-
 
59
$PAGE->set_url("$CFG->wwwroot/login/index.php");
-
 
60
$PAGE->set_context($context);
48
 
61
$PAGE->set_pagelayout('login');
49
$context = context_system::instance();
62
 
50
$PAGE->set_url("$CFG->wwwroot/login/index.php");
63
// ============================================================================
-
 
64
// CONFIGURACIÓN INICIAL Y VARIABLES
-
 
65
// ============================================================================
-
 
66
 
51
$PAGE->set_context($context);
67
// Inicialización de variables para el manejo de mensajes y errores
-
 
Línea 68... Línea 52...
68
$errormsg = '';    // Almacena mensajes de error para mostrar al usuario
52
$PAGE->set_pagelayout('login');
69
$infomsg = '';     // Almacena mensajes informativos para mostrar al usuario
53
$PAGE->set_cacheable(false);
70
$errorcode = 0;    // Código numérico que identifica el tipo de error
54
 
71
 
-
 
72
// ============================================================================
55
/// Initialize variables
73
// VERIFICACIÓN DE SESIÓN
56
$errormsg = '';
74
// ============================================================================
57
$infomsg = '';
75
 
58
$errorcode = 0;
76
// Prueba de funcionamiento de la sesión
59
 
77
if ($testsession) {
60
// login page requested session test
78
    if ($testsession == $USER->id) {
61
if ($testsession) {
79
        // Si la sesión es válida, redirigir a la URL deseada
62
    if ($testsession == $USER->id) {
80
        if (isset($SESSION->wantsurl)) {
63
        if (isset($SESSION->wantsurl)) {
81
            $urltogo = $SESSION->wantsurl;
64
            $urltogo = $SESSION->wantsurl;
82
        } else {
65
        } else {
83
            $urltogo = $CFG->wwwroot . '/';
66
            $urltogo = $CFG->wwwroot.'/';
84
        }
67
        }
Línea 85... Línea -...
85
        unset($SESSION->wantsurl);
-
 
86
        redirect($urltogo);
68
        unset($SESSION->wantsurl);
87
    } else {
-
 
88
        // Si la sesión no es válida, mostrar error de cookies
-
 
89
        $errormsg = get_string("cookiesnotenabled");
-
 
90
        $errorcode = 1;
69
        redirect($urltogo);
91
    }
70
    } else {
92
}
71
        // TODO: try to find out what is the exact reason why sessions do not work
93
 
72
        $errormsg = get_string("cookiesnotenabled");
94
// ============================================================================
73
        $errorcode = 1;
95
// MANEJO DE SESIONES EXPIRADAS
74
    }
Línea 96... Línea -...
96
// ============================================================================
-
 
97
 
75
}
98
// Verificar si la sesión actual ha expirado
76
 
Línea 99... Línea -...
99
if (!empty($SESSION->has_timed_out)) {
-
 
100
    $session_has_timed_out = true;
77
/// Check for timed out sessions
101
    unset($SESSION->has_timed_out);
78
if (!empty($SESSION->has_timed_out)) {
102
} else {
79
    $session_has_timed_out = true;
103
    $session_has_timed_out = false;
80
    unset($SESSION->has_timed_out);
104
}
81
} else {
105
 
82
    $session_has_timed_out = false;
Línea 106... Línea -...
106
// Inicialización de variables para el formulario y usuario
-
 
107
$frm = false;
-
 
108
$user = false;
-
 
Línea 109... Línea 83...
109
 
83
}
110
// Obtener la secuencia de plugins de autenticación habilitados
84
 
Línea 111... Línea 85...
111
$authsequence = get_enabled_auth_plugins();
85
$frm  = false;
-
 
86
$user = false;
-
 
87
 
112
foreach ($authsequence as $authname) {
88
$authsequence = get_enabled_auth_plugins(); // Auths, in sequence.
113
    $authplugin = get_auth_plugin($authname);
89
foreach($authsequence as $authname) {
114
    // El hook loginpage_hook() del plugin de autenticación puede establecer $frm y/o $user
90
    $authplugin = get_auth_plugin($authname);
Línea 115... Línea -...
115
    $authplugin->loginpage_hook();
-
 
116
}
-
 
117
 
-
 
118
// ============================================================================
-
 
119
// CONFIGURACIÓN DEL SITIO Y NAVEGACIÓN
-
 
120
// ============================================================================
91
    // The auth plugin's loginpage_hook() can eventually set $frm and/or $user.
121
 
92
    $authplugin->loginpage_hook();
122
// Obtener información del sitio
-
 
-
 
93
}
123
$site = get_site();
94
 
124
 
95
 
-
 
96
/// Define variables used in page
125
// Ignorar páginas activas en la navegación/configuración
97
$site = get_site();
126
$PAGE->navbar->ignore_active();
98
 
127
$loginsite = get_string("loginsite");
99
// Ignore any active pages in the navigation/settings.
128
$PAGE->navbar->add($loginsite);
100
// We do this because there won't be an active page there, and by ignoring the active pages the
129
 
101
// navigation and settings won't be initialised unless something else needs them.
130
// ============================================================================
102
$PAGE->navbar->ignore_active();
131
// PROCESO DE AUTENTICACIÓN
103
$loginsite = get_string("loginsite");
132
// ============================================================================
104
$PAGE->navbar->add($loginsite);
133
 
105
 
-
 
106
if ($user !== false or $frm !== false or $errormsg !== '') {
134
// Verificar si algún plugin de autenticación ya proporcionó el usuario completo
107
    // some auth plugin already supplied full user, fake form data or prevented user login with error message
135
if ($user !== false or $frm !== false or $errormsg !== '') {
108
 
136
    // El plugin de autenticación ya proporcionó el usuario completo, datos del formulario falso
109
} else if (!empty($SESSION->wantsurl) && file_exists($CFG->dirroot.'/login/weblinkauth.php')) {
Línea 137... Línea 110...
137
    // o impidió el inicio de sesión con mensaje de error
110
    // Handles the case of another Moodle site linking into a page on this site
-
 
111
    //TODO: move weblink into own auth plugin
-
 
112
    include($CFG->dirroot.'/login/weblinkauth.php');
138
} else if (!empty($SESSION->wantsurl) && file_exists($CFG->dirroot . '/login/weblinkauth.php')) {
113
    if (function_exists('weblink_auth')) {
139
    // Maneja el caso de otro sitio Moodle vinculando a una página en este sitio
114
        $user = weblink_auth($SESSION->wantsurl);
140
    include($CFG->dirroot . '/login/weblinkauth.php');
115
    }
141
    if (function_exists('weblink_auth')) {
116
    if ($user) {
142
        $user = weblink_auth($SESSION->wantsurl);
117
        $frm->username = $user->username;
Línea 143... Línea -...
143
    }
-
 
144
    if ($user) {
-
 
145
        $frm->username = $user->username;
118
    } else {
146
    } else {
119
        $frm = data_submitted();
147
        $frm = data_submitted();
-
 
148
    }
120
    }
149
} else {
-
 
-
 
121
 
150
    $frm = data_submitted();
122
} else {
Línea 151... Línea -...
151
}
-
 
152
 
123
    $frm = data_submitted();
153
// Restaurar el #anchor a la wantsurl original
124
}
154
if ($anchor && isset($SESSION->wantsurl) && strpos($SESSION->wantsurl, '#') === false) {
125
 
155
    $wantsurl = new moodle_url($SESSION->wantsurl);
126
// Restore the #anchor to the original wantsurl. Note that this
156
    $wantsurl->set_anchor(substr($anchor, 1));
127
// will only work for internal auth plugins, SSO plugins such as
157
    $SESSION->wantsurl = $wantsurl->out();
128
// SAML / CAS / OIDC will have to handle this correctly directly.
158
}
129
if ($anchor && isset($SESSION->wantsurl) && strpos($SESSION->wantsurl, '#') === false) {
Línea 159... Línea -...
159
 
-
 
160
// ============================================================================
130
    $wantsurl = new moodle_url($SESSION->wantsurl);
161
// VERIFICACIÓN DE CREDENCIALES
131
    $wantsurl->set_anchor(substr($anchor, 1));
162
// ============================================================================
132
    $SESSION->wantsurl = $wantsurl->out();
163
 
133
}
164
// Verificar si el usuario ha enviado datos de inicio de sesión
134
 
165
if ($frm and isset($frm->username)) {
135
/// Check if the user has actually submitted login data to us
166
    // Normalizar el nombre de usuario
136
 
167
    $frm->username = trim(core_text::strtolower($frm->username));
-
 
168
 
137
if ($frm and isset($frm->username)) {                             // Login WITH cookies
169
    // Verificar la autenticación 'none' si está habilitada
138
 
170
    if (is_enabled_auth('none')) {
139
    $frm->username = trim(core_text::strtolower($frm->username));
171
        if ($frm->username !== core_user::clean_field($frm->username, 'username')) {
140
 
172
            $errormsg = get_string('username') . ': ' . get_string("invalidusername");
141
    if (is_enabled_auth('none') ) {
Línea 173... Línea -...
173
            $errorcode = 2;
-
 
174
            $user = null;
-
 
175
        }
-
 
176
    }
-
 
177
 
142
        if ($frm->username !== core_user::clean_field($frm->username, 'username')) {
178
    // Verificar si el usuario es invitado
143
            $errormsg = get_string('username').': '.get_string("invalidusername");
179
    if ($user) {
144
            $errorcode = 2;
180
        // El plugin de autenticación ya proporcionó el usuario
145
            $user = null;
181
    } else if (($frm->username == 'guest') and empty($CFG->guestloginbutton)) {
146
        }
182
        $user = false;    // No se puede iniciar sesión como invitado si el botón de invitado está deshabilitado
147
    }
183
        $frm = false;
148
 
184
    } else {
149
    if ($user) {
185
        if (empty($errormsg)) {
150
        // The auth plugin has already provided the user via the loginpage_hook() called above.
186
            // Intentar autenticar al usuario
151
    } else if (($frm->username == 'guest') and empty($CFG->guestloginbutton)) {
187
            $logintoken = isset($frm->logintoken) ? $frm->logintoken : '';
152
        $user = false;    /// Can't log in as guest if guest button is disabled
188
            $loginrecaptcha = login_captcha_enabled() ? $frm->{'g-recaptcha-response'} ?? '' : false;
153
        $frm = false;
189
            $user = authenticate_user_login($frm->username, $frm->password, false, $errorcode, $logintoken, $loginrecaptcha);
154
    } else {
Línea 190... Línea -...
190
        }
-
 
191
    }
-
 
192
 
-
 
193
    // ============================================================================
-
 
194
    // MANEJO DE USUARIOS RESTAURADOS
155
        if (empty($errormsg)) {
-
 
156
            $logintoken = isset($frm->logintoken) ? $frm->logintoken : '';
195
    // ============================================================================
157
            $loginrecaptcha = login_captcha_enabled() ? $frm->{'g-recaptcha-response'} ?? '' : false;
196
 
158
            $user = authenticate_user_login($frm->username, $frm->password, false, $errorcode, $logintoken, $loginrecaptcha);
197
    // Procesar usuarios que han sido restaurados desde una copia de seguridad
159
        }
198
    if (!$user and $frm and is_restored_user($frm->username)) {
160
    }
-
 
161
 
199
        $PAGE->set_title(get_string('restoredaccount'));
162
    // Intercept 'restored' users to provide them with info & reset password
200
        $PAGE->set_heading($site->fullname);
163
    if (!$user and $frm and is_restored_user($frm->username)) {
201
        echo $OUTPUT->header();
164
        $PAGE->set_title(get_string('restoredaccount'));
202
        echo $OUTPUT->heading(get_string('restoredaccount'));
165
        $PAGE->set_heading($site->fullname);
Línea 203... Línea -...
203
        echo $OUTPUT->box(get_string('restoredaccountinfo'), 'generalbox boxaligncenter');
-
 
204
        require_once('restored_password_form.php');
166
        echo $OUTPUT->header();
205
        $form = new login_forgot_password_form('forgot_password.php', array('username' => $frm->username));
167
        echo $OUTPUT->heading(get_string('restoredaccount'));
206
        $form->display();
168
        echo $OUTPUT->box(get_string('restoredaccountinfo'), 'generalbox boxaligncenter');
207
        echo $OUTPUT->footer();
169
        require_once('restored_password_form.php'); // Use our "supplanter" login_forgot_password_form. MDL-20846
208
        die;
170
        $form = new login_forgot_password_form('forgot_password.php', array('username' => $frm->username));
209
    }
171
        $form->display();
Línea 234... Línea 196...
234
                } else {
196
                } else {
235
                    echo $OUTPUT->notification(get_string('emailconfirmsentsuccess'), \core\output\notification::NOTIFY_SUCCESS);
197
                    echo $OUTPUT->notification(get_string('emailconfirmsentsuccess'), \core\output\notification::NOTIFY_SUCCESS);
236
                }
198
                }
237
            }
199
            }
238
            echo $OUTPUT->box(get_string("emailconfirmsent", "", s($user->email)), "generalbox boxaligncenter");
200
            echo $OUTPUT->box(get_string("emailconfirmsent", "", s($user->email)), "generalbox boxaligncenter");
239
            $resendconfirmurl = new moodle_url(
201
            $resendconfirmurl = new moodle_url('/login/index.php',
240
                '/login/index.php',
-
 
241
                [
202
                [
242
                    'username' => $frm->username,
203
                    'username' => $frm->username,
243
                    'password' => $frm->password,
204
                    'password' => $frm->password,
244
                    'resendconfirmemail' => true,
205
                    'resendconfirmemail' => true,
245
                    'logintoken' => \core\session\manager::get_login_token()
206
                    'logintoken' => \core\session\manager::get_login_token()
Línea 248... Línea 209...
248
            echo $OUTPUT->single_button($resendconfirmurl, get_string('emailconfirmationresend'));
209
            echo $OUTPUT->single_button($resendconfirmurl, get_string('emailconfirmationresend'));
249
            echo $OUTPUT->footer();
210
            echo $OUTPUT->footer();
250
            die;
211
            die;
251
        }
212
        }
Línea 252... Línea -...
252
 
-
 
253
        // ============================================================================
213
 
254
        // COMPLETAR INICIO DE SESIÓN
-
 
255
        // ============================================================================
-
 
256
 
-
 
257
        // Completar el proceso de inicio de sesión
214
    /// Let's get them all set up.
Línea 258... Línea -...
258
        complete_user_login($user);
-
 
259
 
215
        complete_user_login($user);
Línea 260... Línea 216...
260
        // Aplicar límite de inicio de sesión concurrente
216
 
261
        \core\session\manager::apply_concurrent_login_limit($user->id, session_id());
217
        \core\session\manager::apply_concurrent_login_limit($user->id, session_id());
262
 
218
 
-
 
219
        // sets the username cookie
-
 
220
        if (!empty($CFG->nolastloggedin)) {
-
 
221
            // do not store last logged in user in cookie
263
        // Configurar cookie de nombre de usuario
222
            // auth plugins can temporarily override this from loginpage_hook()
264
        if (!empty($CFG->nolastloggedin)) {
223
            // do not save $CFG->nolastloggedin in database!
265
            // No almacenar último usuario conectado en cookie
224
 
-
 
225
        } else if (empty($CFG->rememberusername)) {
266
        } else if (empty($CFG->rememberusername)) {
226
            // no permanent cookies, delete old one if exists
267
            // Sin cookies permanentes, eliminar la anterior si existe
227
            set_moodle_cookie('');
268
            set_moodle_cookie('');
228
 
Línea 269... Línea -...
269
        } else {
-
 
270
            set_moodle_cookie($USER->username);
229
        } else {
Línea 271... Línea -...
271
        }
-
 
272
 
230
            set_moodle_cookie($USER->username);
273
        // Obtener URL de redirección
-
 
274
        $urltogo = core_login_get_return_url();
-
 
275
 
231
        }
276
        // ============================================================================
232
 
277
        // VERIFICACIÓN DE CONTRASEÑAS EXPIRADAS
233
        $urltogo = core_login_get_return_url();
278
        // ============================================================================
234
 
279
 
235
    /// check if user password has expired
280
        // Verificar si la contraseña del usuario ha expirado (solo para autenticación LDAP)
236
    /// Currently supported only for ldap-authentication module
281
        $userauth = get_auth_plugin($USER->auth);
237
        $userauth = get_auth_plugin($USER->auth);
282
        if (!isguestuser() and !empty($userauth->config->expiration) and $userauth->config->expiration == 1) {
238
        if (!isguestuser() and !empty($userauth->config->expiration) and $userauth->config->expiration == 1) {
283
            $externalchangepassword = false;
239
            $externalchangepassword = false;
284
            if ($userauth->can_change_password()) {
240
            if ($userauth->can_change_password()) {
285
                $passwordchangeurl = $userauth->change_password_url();
241
                $passwordchangeurl = $userauth->change_password_url();
286
                if (!$passwordchangeurl) {
242
                if (!$passwordchangeurl) {
287
                    $passwordchangeurl = $CFG->wwwroot . '/login/change_password.php';
243
                    $passwordchangeurl = $CFG->wwwroot.'/login/change_password.php';
288
                } else {
244
                } else {
289
                    $externalchangepassword = true;
245
                    $externalchangepassword = true;
290
                }
246
                }
291
            } else {
247
            } else {
292
                $passwordchangeurl = $CFG->wwwroot . '/login/change_password.php';
248
                $passwordchangeurl = $CFG->wwwroot.'/login/change_password.php';
293
            }
249
            }
294
            $days2expire = $userauth->password_expire($USER->username);
250
            $days2expire = $userauth->password_expire($USER->username);
295
            $PAGE->set_title($loginsite);
251
            $PAGE->set_title($loginsite);
296
            $PAGE->set_heading("$site->fullname");
252
            $PAGE->set_heading("$site->fullname");
297
            if (intval($days2expire) > 0 && intval($days2expire) < intval($userauth->config->expiration_warning)) {
253
            if (intval($days2expire) > 0 && intval($days2expire) < intval($userauth->config->expiration_warning)) {
298
                echo $OUTPUT->header();
254
                echo $OUTPUT->header();
299
                echo $OUTPUT->confirm(get_string('auth_passwordwillexpire', 'auth', $days2expire), $passwordchangeurl, $urltogo);
255
                echo $OUTPUT->confirm(get_string('auth_passwordwillexpire', 'auth', $days2expire), $passwordchangeurl, $urltogo);
-
 
256
                echo $OUTPUT->footer();
300
                echo $OUTPUT->footer();
257
                exit;
301
                exit;
258
            } elseif (intval($days2expire) < 0 ) {
-
 
259
                if ($externalchangepassword) {
302
            } elseif (intval($days2expire) < 0) {
260
                    // We end the session if the change password form is external. This prevents access to the site
303
                if ($externalchangepassword) {
261
                    // until the password is correctly changed.
304
                    // Cerrar sesión si el formulario de cambio de contraseña es externo
262
                    require_logout();
305
                    require_logout();
263
                } else {
306
                } else {
264
                    // If we use the standard change password form, this user preference will be reset when the password
307
                    // Forzar cambio de contraseña si se usa el formulario estándar
265
                    // is changed. Until then it will prevent access to the site.
308
                    set_user_preference('auth_forcepasswordchange', 1, $USER);
266
                    set_user_preference('auth_forcepasswordchange', 1, $USER);
309
                }
267
                }
310
                echo $OUTPUT->header();
268
                echo $OUTPUT->header();
Línea 311... Línea 269...
311
                echo $OUTPUT->confirm(get_string('auth_passwordisexpired', 'auth'), $passwordchangeurl, $urltogo);
269
                echo $OUTPUT->confirm(get_string('auth_passwordisexpired', 'auth'), $passwordchangeurl, $urltogo);
312
                echo $OUTPUT->footer();
270
                echo $OUTPUT->footer();
313
                exit;
271
                exit;
Línea 314... Línea 272...
314
            }
272
            }
315
        }
273
        }
Línea 316... Línea 274...
316
 
274
 
317
        // Limpiar mensajes de error antes de la última redirección
275
        // Discard any errors before the last redirect.
318
        unset($SESSION->loginerrormsg);
276
        unset($SESSION->loginerrormsg);
-
 
277
        unset($SESSION->logininfomsg);
319
        unset($SESSION->logininfomsg);
278
 
320
 
-
 
321
        // Descartar loginredirect si estamos redirigiendo
279
        // Discard loginredirect if we are redirecting away.
322
        unset($SESSION->loginredirect);
280
        unset($SESSION->loginredirect);
323
 
281
 
324
        // Probar que la sesión funciona redirigiendo a sí mismo
282
        // test the session actually works by redirecting to self
325
        $SESSION->wantsurl = $urltogo;
283
        $SESSION->wantsurl = $urltogo;
Línea 337... Línea 295...
337
            }
295
            }
338
        }
296
        }
339
    }
297
    }
340
}
298
}
Línea 341... Línea -...
341
 
-
 
342
// ============================================================================
-
 
343
// DETECCIÓN DE PROBLEMAS CON SESIONES
-
 
344
// ============================================================================
-
 
345
 
299
 
346
// Detectar problemas con sesiones con tiempo de espera agotado
300
/// Detect problems with timedout sessions
347
if ($session_has_timed_out and !data_submitted()) {
301
if ($session_has_timed_out and !data_submitted()) {
348
    $errormsg = get_string('sessionerroruser', 'error');
302
    $errormsg = get_string('sessionerroruser', 'error');
349
    $errorcode = 4;
303
    $errorcode = 4;
Línea 350... Línea -...
350
}
-
 
351
 
-
 
352
// ============================================================================
304
}
Línea 353... Línea -...
353
// MANEJO DE URL DE DESTINO
-
 
354
// ============================================================================
305
 
355
 
306
/// First, let's remember where the user was trying to get to before they got here
356
// Recordar dónde estaba intentando llegar el usuario antes de llegar aquí
307
 
357
if (empty($SESSION->wantsurl)) {
-
 
358
    $SESSION->wantsurl = null;
308
if (empty($SESSION->wantsurl)) {
359
    $referer = get_local_referer(false);
309
    $SESSION->wantsurl = null;
360
    if (
310
    $referer = get_local_referer(false);
361
        $referer &&
311
    if ($referer &&
362
        $referer != $CFG->wwwroot &&
312
            $referer != $CFG->wwwroot &&
363
        $referer != $CFG->wwwroot . '/' &&
313
            $referer != $CFG->wwwroot . '/' &&
364
        $referer != $CFG->wwwroot . '/login/' &&
-
 
365
        strpos($referer, $CFG->wwwroot . '/login/?') !== 0 &&
314
            $referer != $CFG->wwwroot . '/login/' &&
366
        strpos($referer, $CFG->wwwroot . '/login/index.php') !== 0
315
            strpos($referer, $CFG->wwwroot . '/login/?') !== 0 &&
367
    ) {
316
            strpos($referer, $CFG->wwwroot . '/login/index.php') !== 0) { // There might be some extra params such as ?lang=.
Línea 368... Línea 317...
368
        $SESSION->wantsurl = $referer;
317
        $SESSION->wantsurl = $referer;
369
    }
318
    }
370
}
319
}
371
 
320
 
372
// Verificar si loginredirect está establecido en la SESSION
321
// Check if loginredirect is set in the SESSION.
Línea 373... Línea -...
373
if ($errorcode && isset($SESSION->loginredirect)) {
-
 
374
    $loginredirect = $SESSION->loginredirect;
-
 
375
}
-
 
376
$SESSION->loginredirect = $loginredirect;
-
 
377
 
322
if ($errorcode && isset($SESSION->loginredirect)) {
378
// ============================================================================
323
    $loginredirect = $SESSION->loginredirect;
379
// REDIRECCIÓN A URL DE INICIO DE SESIÓN ALTERNATIVA
324
}
-
 
325
$SESSION->loginredirect = $loginredirect;
380
// ============================================================================
326
 
Línea 381... Línea 327...
381
 
327
/// Redirect to alternative login URL if needed
382
// Redirigir a URL de inicio de sesión alternativa si es necesario
328
if (!empty($CFG->alternateloginurl) && $loginredirect) {
383
if (!empty($CFG->alternateloginurl) && $loginredirect) {
329
    $loginurl = new moodle_url($CFG->alternateloginurl);
384
    $loginurl = new moodle_url($CFG->alternateloginurl);
330
 
Línea 385... Línea 331...
385
    $loginurlstr = $loginurl->out(false);
331
    $loginurlstr = $loginurl->out(false);
386
 
332
 
387
    if ($SESSION->wantsurl != '' && strpos($SESSION->wantsurl, $loginurlstr) === 0) {
333
    if ($SESSION->wantsurl != '' && strpos($SESSION->wantsurl, $loginurlstr) === 0) {
388
        // No queremos volver a la URL alternativa
334
        // We do not want to return to alternate url.
Línea 389... Línea 335...
389
        $SESSION->wantsurl = null;
335
        $SESSION->wantsurl = null;
390
    }
336
    }
Línea 391... Línea -...
391
 
-
 
392
    // Si hay código de error, agregarlo a la URL
337
 
393
    if ($errorcode) {
-
 
Línea 394... Línea -...
394
        $loginurl->param('errorcode', $errorcode);
-
 
395
    }
338
    // If error code then add that to url.
396
 
339
    if ($errorcode) {
397
    redirect($loginurl->out(false));
340
        $loginurl->param('errorcode', $errorcode);
Línea 398... Línea -...
398
}
-
 
399
 
341
    }
400
// ============================================================================
342
 
-
 
343
    redirect($loginurl->out(false));
401
// GENERACIÓN DE LA PÁGINA DE INICIO DE SESIÓN
344
}
402
// ============================================================================
345
 
403
 
346
/// Generate the login page with forms
404
// Inicializar el objeto del formulario si no existe
347
 
-
 
348
if (!isset($frm) or !is_object($frm)) {
405
if (!isset($frm) or !is_object($frm)) {
349
    $frm = new stdClass();
406
    $frm = new stdClass();
350
}
Línea 407... Línea -...
407
}
-
 
408
 
351
 
-
 
352
if (empty($frm->username) && $authsequence[0] != 'shibboleth') {  // See bug 5184
409
// Configurar valores predeterminados del formulario
353
    if (!empty($_GET["username"])) {
410
if (empty($frm->username) && $authsequence[0] != 'shibboleth') {
354
        // we do not want data from _POST here
411
    if (!empty($_GET["username"])) {
355
        $frm->username = clean_param($_GET["username"], PARAM_RAW); // we do not want data from _POST here
412
        $frm->username = clean_param($_GET["username"], PARAM_RAW);
356
    } else {
-
 
357
        $frm->username = get_moodle_cookie();
413
    } else {
358
    }
-
 
359
 
414
        $frm->username = get_moodle_cookie();
360
    $frm->password = "";
415
    }
361
}
-
 
362
 
416
    $frm->password = "";
363
if (!empty($SESSION->loginerrormsg) || !empty($SESSION->logininfomsg)) {
-
 
364
    // We had some messages before redirect, show them now.
417
}
365
    $errormsg = $SESSION->loginerrormsg ?? '';
418
 
366
    $infomsg = $SESSION->logininfomsg ?? '';
419
// Manejar mensajes de error e información
367
    unset($SESSION->loginerrormsg);
-
 
368
    unset($SESSION->logininfomsg);
-
 
369
 
420
if (!empty($SESSION->loginerrormsg) || !empty($SESSION->logininfomsg)) {
370
} else if ($testsession) {
421
    $errormsg = $SESSION->loginerrormsg ?? '';
371
    // No need to redirect here.
-
 
372
    unset($SESSION->loginerrormsg);
422
    $infomsg = $SESSION->logininfomsg ?? '';
373
    unset($SESSION->logininfomsg);
423
    unset($SESSION->loginerrormsg);
374
 
Línea 424... Línea -...
424
    unset($SESSION->logininfomsg);
-
 
425
} else if ($testsession) {
-
 
426
    unset($SESSION->loginerrormsg);
-
 
427
    unset($SESSION->logininfomsg);
-
 
428
} else if ($errormsg or !empty($frm->password)) {
-
 
429
    if ($errormsg) {
375
} else if ($errormsg or !empty($frm->password)) {
430
        $SESSION->loginerrormsg = $errormsg;
376
    // We must redirect after every password submission.
Línea 431... Línea -...
431
    }
-
 
432
    $loginurl = new moodle_url('/login/index.php');
377
    if ($errormsg) {
Línea 433... Línea -...
433
    $loginurl->param('loginredirect', $SESSION->loginredirect);
-
 
434
    redirect($loginurl->out(false));
378
        $SESSION->loginerrormsg = $errormsg;
435
}
379
    }
436
 
380
 
437
// ============================================================================
381
    // Add redirect param to url.
438
// RENDERIZADO DE LA PÁGINA
382
    $loginurl = new moodle_url('/login/index.php');
439
// ============================================================================
383
    $loginurl->param('loginredirect', $SESSION->loginredirect);
440
 
384
 
441
// Configurar título y encabezado de la página
385
    redirect($loginurl->out(false));
442
$PAGE->set_title($loginsite);
-
 
443
$PAGE->set_heading("$site->fullname");
386
}
444
 
387
 
445
// Mostrar el encabezado de la página
388
$PAGE->set_title($loginsite);
446
echo $OUTPUT->header();
389
$PAGE->set_heading("$site->fullname");
447
 
390
 
Línea 448... Línea -...
448
// Verificar el estado de la sesión del usuario
-
 
449
if (isloggedin() and !isguestuser()) {
391
echo $OUTPUT->header();