2018-01-10 01:41:53 +00:00
|
|
|
const Promise = require('bluebird')
|
|
|
|
const crypto = require('crypto')
|
2018-10-08 04:17:31 +00:00
|
|
|
const passportJWT = require('passport-jwt')
|
2017-04-29 15:53:44 +00:00
|
|
|
|
2017-04-28 22:22:03 +00:00
|
|
|
module.exports = {
|
|
|
|
sanitizeCommitUser (user) {
|
2018-01-10 01:41:53 +00:00
|
|
|
// let wlist = new RegExp('[^a-zA-Z0-9-_.\',& ' + appdata.regex.cjk + appdata.regex.arabic + ']', 'g')
|
|
|
|
// return {
|
|
|
|
// name: _.chain(user.name).replace(wlist, '').trim().value(),
|
|
|
|
// email: appconfig.git.showUserEmail ? user.email : appconfig.git.serverEmail
|
|
|
|
// }
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Generate a random token
|
|
|
|
*
|
|
|
|
* @param {any} length
|
|
|
|
* @returns
|
|
|
|
*/
|
|
|
|
async generateToken (length) {
|
|
|
|
return Promise.fromCallback(clb => {
|
|
|
|
crypto.randomBytes(length, clb)
|
|
|
|
}).then(buf => {
|
|
|
|
return buf.toString('hex')
|
|
|
|
})
|
2018-10-08 04:17:31 +00:00
|
|
|
},
|
|
|
|
|
2018-10-12 20:39:02 +00:00
|
|
|
extractJWT: passportJWT.ExtractJwt.fromExtractors([
|
|
|
|
passportJWT.ExtractJwt.fromAuthHeaderAsBearerToken(),
|
|
|
|
(req) => {
|
|
|
|
let token = null
|
|
|
|
if (req && req.cookies) {
|
|
|
|
token = req.cookies['jwt']
|
2018-10-08 04:17:31 +00:00
|
|
|
}
|
2022-01-23 00:52:59 +00:00
|
|
|
// Force uploads to use Auth headers
|
|
|
|
if (req.path === '/u') {
|
|
|
|
return null
|
|
|
|
}
|
2018-10-12 20:39:02 +00:00
|
|
|
return token
|
|
|
|
}
|
|
|
|
])
|
2017-04-28 22:22:03 +00:00
|
|
|
}
|