summaryrefslogtreecommitdiffstats
path: root/server/api/authentication.js
diff options
context:
space:
mode:
authorJannik Schönartz2019-02-22 02:59:26 +0100
committerJannik Schönartz2019-02-22 02:59:26 +0100
commit892a048d072d05886951bcb92e6b61c2094a6463 (patch)
tree2ff89b4d69c829304f55d529203eed985aaac413 /server/api/authentication.js
parentrework user api to rest (diff)
downloadbas-892a048d072d05886951bcb92e6b61c2094a6463.tar.gz
bas-892a048d072d05886951bcb92e6b61c2094a6463.tar.xz
bas-892a048d072d05886951bcb92e6b61c2094a6463.zip
[authentication] Implement initial root account setup
[backend] Reworked authentication library to the api structure Add authentication api to remove the login routes from the router.js [webapp] Split login Page in StartPage + Login/Setup Add Setup Page for the initial root creation
Diffstat (limited to 'server/api/authentication.js')
-rw-r--r--server/api/authentication.js42
1 files changed, 42 insertions, 0 deletions
diff --git a/server/api/authentication.js b/server/api/authentication.js
new file mode 100644
index 0000000..02b295b
--- /dev/null
+++ b/server/api/authentication.js
@@ -0,0 +1,42 @@
+/* global __appdir */
+const path = require('path')
+var db = require(path.join(__appdir, 'lib', 'sequelize'))
+var express = require('express')
+var noAuthRouter = express.Router()
+var authentication = require(path.join(__appdir, 'lib', 'authentication'))
+
+noAuthRouter.post('/token', (req, res) => {
+ authentication.loginToken(req, res)
+})
+
+noAuthRouter.post('/login', (req, res) => {
+ authentication.loginCookie(req, res)
+})
+
+noAuthRouter.post('/logout', (req, res) => {
+ authentication.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.send({ status: 'USERTABLE_NOT_EMPTY', error_message: 'The user table is not empty, unauthorized creation is forbidden.' })
+ else if (req.body.username) authentication.signup(req, res)
+ else res.send({ status: 'SUCCESS' })
+ })
+})
+
+module.exports.noAuthRouter = noAuthRouter
+
+/* USERS API
+var authentication = require(path.join(__appdir, 'lib', 'authentication'))
+router.post('/', (req, res) => {
+ authentication.signup(req, res)
+})
+
+router.post('/:id/password', (req, res) => {
+ authentication.changepassword(req, res)
+})
+
+module.exports.router = router
+*/