Initial commit.
This commit is contained in:
commit
f0c91b4e55
78 changed files with 5054 additions and 0 deletions
48
src/utils/sessionUtils.js
Normal file
48
src/utils/sessionUtils.js
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
/*Canopy - The next generation of stoner streaming software
|
||||
Copyright (C) 2024 Rainbownapkin and the TTN Community
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.*/
|
||||
|
||||
//local imports
|
||||
const userModel = require('../schemas/userSchema.js');
|
||||
|
||||
//this module is good for keeping wrappers for userModel and other shit in that does more session handling than database access/modification.
|
||||
|
||||
module.exports.authenticateSession = async function(user, pass, req){
|
||||
|
||||
//Authenticate the session
|
||||
userDB = await userModel.authenticate(user, pass);
|
||||
|
||||
//Tattoo the session with user and metadata
|
||||
//unfortunately store.all() does not return sessions w/ their ID so we had to improvise...
|
||||
//Not sure if this is just how connect-mongo is implemented or if it's an express issue, but connect-mongodb-session seems to not implement the all() function what so ever...
|
||||
req.session.seshid = req.session.id;
|
||||
req.session.authdate = new Date();
|
||||
req.session.authip = req.ip;
|
||||
req.session.user = {
|
||||
user: userDB.user,
|
||||
id: userDB.id
|
||||
}
|
||||
|
||||
|
||||
//userDB.activeSessions.push(sessionData);
|
||||
await userDB.save();
|
||||
|
||||
//return user
|
||||
return userDB.user;
|
||||
}
|
||||
|
||||
module.exports.killSession = async function(session){
|
||||
session.destroy();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue