Authored by htoooth

refactor

... ... @@ -16,7 +16,7 @@ module.exports = (req, res, next) => {
let loginPage = helpers.urlFormat('/passport/login', {refer: req.fullUrl()});
if (_.isEmpty(req.user) || !req.user.uid || !req.user.uid.session) {
if (_.isEmpty(req.user) || !req.user.uid.isValid()) {
if (req.xhr) {
return res.json({
code: 400,
... ...
... ... @@ -4,6 +4,7 @@
*/
const headerModel = require('../models/header');
const logger = global.yoho.logger;
const helpers = global.yoho.helpers;
const forceNoCache = (res) => {
if (res) {
... ... @@ -48,6 +49,15 @@ exports.serverError = () => {
logger.error(`error at path: ${req.url}`);
logger.error(err);
if (err && err.code === 401) {
if (req.xhr) {
return res.json(err);
} else {
return res.redirect(helpers.urlFormat('/signin.html', {refer: req.fullUrl()}));
}
}
if (!res.headersSent) {
if (req.xhr) {
return res.status(500).json({
... ...
... ... @@ -31,7 +31,10 @@ module.exports = () => {
return this.uid;
},
uid: cookie.getUid(req),
session: req.cookies._SESSSION
session: req.cookies._SESSION,
isValid() {
return this.uid && this.session;
}
};
}
... ...