Skip to content

Commit

Permalink
Merge pull request #182 from Dahlgren/bugfix/empty-server-title
Browse files Browse the repository at this point in the history
Block empty server titles
  • Loading branch information
Dahlgren authored Mar 3, 2021
2 parents b7d0aaa + da7a71e commit f69df71
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
13 changes: 12 additions & 1 deletion public/js/app/views/servers/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 12 additions & 0 deletions public/js/app/views/servers/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
10 changes: 10 additions & 0 deletions routes/servers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand All @@ -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()
Expand Down

0 comments on commit f69df71

Please sign in to comment.