"use strict"; const SessionManager = (function(){ const SessionManager = function(judge_pole){ const self = this; let current_user = null; // Comprueba si existe al menos un usuario con contraseƱa registrada this.is_auth_required = () => { const users = judge_pole.db.get_data().users || []; return users.some(u => u.password && u.password.trim().length > 0); }; // Si no hay usuarios con contraseƱa, cualquiera es admin por defecto this.is_admin = () => { if(!self.is_auth_required()) return true; return current_user !== null; }; this.get_user = () => current_user; this.login = (nick, password) => { const users = judge_pole.db.get_data().users || []; const user = users.find(u => u.nick.trim().toLowerCase() === nick.trim().toLowerCase() && u.password === password ); if(user){ current_user = user; return true; } return false; }; this.logout = () => { current_user = null; }; }; return SessionManager; })();