mirror of
https://github.com/QuiteAFancyEmerald/Holy-Unblocker.git
synced 2025-05-13 03:50:02 -04:00
Cookie Auth
This commit is contained in:
parent
f2b7ca0764
commit
18f94a081b
1 changed files with 232 additions and 214 deletions
30
app.js
30
app.js
|
@ -23,8 +23,13 @@
|
|||
key: fs.readFileSync('./ssl/default.key'),
|
||||
cert: fs.readFileSync('./ssl/default.crt')
|
||||
}
|
||||
if (config.ssl == true) { server = https.createServer(server_options, app); server_protocol = 'https://';}
|
||||
else { server = http.createServer(app); server_protocol = 'http://';};
|
||||
if (config.ssl == true) {
|
||||
server = https.createServer(server_options, app);
|
||||
server_protocol = 'https://';
|
||||
} else {
|
||||
server = http.createServer(app);
|
||||
server_protocol = 'http://';
|
||||
};
|
||||
|
||||
|
||||
console.log(`Alloy Proxy now running on ${server_protocol}0.0.0.0:${config.port}! Proxy prefix is "${config.prefix}"!`);
|
||||
|
@ -52,12 +57,27 @@
|
|||
}
|
||||
if (websitePath == '/') { return `${websiteURL}`; } else return `${websiteURL}${websitePath}`;
|
||||
};
|
||||
|
||||
const uuid = require('uuid/v4')
|
||||
app.use(session({
|
||||
secret: 'alloy',
|
||||
genid: (req) => {
|
||||
return uuid() // use UUIDs for session IDs
|
||||
},
|
||||
saveUninitialized: true,
|
||||
resave: true
|
||||
}));
|
||||
app.post('/home/session', (req, res, next) => {
|
||||
console.log('Inside POST /home/session callback')
|
||||
session.authenticate('local', (err, user, info) => {
|
||||
console.log('Inside authenticate() callback');
|
||||
console.log(`req.session: ${JSON.stringify(req.session)}`)
|
||||
console.log(`req.user: ${JSON.stringify(req.user)}`)
|
||||
req.login(user, (err) => {
|
||||
console.log('Inside req.login() callback')
|
||||
return res.send('You were authenticated & logged in!\n');
|
||||
})
|
||||
})(req, res, next);
|
||||
})
|
||||
// We made our own version of body-parser instead, due to issues.
|
||||
app.use((req, res, next) => {
|
||||
if (req.method == 'POST') {
|
||||
|
@ -94,9 +114,7 @@
|
|||
|
||||
app.post(`${config.prefix}session/`, async(req, res, next) => {
|
||||
let url = querystring.parse(req.raw_body).url;
|
||||
if (url.startsWith('//')) { url = 'http:' + url; }
|
||||
else if (url.startsWith('https://') || url.startsWith('http://')) { url = url }
|
||||
else {url = 'http://' + url};
|
||||
if (url.startsWith('//')) { url = 'http:' + url; } else if (url.startsWith('https://') || url.startsWith('http://')) { url = url } else { url = 'http://' + url };
|
||||
return res.redirect(config.prefix + rewrite_url(url));
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue