From da7a71ed7fca1def62b749e8a27c40f6c0390966 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bjo=CC=88rn=20Dahlgren?= Date: Sun, 28 Feb 2021 15:26:26 +0100 Subject: [PATCH] Block empty server titles --- public/js/app/views/servers/form.js | 13 ++++++++++++- public/js/app/views/servers/view.js | 12 ++++++++++++ routes/servers.js | 10 ++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/public/js/app/views/servers/form.js b/public/js/app/views/servers/form.js index b49de4c..e0ffb63 100644 --- a/public/js/app/views/servers/form.js +++ b/public/js/app/views/servers/form.js @@ -37,7 +37,18 @@ module.exports = Marionette.ItemView.extend({ submit: function (modal) { modal.preventClose() - this.model.set(this.serialize()) + var data = this.serialize() + + if (!data.title) { + sweetAlert({ + title: 'Error', + text: 'Server title cannot be empty', + type: 'error' + }) + return + } + + this.model.set(data) var self = this diff --git a/public/js/app/views/servers/view.js b/public/js/app/views/servers/view.js index 51dd3a7..d93123a 100644 --- a/public/js/app/views/servers/view.js +++ b/public/js/app/views/servers/view.js @@ -57,12 +57,24 @@ module.exports = Marionette.LayoutView.extend({ save: function (e) { e.preventDefault() + var self = this var oldId = this.model.get('id') var data = this.settingsView.currentView.serialize() + + if (!data.title) { + sweetAlert({ + title: 'Error', + text: 'Server title cannot be empty', + type: 'error' + }) + return + } + _.extend(data, this.missionsView.currentView.serialize()) _.extend(data, this.modsView.currentView.serialize()) _.extend(data, this.parametersView.currentView.serialize()) + this.model.save(data, { success: function () { var newId = self.model.get('id') diff --git a/routes/servers.js b/routes/servers.js index c63aa6f..8a64cb8 100644 --- a/routes/servers.js +++ b/routes/servers.js @@ -8,6 +8,11 @@ module.exports = function (manager, mods) { }) router.post('/', function (req, res) { + if (!req.body.title) { + res.status(400).send('Server title cannot be empty') + return + } + var server = manager.addServer(req.body) res.json(server) }) @@ -18,6 +23,11 @@ module.exports = function (manager, mods) { }) router.put('/:server', function (req, res) { + if (!req.body.title) { + res.status(400).send('Server title cannot be empty') + return + } + var server = manager.getServer(req.params.server) server.update(req.body) manager.save()