d2624628d8
* Added simple tag editing from note page
66 lines
1.3 KiB
JavaScript
66 lines
1.3 KiB
JavaScript
var express = require('express')
|
|
var router = express.Router()
|
|
|
|
let User = require('@models/User');
|
|
const cs = require('@helpers/CryptoString')
|
|
|
|
// middleware that is specific to this router
|
|
router.use(function timeLog (req, res, next) {
|
|
// console.log('Time: ', Date.now())
|
|
next()
|
|
})
|
|
// define the home page route
|
|
router.get('/', function (req, res) {
|
|
res.send('User Home Page ' + User.getUsername())
|
|
})
|
|
// define the about route
|
|
router.get('/about', function (req, res) {
|
|
User.getUsername(req.headers.userId)
|
|
.then( data => res.send(data) )
|
|
})
|
|
// Login User
|
|
router.post('/login', function (req, res) {
|
|
|
|
User.login(req.body.username, req.body.password)
|
|
.then( returnData => {
|
|
|
|
res.send(returnData)
|
|
})
|
|
.catch(e => {
|
|
res.send(false)
|
|
})
|
|
})
|
|
// Logout User
|
|
router.post('/logout', function (req, res) {
|
|
|
|
User.logout(req.headers.tokenId)
|
|
.then( returnData => {
|
|
res.send(true)
|
|
})
|
|
})
|
|
|
|
|
|
|
|
|
|
// Login User
|
|
router.post('/register', function (req, res) {
|
|
|
|
User.register(req.body.username, req.body.password)
|
|
.then( returnData => {
|
|
|
|
res.send(returnData)
|
|
})
|
|
.catch(e => {
|
|
res.send(false)
|
|
})
|
|
})
|
|
|
|
|
|
// fetch counts of users notes
|
|
router.post('/totals', function (req, res) {
|
|
User.getCounts(req.headers.userId)
|
|
.then( countsObject => res.send( countsObject ))
|
|
})
|
|
|
|
|
|
module.exports = router |