refactor: global namespace + admin pages UI
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/* global wiki */
|
||||
/* global WIKI */
|
||||
|
||||
const _ = require('lodash')
|
||||
const passport = require('passport')
|
||||
@@ -17,11 +17,11 @@ module.exports = {
|
||||
})
|
||||
|
||||
passport.deserializeUser(function (id, done) {
|
||||
wiki.db.User.findById(id).then((user) => {
|
||||
WIKI.db.User.findById(id).then((user) => {
|
||||
if (user) {
|
||||
done(null, user)
|
||||
} else {
|
||||
done(new Error(wiki.lang.t('auth:errors:usernotfound')), null)
|
||||
done(new Error(WIKI.lang.t('auth:errors:usernotfound')), null)
|
||||
}
|
||||
return true
|
||||
}).catch((err) => {
|
||||
@@ -31,49 +31,49 @@ module.exports = {
|
||||
|
||||
// Load authentication strategies
|
||||
|
||||
_.forOwn(_.omitBy(wiki.config.auth.strategies, s => s.enabled === false), (strategyConfig, strategyKey) => {
|
||||
strategyConfig.callbackURL = `${wiki.config.site.host}${wiki.config.site.path}login/${strategyKey}/callback`
|
||||
_.forOwn(_.omitBy(WIKI.config.auth.strategies, s => s.enabled === false), (strategyConfig, strategyKey) => {
|
||||
strategyConfig.callbackURL = `${WIKI.config.site.host}${WIKI.config.site.path}login/${strategyKey}/callback`
|
||||
let strategy = require(`../modules/authentication/${strategyKey}`)
|
||||
try {
|
||||
strategy.init(passport, strategyConfig)
|
||||
} catch (err) {
|
||||
wiki.logger.error(`Authentication Provider ${strategyKey}: [ FAILED ]`)
|
||||
wiki.logger.error(err)
|
||||
WIKI.logger.error(`Authentication Provider ${strategyKey}: [ FAILED ]`)
|
||||
WIKI.logger.error(err)
|
||||
}
|
||||
fs.readFile(path.join(wiki.ROOTPATH, `assets/svg/auth-icon-${strategyKey}.svg`), 'utf8').then(iconData => {
|
||||
fs.readFile(path.join(WIKI.ROOTPATH, `assets/svg/auth-icon-${strategyKey}.svg`), 'utf8').then(iconData => {
|
||||
strategy.icon = iconData
|
||||
}).catch(err => {
|
||||
if (err.code === 'ENOENT') {
|
||||
strategy.icon = '[missing icon]'
|
||||
} else {
|
||||
wiki.logger.error(err)
|
||||
WIKI.logger.error(err)
|
||||
}
|
||||
})
|
||||
this.strategies[strategy.key] = strategy
|
||||
wiki.logger.info(`Authentication Provider ${strategyKey}: [ OK ]`)
|
||||
WIKI.logger.info(`Authentication Provider ${strategyKey}: [ OK ]`)
|
||||
})
|
||||
|
||||
// Create Guest account for first-time
|
||||
|
||||
wiki.db.User.findOne({
|
||||
WIKI.db.User.findOne({
|
||||
where: {
|
||||
provider: 'local',
|
||||
email: 'guest@example.com'
|
||||
}
|
||||
}).then((c) => {
|
||||
if (c < 1) {
|
||||
return wiki.db.User.create({
|
||||
return WIKI.db.User.create({
|
||||
provider: 'local',
|
||||
email: 'guest@example.com',
|
||||
name: 'Guest',
|
||||
password: '',
|
||||
role: 'guest'
|
||||
}).then(() => {
|
||||
wiki.logger.info('[AUTH] Guest account created successfully!')
|
||||
WIKI.logger.info('[AUTH] Guest account created successfully!')
|
||||
return true
|
||||
}).catch((err) => {
|
||||
wiki.logger.error('[AUTH] An error occured while creating guest account:')
|
||||
wiki.logger.error(err)
|
||||
WIKI.logger.error('[AUTH] An error occured while creating guest account:')
|
||||
WIKI.logger.error(err)
|
||||
return err
|
||||
})
|
||||
}
|
||||
@@ -81,22 +81,22 @@ module.exports = {
|
||||
|
||||
// .then(() => {
|
||||
// if (process.env.WIKI_JS_HEROKU) {
|
||||
// return wiki.db.User.findOne({ provider: 'local', email: process.env.WIKI_ADMIN_EMAIL }).then((c) => {
|
||||
// return WIKI.db.User.findOne({ provider: 'local', email: process.env.WIKI_ADMIN_EMAIL }).then((c) => {
|
||||
// if (c < 1) {
|
||||
// // Create root admin account (HEROKU ONLY)
|
||||
|
||||
// return wiki.db.User.create({
|
||||
// return WIKI.db.User.create({
|
||||
// provider: 'local',
|
||||
// email: process.env.WIKI_ADMIN_EMAIL,
|
||||
// name: 'Administrator',
|
||||
// password: '$2a$04$MAHRw785Xe/Jd5kcKzr3D.VRZDeomFZu2lius4gGpZZ9cJw7B7Mna', // admin123 (default)
|
||||
// role: 'admin'
|
||||
// }).then(() => {
|
||||
// wiki.logger.info('[AUTH] Root admin account created successfully!')
|
||||
// WIKI.logger.info('[AUTH] Root admin account created successfully!')
|
||||
// return true
|
||||
// }).catch((err) => {
|
||||
// wiki.logger.error('[AUTH] An error occured while creating root admin account:')
|
||||
// wiki.logger.error(err)
|
||||
// WIKI.logger.error('[AUTH] An error occured while creating root admin account:')
|
||||
// WIKI.logger.error(err)
|
||||
// return err
|
||||
// })
|
||||
// } else { return true }
|
||||
|
Reference in New Issue
Block a user