summaryrefslogtreecommitdiffstats
path: root/server/api/authentication.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/api/authentication.js')
-rw-r--r--server/api/authentication.js13
1 files changed, 10 insertions, 3 deletions
diff --git a/server/api/authentication.js b/server/api/authentication.js
index 18158ce..60b04f9 100644
--- a/server/api/authentication.js
+++ b/server/api/authentication.js
@@ -5,6 +5,14 @@ var express = require('express')
var noAuthRouter = express.Router()
var authentication = require(path.join(__appdir, 'lib', 'authentication'))
+// Setup method for checking if setup is possible.
+noAuthRouter.get('/setup', (req, res) => {
+ db.user.findAll().then(users => {
+ if (users.length > 0) res.status(403).send({ status: 'USERTABLE_NOT_EMPTY', error_message: 'The user table is not empty, unauthorized creation is forbidden.' })
+ else res.send({ status: 'SUCCESS' })
+ })
+})
+
noAuthRouter.post('/token', (req, res) => {
authentication.loginToken(req, res)
})
@@ -20,9 +28,8 @@ noAuthRouter.post('/logout', (req, res) => {
// Setup method for creating the initial root account.
noAuthRouter.post('/setup', (req, res) => {
db.user.findAll().then(users => {
- if (users.length > 0) res.status(500).send({ status: 'USERTABLE_NOT_EMPTY', error_message: 'The user table is not empty, unauthorized creation is forbidden.' })
- else if (req.body.username) return authentication.signup(req, res)
- else res.send({ status: 'SUCCESS' })
+ if (users.length > 0) res.status(403).send({ status: 'USERTABLE_NOT_EMPTY', error_message: 'The user table is not empty, unauthorized creation is forbidden.' })
+ else authentication.signup(req, res)
})
})