Added kickConnections to channelManager

This commit is contained in:
rainbow napkin 2024-12-01 20:48:42 -05:00
parent 0432c9d1cc
commit b138b26f27
6 changed files with 37 additions and 15 deletions

View file

@ -119,7 +119,11 @@ userBanSchema.statics.banByUserDoc = async function(userDB, permanent, expiratio
}
//Log the user out
await userDB.killAllSessions();
if(permanent){
await userDB.killAllSessions(`Your account has been permanently banned, and will be nuked from the database in ${expirationDays} day(s).`);
}else{
await userDB.killAllSessions(`Your account has been temporarily banned, and will be reinstated in: ${expirationDays} day(s).`);
}
//Add the ban to the database
return await this.create({user: userDB._id, permanent, expirationDays});

View file

@ -113,7 +113,7 @@ userSchema.pre('save', async function (next){
}
if(this.isModified("rank")){
await this.killAllSessions();
await this.killAllSessions("Your site-wide rank has changed. Sign-in required.");
}
//All is good, continue on saving.
@ -235,7 +235,7 @@ userSchema.statics.getUserList = async function(fullList = false){
}
//note: if you gotta call this from a request authenticated by it's user, make sure to kill that session first!
userSchema.methods.killAllSessions = async function(){
userSchema.methods.killAllSessions = async function(reason = "A full log-out from all devices was requested for your account."){
//get authenticated sessions
var sessions = await this.getAuthenticatedSessions();
@ -243,6 +243,9 @@ userSchema.methods.killAllSessions = async function(){
sessions.forEach((session) => {
server.store.destroy(session.seshid);
});
//Tell the application side of the house to kick the user out as well
server.channelManager.kickConnections(this.user, reason);
}
userSchema.methods.passwordReset = async function(passChange){
@ -255,7 +258,7 @@ userSchema.methods.passwordReset = async function(passChange){
await this.save();
//Kill all authed sessions for security purposes
await this.killAllSessions();
await this.killAllSessions("Your password has been reset.");
}else{
//confirmation pass doesn't match
throw new Error("Mismatched confirmation password!");
@ -277,7 +280,7 @@ userSchema.methods.nuke = async function(pass){
var oldUser = await module.exports.userModel.deleteOne(this);
if(oldUser){
await this.killAllSessions();
await this.killAllSessions("This account has been deleted. So long, and thanks for all the fish! <3");
}else{
throw new Error("Server Error: Unable to delete account! Please report this error to your server administrator, and with timestamp.");
}