feat: authentication improvements

This commit is contained in:
NGPixel
2018-08-04 17:27:55 -04:00
committed by Nicolas Giard
parent 2817c72ec3
commit bcd6ceb271
39 changed files with 1727 additions and 1828 deletions

View File

@@ -2,6 +2,13 @@ const passport = require('passport')
const fs = require('fs-extra')
const _ = require('lodash')
const path = require('path')
const NodeCache = require('node-cache')
const userCache = new NodeCache({
stdTTL: 10,
checkperiod: 600,
deleteOnExpire: true
})
/* global WIKI */
@@ -17,16 +24,22 @@ module.exports = {
})
passport.deserializeUser(function (id, done) {
WIKI.models.users.query().findById(id).then((user) => {
if (user) {
done(null, user)
} else {
done(new Error(WIKI.lang.t('auth:errors:usernotfound')), null)
}
return true
}).catch((err) => {
done(err, null)
})
const usr = userCache.get(id)
if (usr) {
done(null, usr)
} else {
WIKI.models.users.query().findById(id).then((user) => {
if (user) {
userCache.set(id, user)
done(null, user)
} else {
done(new Error(WIKI.lang.t('auth:errors:usernotfound')), null)
}
return true
}).catch((err) => {
done(err, null)
})
}
})
return this

View File

@@ -47,6 +47,7 @@ module.exports = {
* Post-Master Boot Sequence
*/
async postBootMaster() {
await WIKI.models.authentication.refreshStrategiesFromDisk()
await WIKI.auth.activateStrategies()
await WIKI.models.storage.refreshTargetsFromDisk()
await WIKI.queue.start()