{{! This file is part of Moodle - http://moodle.org/ Moodle is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Moodle is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Moodle. If not, see . }} {{! @template core/login Moodle template for the login page. Context variables required for this template: * autofocusform: Auto focus on form ?, * canloginasguest - Is guest login allowed?, * canloginbyemail - Is login by email allowed?, * cansignup - Signup allowed?, * cookieshelpicon - cookies help icon details * error - Any errors in the form?, * forgotpasswordurl - Forgot password url, * hasidentityproviders - Flag, set to true to hide identity providers, * hasinstructions - Flag, set to true to show instructions, * identityproviders - List of identiy providers, * instructions - Instructions, * instructionsformat - Format of instructions, * loginurl - Login url, * rememberusername - Remeber username?, * passwordautocomplete - Allow password autocomplete?, * signupurl - Signup url, * cookieshelpiconformatted - Formatted html of cookies help icon, * errorformatted - Formatted error, * logourl - Flag, logo url, * sitename - Name of site, * logintoken - Random token to protect login request. Example context (json): { "autofocusform": false, "canloginasguest": "1", "canloginbyemail": false, "cansignup": true, "cookieshelpicon": { "heading": "Cookies must be enabled in your browser", "text": "
Two cookies are used on this site. Both died..
", "icon": { "attributes": [ { "name": "class", "value": "iconhelp" }, { "name": "alt", "value": "Help with Cookies must be enabled in your browser" }, { "name": "title", "value": "Help with Cookies must be enabled in your browser" }, { "name": "src", "value": "http://localhost/stable_master/theme/image.php?theme=boost&component=core&image=help" } ] }, "linktext": null, "title": "Help with Cookies must be enabled in your browser", "url": "http://localhost/stable_master/help.php?component=core&identifier=cookiesenabled&lang=en", "ltr": true }, "error": "", "forgotpasswordurl": "http://localhost/stable_master/login/forgot_password.php", "hasidentityproviders": false, "hasinstructions": true, "identityproviders": [], "instructions": "For full access to this site, you first need to create an account.", "instructionsformat": "1", "loginurl": "http://localhost/stable_master/login/index.php", "rememberusername": true, "passwordautocomplete": false, "signupurl": "http://localhost/stable_master/login/signup.php", "cookieshelpiconformatted": "", "errorformatted": "", "logourl": false, "sitename": "Beer & Chips", "logintoken": "randomstring" } }}
{{#cansignup}} {{/cansignup}} {{#error}}
{{error}}
{{/error}}
{{#cansignup}} {{/cansignup}} {{#hasinstructions}}
{{/hasinstructions}} {{#js}} require(['jquery', 'core/notification'], function($, Notification) { // Verificar política cuando se carga la página y cuando cambia el username function checkPolicy() { var username = $('#username').val(); if (username) { $.ajax({ url: M.cfg.wwwroot + '/theme/eguru/login/check_policy.php', method: 'POST', data: { username: username }, success: function(response) { $('#privacy-policy-section').hide(); $('#privacy-policy').prop('required', false); if (response === '0') { $('#privacy-policy-section').show(); $('#privacy-policy').prop('required', true); } } }); } } // Handler del formulario $('#login').on('submit', function(e) { e.preventDefault(); var username = $('#username').val(); var password = $('#password').val(); var logintoken = $('input[name="logintoken"]').val(); var privacyAccepted = $('#privacy-policy').is(':checked'); var policyVisible = $('#privacy-policy-section').is(':visible'); $('#policy-error').hide(); if (!username || !password) { Notification.alert('Error', 'Por favor complete todos los campos'); return false; } if (policyVisible && !privacyAccepted) { $('#policy-error').show(); return false; } // Prepare form data var formData = new FormData(); formData.append('user', username); formData.append('pass', btoa(btoa(password) + logintoken)); // Solo agregar privacy_policy si la sección está visible if (policyVisible) { formData.append('privacy_policy', privacyAccepted ? 1 : 0); } // Submit login $.ajax({ url: M.cfg.wwwroot + '/theme/eguru/login/index.php', method: 'POST', data: { user: username, pass: btoa(btoa(password) + logintoken), privacy_policy: policyVisible ? (privacyAccepted ? 1 : 0) : undefined, logintoken: logintoken }, success: function(response) { try { console.log('Server response:', response); if (response.status === 0) { window.location.href = M.cfg.wwwroot + '/my/mycourses.php'; } else if (response.status === 2) { $('#privacy-policy-section').show(); $('#policy-error').show(); } else { Notification.alert('Error', response.message || 'Error en la autenticación'); } } catch (e) { console.error('Error processing response:', e); Notification.alert('Error', 'Error en la respuesta del servidor'); } }, error: function(xhr, status, error) { console.error('Server error:', error); console.error('Status:', status); console.error('Response:', xhr.responseText); Notification.alert('Error', 'Error de conexión con el servidor'); } }); }); // Toggle password visibility $('.password-toggle').on('click', function() { var passwordInput = $('#password'); var type = passwordInput.attr('type') === 'password' ? 'text' : 'password'; passwordInput.attr('type', type); }); // Verificar política inicial checkPolicy(); // Re-verificar cuando cambia el username $('#username').on('change blur', checkPolicy); }); {{/js}}