mirror of
https://github.com/QuiteAFancyEmerald/Holy-Unblocker.git
synced 2025-05-13 03:50:02 -04:00
Cookie Auth Skeleton
This commit is contained in:
parent
55910ea89e
commit
939828c7c4
2 changed files with 287 additions and 213 deletions
10
app.js
10
app.js
|
@ -23,9 +23,11 @@
|
|||
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://'; };
|
||||
|
||||
var login = require('./login');
|
||||
|
||||
console.log(`Alloy Proxy now running on ${server_protocol}0.0.0.0:${config.port}! Proxy prefix is "${config.prefix}"!`);
|
||||
server.listen(process.env.PORT || config.port);
|
||||
|
@ -94,9 +96,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));
|
||||
});
|
||||
|
||||
|
|
74
auth.js
Normal file
74
auth.js
Normal file
|
@ -0,0 +1,74 @@
|
|||
/**
|
||||
* Login Class
|
||||
*/
|
||||
function Login() {
|
||||
// sessionId -> user map
|
||||
this.sessionMap = {
|
||||
99999: { name: 'Foo', email: 'foo@bar.com' }
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Say Hello {name} to the user
|
||||
*/
|
||||
Login.prototype.hello = function(sessionId) {
|
||||
if (this.sessionMap[sessionId] == null) {
|
||||
|
||||
return 'Please Login.!';
|
||||
} else {
|
||||
return 'Hello, ' + this.sessionMap[sessionId].name;
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Get Current Session id user name
|
||||
*/
|
||||
Login.prototype.getName = function(sessionId) {
|
||||
return this.sessionMap[sessionId].name;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get Current Session id user email
|
||||
*/
|
||||
Login.prototype.getEmail = function(sessionId) {
|
||||
return this.sessionMap[sessionId].email;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Check whether the given session id is valid (is in sessionMap) or not.
|
||||
*/
|
||||
Login.prototype.isLoggedIn = function(sessionId) {
|
||||
return sessionId in this.sessionMap;
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a new session id for the given user.
|
||||
*/
|
||||
Login.prototype.login = function(_name, _email) {
|
||||
var sessionId = new Date().getTime();
|
||||
this.sessionMap[sessionId] = { name: _name, email: _email }
|
||||
console.log("inside login functionwh ich take email \n")
|
||||
console.log('\n new session id ' + sessionId + ' for login::' + _email);
|
||||
return sessionId;
|
||||
};
|
||||
|
||||
/**
|
||||
* Remove specific refreshed session from SessionMap
|
||||
**/
|
||||
Login.prototype.RefreshSession = function(_sessionId) {
|
||||
// Delete the session id from sessionMap
|
||||
delete this.sessionMap[_sessionId];
|
||||
return "done";
|
||||
};
|
||||
|
||||
/**
|
||||
* Logout from the server
|
||||
*/
|
||||
Login.prototype.logout = function(sessionId) {
|
||||
console.log('logout::' + sessionId);
|
||||
// Delete the session id from sessionMap
|
||||
delete this.sessionMap[sessionId];
|
||||
|
||||
};
|
||||
|
||||
// Export the Login class
|
||||
module.exports = new Login();
|
Loading…
Add table
Add a link
Reference in a new issue