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