import { readFileSync } from 'fs'; import { randomBytes } from 'crypto'; import cheerio from 'cheerio'; import Wiki from '../util/wiki.js'; import { allLangs } from './i18n.js'; import { got, db, oauth, enabledOAuth2, sessionData, settingsData, oauthVerify, sendMsg, addWidgets, createNotice, hasPerm } from './util.js'; import { createRequire } from 'module'; const require = createRequire(import.meta.url); const {defaultPermissions} = require('../util/default.json'); const allLangNames = allLangs().names; const file = readFileSync('./dashboard/login.html'); /** * Let a user login * @param {import('http').ServerResponse} res - The server response * @param {import('./i18n.js').default} dashboardLang - The user language. * @param {String} theme - The display theme * @param {String} [state] - The user state * @param {String} [action] - The action the user made */ function dashboard_login(res, dashboardLang, theme, state, action) { if ( state && sessionData.has(state) ) { if ( !action ) { res.writeHead(302, {Location: '/'}); return res.end(); } sessionData.delete(state); } var $ = cheerio.load(file); $('html').attr('lang', dashboardLang.lang); if ( theme === 'light' ) $('html').addClass('theme-light'); $('