ability to ban and unban users
This commit is contained in:
@@ -142,6 +142,23 @@ const User = sequelize.define(
|
||||
defaultValue: "user",
|
||||
allowNull: false,
|
||||
},
|
||||
isBanned: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
defaultValue: false,
|
||||
allowNull: false,
|
||||
},
|
||||
bannedAt: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: true,
|
||||
},
|
||||
bannedBy: {
|
||||
type: DataTypes.UUID,
|
||||
allowNull: true,
|
||||
},
|
||||
banReason: {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: true,
|
||||
},
|
||||
itemRequestNotificationRadius: {
|
||||
type: DataTypes.INTEGER,
|
||||
defaultValue: 10,
|
||||
@@ -343,4 +360,27 @@ User.prototype.resetPassword = async function (newPassword) {
|
||||
});
|
||||
};
|
||||
|
||||
// Ban user method - sets ban fields and invalidates all sessions
|
||||
User.prototype.banUser = async function (adminId, reason) {
|
||||
return this.update({
|
||||
isBanned: true,
|
||||
bannedAt: new Date(),
|
||||
bannedBy: adminId,
|
||||
banReason: reason,
|
||||
// Increment JWT version to immediately invalidate all sessions
|
||||
jwtVersion: this.jwtVersion + 1,
|
||||
});
|
||||
};
|
||||
|
||||
// Unban user method - clears ban fields
|
||||
User.prototype.unbanUser = async function () {
|
||||
return this.update({
|
||||
isBanned: false,
|
||||
bannedAt: null,
|
||||
bannedBy: null,
|
||||
banReason: null,
|
||||
// Note: We don't increment jwtVersion on unban - user will need to log in fresh
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = User;
|
||||
|
||||
Reference in New Issue
Block a user