summaryrefslogtreecommitdiffstats
path: root/server/api/authentication.js
blob: 02b295b1e2e377d4ba609448756093fa31144c8d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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
*/