const express = require("express"); const { NetHelperModule } = global.moduleApi; const HTTPReverse = require("../components/http-reverse"); module.exports = class CustomAuthPage extends NetHelperModule { constructor () { super(); this.router = express.Router(); this.cauth = new this.statics.Operator("cauth", (argv) => { return argv.length === 2; }, (argv, self, syntaxTree) => { if (![HTTPReverse].includes(syntaxTree.Type)) { throw new SyntaxError("Unsupported type of server"); } const [ login, password ] = argv; const router = this.router; router.get("/auth/:redirectTo", (req, res, next) => { if (req.cookies.auth === login + ":" + password) return next(); const endless = req.query.login + ":" + req.query.password; const redirectTo = Buffer.from(req.params.redirectTo, "hex").toString("utf8"); //console.log("redirect to:", redirectTo); if (endless === login + ":" + password) { res.cookie("auth", endless); } res.redirect(redirectTo); }); router.use((req, res, next) => { //console.log('Cookies: ', req.cookies); if (req.cookies.auth === login + ":" + password) return next(); res.send('

Needs auth


Логин:

Пароль:

'); }); }); this.operators.push(this.cauth); this.emit("runned", () => { this.serverType.app.use(router); }); } bind (type) { super.bind(type); this.serverType.routelist.push(this.router); } };