mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-12-27 08:31:40 +00:00
eddf8a3a33
Since we added user management it's possible to get non-existent users which can cause a crash of the Backend server. Signed-off-by: Sheogorath <sheogorath@shivering-isles.com>
55 lines
1.6 KiB
JavaScript
55 lines
1.6 KiB
JavaScript
'use strict'
|
|
|
|
const Router = require('express').Router
|
|
const passport = require('passport')
|
|
|
|
const config = require('../../config')
|
|
const logger = require('../../logger')
|
|
const models = require('../../models')
|
|
|
|
const authRouter = module.exports = Router()
|
|
|
|
// serialize and deserialize
|
|
passport.serializeUser(function (user, done) {
|
|
logger.info('serializeUser: ' + user.id)
|
|
return done(null, user.id)
|
|
})
|
|
|
|
passport.deserializeUser(function (id, done) {
|
|
models.User.findOne({
|
|
where: {
|
|
id: id
|
|
}
|
|
}).then(function (user) {
|
|
// Don't die on non-existent user
|
|
if (user == null) {
|
|
return done(null, false, { message: 'Invalid UserID' })
|
|
}
|
|
|
|
logger.info('deserializeUser: ' + user.id)
|
|
return done(null, user)
|
|
}).catch(function (err) {
|
|
logger.error(err)
|
|
return done(err, null)
|
|
})
|
|
})
|
|
|
|
if (config.isFacebookEnable) authRouter.use(require('./facebook'))
|
|
if (config.isTwitterEnable) authRouter.use(require('./twitter'))
|
|
if (config.isGitHubEnable) authRouter.use(require('./github'))
|
|
if (config.isGitLabEnable) authRouter.use(require('./gitlab'))
|
|
if (config.isMattermostEnable) authRouter.use(require('./mattermost'))
|
|
if (config.isDropboxEnable) authRouter.use(require('./dropbox'))
|
|
if (config.isGoogleEnable) authRouter.use(require('./google'))
|
|
if (config.isLDAPEnable) authRouter.use(require('./ldap'))
|
|
if (config.isSAMLEnable) authRouter.use(require('./saml'))
|
|
if (config.isEmailEnable) authRouter.use(require('./email'))
|
|
|
|
// logout
|
|
authRouter.get('/logout', function (req, res) {
|
|
if (config.debug && req.isAuthenticated()) {
|
|
logger.debug('user logout: ' + req.user.id)
|
|
}
|
|
req.logout()
|
|
res.redirect(config.serverurl + '/')
|
|
})
|