mirror of
https://github.com/status-im/codimd.git
synced 2025-01-29 19:54:58 +00:00
92c0575977
Signed-off-by: Raccoon <raccoon@hackmd.io>
40 lines
1016 B
TypeScript
40 lines
1016 B
TypeScript
import * as fs from 'fs'
|
|
import * as path from 'path'
|
|
import * as config from '../config'
|
|
// @ts-ignore
|
|
import {User} from '../models'
|
|
import * as logger from '../logger'
|
|
import {Request, Response} from "express";
|
|
|
|
|
|
export async function showIndex(req: Request, res: Response) {
|
|
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 as any).id
|
|
}
|
|
})
|
|
if (user) {
|
|
data.deleteToken = user.deleteToken
|
|
return res.render('index.ejs', data)
|
|
}
|
|
|
|
logger.error(`error: user not found with id ${(req.user as any).id}`)
|
|
return res.render('index.ejs', data)
|
|
}
|