|
@ -29,6 +29,20 @@ export default class ChatController extends SiteController { |
|
|
const authRequired = sessionService.authCheckMiddleware({ requireLogin: true }); |
|
|
const authRequired = sessionService.authCheckMiddleware({ requireLogin: true }); |
|
|
const multer = this.createMulter(ChatController.slug); |
|
|
const multer = this.createMulter(ChatController.slug); |
|
|
|
|
|
|
|
|
|
|
|
async function requireRoomOwner (req, res, next) { |
|
|
|
|
|
if (!req.user) { |
|
|
|
|
|
return next(new SiteError(403, 'Must be logged in to proceed')); |
|
|
|
|
|
} |
|
|
|
|
|
if (!res.locals.room) { |
|
|
|
|
|
return next(new SiteError(403, 'Room not found')); |
|
|
|
|
|
} |
|
|
|
|
|
if (!res.locals.room.owner._id.equals(req.user._id)) { |
|
|
|
|
|
return next(new SiteError(403, 'This is not your room')); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return next(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
const router = express.Router(); |
|
|
const router = express.Router(); |
|
|
this.dtp.app.use('/chat', router); |
|
|
this.dtp.app.use('/chat', router); |
|
|
|
|
|
|
|
@ -48,6 +62,12 @@ export default class ChatController extends SiteController { |
|
|
this.postRoomMessage.bind(this), |
|
|
this.postRoomMessage.bind(this), |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
router.post( |
|
|
|
|
|
'/room/:roomId/settings', |
|
|
|
|
|
requireRoomOwner, |
|
|
|
|
|
this.postRoomSettings.bind(this), |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
router.post( |
|
|
router.post( |
|
|
'/room', |
|
|
'/room', |
|
|
// limiterService.create(limiterService.config.chat.postCreateRoom),
|
|
|
// limiterService.create(limiterService.config.chat.postCreateRoom),
|
|
@ -71,6 +91,13 @@ export default class ChatController extends SiteController { |
|
|
this.getRoomMessages.bind(this), |
|
|
this.getRoomMessages.bind(this), |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
router.get( |
|
|
|
|
|
'/room/:roomId/settings', |
|
|
|
|
|
// limiterService.create(limiterService.config.chat.getRoomMessages),
|
|
|
|
|
|
requireRoomOwner, |
|
|
|
|
|
this.getRoomSettingsView.bind(this), |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
router.get( |
|
|
router.get( |
|
|
'/room/:roomId', |
|
|
'/room/:roomId', |
|
|
// limiterService.create(limiterService.config.chat.getRoomView),
|
|
|
// limiterService.create(limiterService.config.chat.getRoomView),
|
|
@ -124,6 +151,17 @@ export default class ChatController extends SiteController { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async postRoomSettings (req, res, next) { |
|
|
|
|
|
const { chat: chatService } = this.dtp.services; |
|
|
|
|
|
try { |
|
|
|
|
|
await chatService.updateRoomSettings(res.locals.room, req.body); |
|
|
|
|
|
res.redirect(`/chat/room/${res.locals.room._id}`); |
|
|
|
|
|
} catch (error) { |
|
|
|
|
|
this.log.error('failed to present the room settings view', { error }); |
|
|
|
|
|
return next(error); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
async postCreateRoom (req, res, next) { |
|
|
async postCreateRoom (req, res, next) { |
|
|
const { chat: chatService } = this.dtp.services; |
|
|
const { chat: chatService } = this.dtp.services; |
|
|
try { |
|
|
try { |
|
@ -162,6 +200,10 @@ export default class ChatController extends SiteController { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async getRoomSettingsView (req, res) { |
|
|
|
|
|
res.render('chat/room/settings'); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
async getRoomView (req, res, next) { |
|
|
async getRoomView (req, res, next) { |
|
|
const { chat: chatService } = this.dtp.services; |
|
|
const { chat: chatService } = this.dtp.services; |
|
|
try { |
|
|
try { |
|
|