mirror of https://github.com/requarks/wiki
parent
9c112ab535
commit
f32429325c
@ -0,0 +1,33 @@
|
||||
'use strict'
|
||||
|
||||
/* global wiki */
|
||||
|
||||
// ------------------------------------
|
||||
// Azure AD Account
|
||||
// ------------------------------------
|
||||
|
||||
const AzureAdOAuth2Strategy = require('passport-azure-ad-oauth2').Strategy
|
||||
|
||||
module.exports = (passport) => {
|
||||
if (wiki.config.auth.azure && wiki.config.auth.azure.enabled) {
|
||||
const jwt = require('jsonwebtoken')
|
||||
passport.use('azure_ad_oauth2',
|
||||
new AzureAdOAuth2Strategy({
|
||||
clientID: wiki.config.auth.azure.clientId,
|
||||
clientSecret: wiki.config.auth.azure.clientSecret,
|
||||
callbackURL: wiki.config.host + '/login/azure/callback',
|
||||
resource: wiki.config.auth.azure.resource,
|
||||
tenant: wiki.config.auth.azure.tenant
|
||||
}, (accessToken, refreshToken, params, profile, cb) => {
|
||||
let waadProfile = jwt.decode(params.id_token)
|
||||
waadProfile.id = waadProfile.oid
|
||||
waadProfile.provider = 'azure'
|
||||
wiki.db.User.processProfile(waadProfile).then((user) => {
|
||||
return cb(null, user) || true
|
||||
}).catch((err) => {
|
||||
return cb(err, null) || true
|
||||
})
|
||||
}
|
||||
))
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
'use strict'
|
||||
|
||||
/* global wiki */
|
||||
|
||||
// ------------------------------------
|
||||
// Facebook Account
|
||||
// ------------------------------------
|
||||
|
||||
const FacebookStrategy = require('passport-facebook').Strategy
|
||||
|
||||
module.exports = (passport) => {
|
||||
if (wiki.config.auth.facebook && wiki.config.auth.facebook.enabled) {
|
||||
passport.use('facebook',
|
||||
new FacebookStrategy({
|
||||
clientID: wiki.config.auth.facebook.clientId,
|
||||
clientSecret: wiki.config.auth.facebook.clientSecret,
|
||||
callbackURL: wiki.config.host + '/login/facebook/callback',
|
||||
profileFields: ['id', 'displayName', 'email']
|
||||
}, function (accessToken, refreshToken, profile, cb) {
|
||||
wiki.db.User.processProfile(profile).then((user) => {
|
||||
return cb(null, user) || true
|
||||
}).catch((err) => {
|
||||
return cb(err, null) || true
|
||||
})
|
||||
}
|
||||
))
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
'use strict'
|
||||
|
||||
/* global wiki */
|
||||
|
||||
// ------------------------------------
|
||||
// GitHub Account
|
||||
// ------------------------------------
|
||||
|
||||
const GitHubStrategy = require('passport-github2').Strategy
|
||||
|
||||
module.exports = (passport) => {
|
||||
if (wiki.config.auth.github && wiki.config.auth.github.enabled) {
|
||||
passport.use('github',
|
||||
new GitHubStrategy({
|
||||
clientID: wiki.config.auth.github.clientId,
|
||||
clientSecret: wiki.config.auth.github.clientSecret,
|
||||
callbackURL: wiki.config.host + '/login/github/callback',
|
||||
scope: ['user:email']
|
||||
}, (accessToken, refreshToken, profile, cb) => {
|
||||
wiki.db.User.processProfile(profile).then((user) => {
|
||||
return cb(null, user) || true
|
||||
}).catch((err) => {
|
||||
return cb(err, null) || true
|
||||
})
|
||||
}
|
||||
))
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
'use strict'
|
||||
|
||||
/* global wiki */
|
||||
|
||||
// ------------------------------------
|
||||
// Google ID Account
|
||||
// ------------------------------------
|
||||
|
||||
const GoogleStrategy = require('passport-google-oauth20').Strategy
|
||||
|
||||
module.exports = (passport) => {
|
||||
if (wiki.config.auth.google && wiki.config.auth.google.enabled) {
|
||||
passport.use('google',
|
||||
new GoogleStrategy({
|
||||
clientID: wiki.config.auth.google.clientId,
|
||||
clientSecret: wiki.config.auth.google.clientSecret,
|
||||
callbackURL: wiki.config.host + '/login/google/callback'
|
||||
}, (accessToken, refreshToken, profile, cb) => {
|
||||
wiki.db.User.processProfile(profile).then((user) => {
|
||||
return cb(null, user) || true
|
||||
}).catch((err) => {
|
||||
return cb(err, null) || true
|
||||
})
|
||||
}
|
||||
))
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
'use strict'
|
||||
|
||||
/* global wiki */
|
||||
|
||||
// ------------------------------------
|
||||
// LDAP Account
|
||||
// ------------------------------------
|
||||
|
||||
const LdapStrategy = require('passport-ldapauth').Strategy
|
||||
|
||||
module.exports = (passport) => {
|
||||
if (wiki.config.auth.ldap && wiki.config.auth.ldap.enabled) {
|
||||
passport.use('ldapauth',
|
||||
new LdapStrategy({
|
||||
server: {
|
||||
url: wiki.config.auth.ldap.url,
|
||||
bindDn: wiki.config.auth.ldap.bindDn,
|
||||
bindCredentials: wiki.config.auth.ldap.bindCredentials,
|
||||
searchBase: wiki.config.auth.ldap.searchBase,
|
||||
searchFilter: wiki.config.auth.ldap.searchFilter,
|
||||
searchAttributes: ['displayName', 'name', 'cn', 'mail'],
|
||||
tlsOptions: (wiki.config.auth.ldap.tlsEnabled) ? {
|
||||
ca: [
|
||||
fs.readFileSync(wiki.config.auth.ldap.tlsCertPath)
|
||||
]
|
||||
} : {}
|
||||
},
|
||||
usernameField: 'email',
|
||||
passReqToCallback: false
|
||||
}, (profile, cb) => {
|
||||
profile.provider = 'ldap'
|
||||
profile.id = profile.dn
|
||||
wiki.db.User.processProfile(profile).then((user) => {
|
||||
return cb(null, user) || true
|
||||
}).catch((err) => {
|
||||
return cb(err, null) || true
|
||||
})
|
||||
}
|
||||
))
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
'use strict'
|
||||
|
||||
/* global wiki */
|
||||
|
||||
// ------------------------------------
|
||||
// Local Account
|
||||
// ------------------------------------
|
||||
|
||||
const LocalStrategy = require('passport-local').Strategy
|
||||
|
||||
module.exports = (passport) => {
|
||||
if (wiki.config.auth.local && wiki.config.auth.local.enabled) {
|
||||
passport.use('local',
|
||||
new LocalStrategy({
|
||||
usernameField: 'email',
|
||||
passwordField: 'password'
|
||||
}, (uEmail, uPassword, done) => {
|
||||
wiki.db.User.findOne({ email: uEmail, provider: 'local' }).then((user) => {
|
||||
if (user) {
|
||||
return user.validatePassword(uPassword).then(() => {
|
||||
return done(null, user) || true
|
||||
}).catch((err) => {
|
||||
return done(err, null)
|
||||
})
|
||||
} else {
|
||||
return done(new Error('INVALID_LOGIN'), null)
|
||||
}
|
||||
}).catch((err) => {
|
||||
done(err, null)
|
||||
})
|
||||
}
|
||||
))
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
'use strict'
|
||||
|
||||
/* global wiki */
|
||||
|
||||
// ------------------------------------
|
||||
// Microsoft Account
|
||||
// ------------------------------------
|
||||
|
||||
const WindowsLiveStrategy = require('passport-windowslive').Strategy
|
||||
|
||||
module.exports = (passport) => {
|
||||
if (wiki.config.auth.microsoft && wiki.config.auth.microsoft.enabled) {
|
||||
passport.use('windowslive',
|
||||
new WindowsLiveStrategy({
|
||||
clientID: wiki.config.auth.microsoft.clientId,
|
||||
clientSecret: wiki.config.auth.microsoft.clientSecret,
|
||||
callbackURL: wiki.config.host + '/login/ms/callback'
|
||||
}, function (accessToken, refreshToken, profile, cb) {
|
||||
wiki.db.User.processProfile(profile).then((user) => {
|
||||
return cb(null, user) || true
|
||||
}).catch((err) => {
|
||||
return cb(err, null) || true
|
||||
})
|
||||
}
|
||||
))
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
'use strict'
|
||||
|
||||
/* global wiki */
|
||||
|
||||
// ------------------------------------
|
||||
// Slack Account
|
||||
// ------------------------------------
|
||||
|
||||
const SlackStrategy = require('passport-slack').Strategy
|
||||
|
||||
module.exports = (passport) => {
|
||||
if (wiki.config.auth.slack && wiki.config.auth.slack.enabled) {
|
||||
passport.use('slack',
|
||||
new SlackStrategy({
|
||||
clientID: wiki.config.auth.slack.clientId,
|
||||
clientSecret: wiki.config.auth.slack.clientSecret,
|
||||
callbackURL: wiki.config.host + '/login/slack/callback'
|
||||
}, (accessToken, refreshToken, profile, cb) => {
|
||||
wiki.db.User.processProfile(profile).then((user) => {
|
||||
return cb(null, user) || true
|
||||
}).catch((err) => {
|
||||
return cb(err, null) || true
|
||||
})
|
||||
}
|
||||
))
|
||||
}
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
'use strict'
|
||||
|
||||
/* global wiki */
|
||||
|
||||
const Promise = require('bluebird')
|
||||
const fs = Promise.promisifyAll(require('fs-extra'))
|
||||
const klaw = require('klaw')
|
||||
const moment = require('moment')
|
||||
const path = require('path')
|
||||
const entryHelper = require('../helpers/entry')
|
||||
|
||||
module.exports = (job, done) => {
|
||||
return wiki.git.resync().then(() => {
|
||||
// -> Stream all documents
|
||||
|
||||
let cacheJobs = []
|
||||
let jobCbStreamDocsResolve = null
|
||||
let jobCbStreamDocs = new Promise((resolve, reject) => {
|
||||
jobCbStreamDocsResolve = resolve
|
||||
})
|
||||
|
||||
klaw(wiki.REPOPATH).on('data', function (item) {
|
||||
if (path.extname(item.path) === '.md' && path.basename(item.path) !== 'README.md') {
|
||||
let entryPath = entryHelper.parsePath(entryHelper.getEntryPathFromFullPath(item.path))
|
||||
let cachePath = entryHelper.getCachePath(entryPath)
|
||||
|
||||
// -> Purge outdated cache
|
||||
|
||||
cacheJobs.push(
|
||||
fs.statAsync(cachePath).then((st) => {
|
||||
return moment(st.mtime).isBefore(item.stats.mtime) ? 'expired' : 'active'
|
||||
}).catch((err) => {
|
||||
return (err.code !== 'EEXIST') ? err : 'new'
|
||||
}).then((fileStatus) => {
|
||||
// -> Delete expired cache file
|
||||
|
||||
if (fileStatus === 'expired') {
|
||||
return fs.unlinkAsync(cachePath).return(fileStatus)
|
||||
}
|
||||
|
||||
return fileStatus
|
||||
}).then((fileStatus) => {
|
||||
// -> Update cache and search index
|
||||
|
||||
if (fileStatus !== 'active') {
|
||||
return global.entries.updateCache(entryPath).then(entry => {
|
||||
process.send({
|
||||
action: 'searchAdd',
|
||||
content: entry
|
||||
})
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
return true
|
||||
})
|
||||
)
|
||||
}
|
||||
}).on('end', () => {
|
||||
jobCbStreamDocsResolve(Promise.all(cacheJobs))
|
||||
})
|
||||
|
||||
return jobCbStreamDocs
|
||||
})
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
'use strict'
|
||||
|
||||
/* global wiki */
|
||||
|
||||
const Promise = require('bluebird')
|
||||
const fs = Promise.promisifyAll(require('fs-extra'))
|
||||
const moment = require('moment')
|
||||
const path = require('path')
|
||||
|
||||
module.exports = (job, done) => {
|
||||
return fs.readdirAsync(wiki.UPLTEMPPATH).then((ls) => {
|
||||
let fifteenAgo = moment().subtract(15, 'minutes')
|
||||
|
||||
return Promise.map(ls, (f) => {
|
||||
return fs.statAsync(path.join(wiki.UPLTEMPPATH, f)).then((s) => { return { filename: f, stat: s } })
|
||||
}).filter((s) => { return s.stat.isFile() }).then((arrFiles) => {
|
||||
return Promise.map(arrFiles, (f) => {
|
||||
if (moment(f.stat.ctime).isBefore(fifteenAgo, 'minute')) {
|
||||
return fs.unlinkAsync(path.join(wiki.UPLTEMPPATH, f.filename))
|
||||
} else {
|
||||
return true
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
Loading…
Reference in new issue