Added kickConnections to channelManager
This commit is contained in:
parent
0432c9d1cc
commit
b138b26f27
|
|
@ -152,21 +152,33 @@ module.exports = class{
|
|||
return chanList;
|
||||
}
|
||||
|
||||
getConnections(socket){
|
||||
//Create a list to store our connections
|
||||
var connections = [];
|
||||
|
||||
crawlConnections(user, cb){
|
||||
//For each channel
|
||||
this.activeChannels.forEach((channel) => {
|
||||
//Check and see if the user is connected
|
||||
const foundUser = channel.userList.get(socket.user.user);
|
||||
const foundUser = channel.userList.get(user);
|
||||
|
||||
//If we found a user and this channel hasn't been added to the list
|
||||
if(foundUser){
|
||||
connections.push(foundUser);
|
||||
cb(foundUser);
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
getConnections(user){
|
||||
//Create a list to store our connections
|
||||
var connections = [];
|
||||
|
||||
//crawl through connections
|
||||
//this.crawlConnections(user,(foundUser)=>{connections.push(foundUser)});
|
||||
this.crawlConnections(user,(foundUser)=>{connections.push(foundUser)});
|
||||
|
||||
//return connects
|
||||
return connections;
|
||||
}
|
||||
|
||||
kickConnections(user, reason){
|
||||
//crawl through connections and kick user
|
||||
this.crawlConnections(user,(foundUser)=>{foundUser.disconnect(reason)});
|
||||
}
|
||||
}
|
||||
|
|
@ -61,7 +61,7 @@ module.exports = class{
|
|||
userDB.flair = data.flair;
|
||||
userDB = await userDB.save();
|
||||
|
||||
const connections = this.server.getConnections(socket);
|
||||
const connections = this.server.getConnections(socket.user.user);
|
||||
|
||||
connections.forEach((conn) => {
|
||||
conn.updateFlair(userDB.flair);
|
||||
|
|
|
|||
|
|
@ -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});
|
||||
|
|
|
|||
|
|
@ -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.");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ module.exports.authenticateSession = async function(user, pass, req){
|
|||
//Make the number a little prettier despite the lack of precision since we're not doing calculations here :P
|
||||
const expiration = banDB.getDaysUntilExpiration() < 1 ? 0 : banDB.getDaysUntilExpiration();
|
||||
if(banDB.permanent){
|
||||
throw new Error(`Your account has been banned, and will be permanently deleted in: ${expiration} day(s)`);
|
||||
throw new Error(`Your account has been permanently banned, and will be nuked from the database in: ${expiration} day(s)`);
|
||||
}else{
|
||||
throw new Error(`Your account has been temporarily banned, and will be reinstated in: ${expiration} day(s)`);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,6 +56,7 @@ p.navbar-item, input.navbar-item{
|
|||
bottom: 0;
|
||||
right: 0;
|
||||
left: 0;
|
||||
z-index: 9000;
|
||||
}
|
||||
|
||||
.popup-div{
|
||||
|
|
@ -69,6 +70,8 @@ p.navbar-item, input.navbar-item{
|
|||
left: 0;
|
||||
height: fit-content;
|
||||
width: fit-content;
|
||||
/*This joke is probably old enough to drink by now*/
|
||||
z-index: 9001;
|
||||
}
|
||||
|
||||
.popup-close-icon{
|
||||
|
|
|
|||
Loading…
Reference in a new issue