summaryrefslogtreecommitdiffstats
path: root/server/api/authentication.js
diff options
context:
space:
mode:
authorJannik Schönartz2019-02-26 08:18:52 +0100
committerJannik Schönartz2019-02-26 08:18:52 +0100
commitdcd82e1c5847151678ae7ffc982b4595304c1eeb (patch)
treed3a7ea5a6390e0c1c2bb49ef24f31b1ddec50606 /server/api/authentication.js
parent[webapp/configurator] disable touch swipe tabs switching (diff)
downloadbas-dcd82e1c5847151678ae7ffc982b4595304c1eeb.tar.gz
bas-dcd82e1c5847151678ae7ffc982b4595304c1eeb.tar.xz
bas-dcd82e1c5847151678ae7ffc982b4595304c1eeb.zip
[authentication] Rewrite code in async/await, fix edit account module
Diffstat (limited to 'server/api/authentication.js')
-rw-r--r--server/api/authentication.js19
1 files changed, 13 insertions, 6 deletions
diff --git a/server/api/authentication.js b/server/api/authentication.js
index 60b04f9..60b08a1 100644
--- a/server/api/authentication.js
+++ b/server/api/authentication.js
@@ -2,7 +2,8 @@
const path = require('path')
var db = require(path.join(__appdir, 'lib', 'sequelize'))
var express = require('express')
-var noAuthRouter = express.Router()
+const { decorateApp } = require('@awaitjs/express')
+var noAuthRouter = decorateApp(express.Router())
var authentication = require(path.join(__appdir, 'lib', 'authentication'))
// Setup method for checking if setup is possible.
@@ -26,11 +27,17 @@ 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(403).send({ status: 'USERTABLE_NOT_EMPTY', error_message: 'The user table is not empty, unauthorized creation is forbidden.' })
- else authentication.signup(req, res)
- })
+noAuthRouter.postAsync('/setup', async (req, res) => {
+ const users = await db.user.findAll()
+ 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 {
+ const user = await authentication.signup(req, res)
+ const roleDb = await db.role.create({ name: user.username, descr: 'Superadmin' })
+ const permission = await db.permission.findOne({ where: { name: 'superadmin' } })
+ await roleDb.addPermissions(permission.id)
+ await user.addRoles(roleDb.id)
+ res.status(200).send({ auth: true, status: 'VALID' })
+ }
})
module.exports.noAuthRouter = noAuthRouter