mirror of https://github.com/status-im/codimd.git
refactor(app.js): Extract /me page
This commit is contained in:
parent
e3fde01e3a
commit
e2ac73f5a3
29
app.js
29
app.js
|
@ -199,34 +199,7 @@ app.use(require('./lib/web/baseRouter'))
|
|||
app.use(require('./lib/web/statusRouter'))
|
||||
app.use(require('./lib/web/auth'))
|
||||
app.use(require('./lib/web/historyRouter'))
|
||||
|
||||
// get me info
|
||||
app.get('/me', function (req, res) {
|
||||
if (req.isAuthenticated()) {
|
||||
models.User.findOne({
|
||||
where: {
|
||||
id: req.user.id
|
||||
}
|
||||
}).then(function (user) {
|
||||
if (!user) { return response.errorNotFound(res) }
|
||||
var profile = models.User.getProfile(user)
|
||||
res.send({
|
||||
status: 'ok',
|
||||
id: req.user.id,
|
||||
name: profile.name,
|
||||
photo: profile.photo
|
||||
})
|
||||
}).catch(function (err) {
|
||||
logger.error('read me failed: ' + err)
|
||||
return response.errorInternalError(res)
|
||||
})
|
||||
} else {
|
||||
res.send({
|
||||
status: 'forbidden'
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
app.use(require('./lib/web/userRouter'))
|
||||
// upload image
|
||||
app.post('/uploadimage', function (req, res) {
|
||||
var form = new formidable.IncomingForm()
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
'use strict'
|
||||
|
||||
const Router = require('express').Router
|
||||
|
||||
const response = require('../response')
|
||||
const models = require('../models')
|
||||
const logger = require('../logger')
|
||||
|
||||
const UserRouter = module.exports = Router()
|
||||
|
||||
// get me info
|
||||
UserRouter.get('/me', function (req, res) {
|
||||
if (req.isAuthenticated()) {
|
||||
models.User.findOne({
|
||||
where: {
|
||||
id: req.user.id
|
||||
}
|
||||
}).then(function (user) {
|
||||
if (!user) { return response.errorNotFound(res) }
|
||||
var profile = models.User.getProfile(user)
|
||||
res.send({
|
||||
status: 'ok',
|
||||
id: req.user.id,
|
||||
name: profile.name,
|
||||
photo: profile.photo
|
||||
})
|
||||
}).catch(function (err) {
|
||||
logger.error('read me failed: ' + err)
|
||||
return response.errorInternalError(res)
|
||||
})
|
||||
} else {
|
||||
res.send({
|
||||
status: 'forbidden'
|
||||
})
|
||||
}
|
||||
})
|
Loading…
Reference in New Issue