2020-01-04 21:59:57 +00:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
const fs = require('fs')
|
|
|
|
const path = require('path')
|
2020-01-04 22:30:23 +00:00
|
|
|
const config = require('../config')
|
|
|
|
const { User } = require('../models')
|
|
|
|
const logger = require('../logger')
|
2020-01-04 21:59:57 +00:00
|
|
|
|
|
|
|
exports.showIndex = async (req, res) => {
|
|
|
|
const isLogin = req.isAuthenticated()
|
|
|
|
const deleteToken = ''
|
|
|
|
|
|
|
|
const data = {
|
|
|
|
signin: isLogin,
|
|
|
|
infoMessage: req.flash('info'),
|
|
|
|
errorMessage: req.flash('error'),
|
|
|
|
privacyStatement: fs.existsSync(path.join(config.docsPath, 'privacy.md')),
|
|
|
|
termsOfUse: fs.existsSync(path.join(config.docsPath, 'terms-of-use.md')),
|
|
|
|
deleteToken: deleteToken
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isLogin) {
|
|
|
|
return res.render('index.ejs', data)
|
|
|
|
}
|
|
|
|
|
|
|
|
const user = await User.findOne({
|
|
|
|
where: {
|
|
|
|
id: req.user.id
|
|
|
|
}
|
|
|
|
})
|
|
|
|
if (user) {
|
|
|
|
data.deleteToken = user.deleteToken
|
|
|
|
return res.render('index.ejs', data)
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.error(`error: user not found with id ${req.user.id}`)
|
|
|
|
return res.render('index.ejs', data)
|
|
|
|
}
|