feat: modular auth + logging changes

This commit is contained in:
NGPixel
2017-07-30 00:04:57 -04:00
parent f32429325c
commit 2020e457cf
15 changed files with 174 additions and 185 deletions

View File

@@ -2,9 +2,9 @@
/* global wiki */
const fs = require('fs')
const _ = require('lodash')
module.exports = function (passport) {
module.exports = (passport) => {
// Serialization user methods
passport.serializeUser(function (user, done) {
@@ -24,12 +24,28 @@ module.exports = function (passport) {
})
})
// Create users for first-time
// Load authentication strategies
return wiki.db.User.findOne({ provider: 'local', email: 'guest@example.com' }).then((c) => {
wiki.config.authStrategies = {
list: _.pickBy(wiki.config.auth, strategy => strategy.enabled),
socialEnabled: (_.chain(wiki.config.auth).omit('local').filter(['enabled', true]).value().length > 0)
}
_.forOwn(wiki.config.authStrategies.list, (strategyConfig, strategyName) => {
strategyConfig.callbackURL = `${wiki.config.site.host}/login/${strategyName}/callback`
require(`../authentication/${strategyName}`)(passport, strategyConfig)
wiki.logger.info(`Authentication Provider ${_.upperFirst(strategyName)}: OK`)
})
// Create Guest account for first-time
return wiki.db.User.findOne({
where: {
provider: 'local',
email: 'guest@example.com'
}
}).then((c) => {
if (c < 1) {
// Create guest account
return wiki.db.User.create({
provider: 'local',
email: 'guest@example.com',

View File

@@ -57,17 +57,6 @@ module.exports = {
// List authentication strategies
wiki.config = appconfig
wiki.data = appdata
// List authentication strategies
// appconfig.authStrategies = {
// list: _.filter(appconfig.auth, ['enabled', true]),
// socialEnabled: (_.chain(appconfig.auth).omit('local').filter(['enabled', true]).value().length > 0)
// }
// if (appconfig.authStrategies.list.length < 1) {
// console.error(new Error('You must enable at least 1 authentication strategy!'))
// process.exit(1)
// }
},
/**

View File

@@ -41,7 +41,7 @@ module.exports = {
// Attempt to connect and authenticate to DB
self.inst.authenticate().then(() => {
wiki.logger.info('Connected to PostgreSQL database.')
wiki.logger.info('Database (PostgreSQL) connection: OK')
}).catch(err => {
wiki.logger.error('Failed to connect to MongoDB instance.')
return err

View File

@@ -94,8 +94,6 @@ module.exports = {
* Creates a base directories (Synchronous).
*/
createBaseDirectories () {
wiki.logger.info('Checking data directories...')
try {
fs.ensureDirSync(path.resolve(wiki.ROOTPATH, wiki.config.paths.data))
fs.emptyDirSync(path.resolve(wiki.ROOTPATH, wiki.config.paths.data))
@@ -117,7 +115,7 @@ module.exports = {
wiki.logger.error(err)
}
wiki.logger.info('Data and Repository directories are OK.')
wiki.logger.info('Disk Data Paths: OK')
},
/**

View File

@@ -71,8 +71,6 @@ module.exports = {
_initRepo() {
let self = this
wiki.logger.info('Checking Git repository...')
// -> Check if path is accessible
return fs.mkdirAsync(self._repo.path).catch((err) => {
@@ -92,7 +90,7 @@ module.exports = {
})
}).then(() => {
if (wiki.config.git === false) {
wiki.logger.info('Remote Git syncing is disabled. Not recommended!')
wiki.logger.warn('Remote Git syncing is disabled. Not recommended!')
return Promise.resolve(true)
}
@@ -132,7 +130,7 @@ module.exports = {
wiki.logger.error('Git remote error!')
throw err
}).then(() => {
wiki.logger.info('Git repository is OK.')
wiki.logger.info('Git Repository: OK')
return true
})
},