2
1
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2023-12-13 21:00:40 +01:00

Putting back relative redirects

issue #1523

- also added some comments to indicate the difference between the two custom middleware files.
This commit is contained in:
Hannah Wolfe 2013-11-25 20:31:18 +00:00
parent 71ddd73a00
commit 5ad2d6178b
2 changed files with 15 additions and 5 deletions

View file

@ -1,3 +1,7 @@
// # Custom Middleware
// The following custom middleware functions cannot yet be unit tested, and as such are kept separate from
// the testable custom middleware functions in middleware.js
var middleware = require('./middleware'), var middleware = require('./middleware'),
express = require('express'), express = require('express'),
_ = require('underscore'), _ = require('underscore'),

View file

@ -1,3 +1,6 @@
// # Custom Middleware
// The following custom middleware functions are all unit testable, and have accompanying unit tests in
// middleware_spec.js
var _ = require('underscore'), var _ = require('underscore'),
express = require('express'), express = require('express'),
@ -18,11 +21,12 @@ var middleware = {
// We strip /ghost/ out of the redirect parameter for neatness // We strip /ghost/ out of the redirect parameter for neatness
auth: function (req, res, next) { auth: function (req, res, next) {
if (!req.session.user) { if (!req.session.user) {
var path = req.path.replace(/^\/ghost\/?/gi, ''), var reqPath = req.path.replace(/^\/ghost\/?/gi, ''),
root = ghost.blogGlobals().path === '/' ? '' : ghost.blogGlobals().path,
redirect = '', redirect = '',
msg; msg;
if (path !== '') { if (reqPath !== '') {
msg = { msg = {
type: 'error', type: 'error',
message: 'Please Sign In', message: 'Please Sign In',
@ -33,9 +37,9 @@ var middleware = {
if (!_.contains(_.pluck(ghost.notifications, 'id'), 'failedauth')) { if (!_.contains(_.pluck(ghost.notifications, 'id'), 'failedauth')) {
ghost.notifications.push(msg); ghost.notifications.push(msg);
} }
redirect = '?r=' + encodeURIComponent(path); redirect = '?r=' + encodeURIComponent(reqPath);
} }
return res.redirect(ghost.blogGlobals().url + '/ghost/signin/' + redirect); return res.redirect(root + '/ghost/signin/' + redirect);
} }
next(); next();
@ -56,8 +60,10 @@ var middleware = {
// Check if we're logged in, and if so, redirect people back to dashboard // Check if we're logged in, and if so, redirect people back to dashboard
// Login and signup forms in particular // Login and signup forms in particular
redirectToDashboard: function (req, res, next) { redirectToDashboard: function (req, res, next) {
var root = ghost.blogGlobals().path === '/' ? '' : ghost.blogGlobals().path;
if (req.session.user) { if (req.session.user) {
return res.redirect(ghost.blogGlobals().url + '/ghost/'); return res.redirect(root + '/ghost/');
} }
next(); next();