* Added new token system to add more security to logins

* Added simple tag editing from note page
This commit is contained in:
Max G committed 2020-06-10 04:41:52 +00:00
1 parent 6bb856689d
commit d2624628d8
11 files changed
+324 -103

No files matched your search

+19 -15
View File
@@ -198,19 +198,21 @@ http.listen(3001, function(){
//Enable json body parsing in requests. Allows me to post data in ajax calls
app.use(express.json({limit: '5mb'}))
//Prefix defied by route in nginx config
const prefix = '/api'
//App Auth, all requests will come in with a token, decode the token and set global var
app.use(function(req, res, next){
//Always null out master key, never allow it set from outside
req.headers.masterKey = null
req.headers.tokenId = null
//auth token set by axios in headers
let token = req.headers.authorizationtoken
if(token && token != null && typeof token === 'string'){
Auth.decodeToken(token)
Auth.decodeToken(token, req)
.then(userData => {
req.headers.userId = userData.id //Update headers for the rest of the application
req.headers.userId = userData.userId //Update headers for the rest of the application
req.headers.masterKey = userData.masterKey
req.headers.tokenId = userData.tokenId
next()
}).catch(error => {
@@ -224,9 +226,11 @@ app.use(function(req, res, next){
// Test Area
const printResults = false
const printResults = true
let UserTest = require('@models/User')
let NoteTest = require('@models/Note')
let AuthTest = require('@helpers/Auth')
Auth.test()
UserTest.keyPairTest('genMan12', '1', printResults)
.then( ({testUserId, masterKey}) => NoteTest.test(testUserId, masterKey, printResults))
.then( message => {
@@ -236,34 +240,34 @@ UserTest.keyPairTest('genMan12', '1', printResults)
//Test
app.get(prefix, (req, res) => res.send('The api is running'))
app.get('/api', (req, res) => res.send('Solidscribe API is up and running'))
//Serve up uploaded files
app.use(prefix+'/static', express.static( __dirname+'/../staticFiles' ))
app.use('/api/static', express.static( __dirname+'/../staticFiles' ))
//Public routes
var public = require('@routes/publicController')
app.use(prefix+'/public', public)
app.use('/api/public', public)
//user endpoint
var user = require('@routes/userController')
app.use(prefix+'/user', user)
app.use('/api/user', user)
//notes endpoint
var notes = require('@routes/noteController')
app.use(prefix+'/note', notes)
app.use('/api/note', notes)
//tags endpoint
var tags = require('@routes/tagController')
app.use(prefix+'/tag', tags)
app.use('/api/tag', tags)
//notes endpoint
var attachment = require('@routes/attachmentController')
app.use(prefix+'/attachment', attachment)
app.use('/api/attachment', attachment)
//quick notes endpoint
var quickNote = require('@routes/quicknoteController')
app.use(prefix+'/quick-note', quickNote)
app.use('/api/quick-note', quickNote)
//Output running status
app.listen(port, () => {