diff --git a/core/client/views/base.js b/core/client/views/base.js
index fb93786a7e..2ec95cf806 100644
--- a/core/client/views/base.js
+++ b/core/client/views/base.js
@@ -99,8 +99,22 @@
}
return message;
- }
+ },
+ // Getting URL vars
+ getUrlVariables: function () {
+ var vars = [],
+ hash,
+ hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&'),
+ i;
+
+ for (i = 0; i < hashes.length; i += 1) {
+ hash = hashes[i].split('=');
+ vars.push(hash[0]);
+ vars[hash[0]] = hash[1];
+ }
+ return vars;
+ }
});
/**
diff --git a/core/client/views/login.js b/core/client/views/login.js
index e46ddc1305..4bd30eb964 100644
--- a/core/client/views/login.js
+++ b/core/client/views/login.js
@@ -46,6 +46,7 @@
event.preventDefault();
var email = this.$el.find('.email').val(),
password = this.$el.find('.password').val(),
+ redirect = this.getUrlVariables().r,
self = this;
$.ajax({
@@ -53,7 +54,8 @@
type: 'POST',
data: {
email: email,
- password: password
+ password: password,
+ redirect: redirect
},
success: function (msg) {
window.location.href = msg.redirect;
diff --git a/core/server/controllers/admin.js b/core/server/controllers/admin.js
index 197b668299..5727d47da9 100644
--- a/core/server/controllers/admin.js
+++ b/core/server/controllers/admin.js
@@ -95,7 +95,8 @@ adminControllers = {
'auth': function (req, res) {
api.users.check({email: req.body.email, pw: req.body.password}).then(function (user) {
req.session.user = user.id;
- res.json(200, {redirect: req.query.r ? '/ghost/' + req.query.r : '/ghost/'});
+ res.json(200, {redirect: req.body.redirect ? '/ghost/'
+ + decodeURIComponent(req.body.redirect) : '/ghost/'});
}, function (error) {
res.json(401, {error: error.message});
});
@@ -139,7 +140,17 @@ adminControllers = {
},
'logout': function (req, res) {
delete req.session.user;
- req.flash('success', "You were successfully logged out");
+ var msg = {
+ type: 'success',
+ message: 'You were successfully logged out',
+ status: 'passive',
+ id: 'successlogout'
+ };
+ // let's only add the notification once
+ if (!_.contains(_.pluck(ghost.notifications, 'id'), 'successlogout')) {
+ ghost.notifications.push(msg);
+ }
+
res.redirect('/ghost/login/');
},
'index': function (req, res) {
diff --git a/core/server/helpers/tpl/notification.hbs b/core/server/helpers/tpl/notification.hbs
deleted file mode 100644
index 1035ed1ca9..0000000000
--- a/core/server/helpers/tpl/notification.hbs
+++ /dev/null
@@ -1,4 +0,0 @@
-
diff --git a/core/server/views/default.hbs b/core/server/views/default.hbs
index d755d0f51d..060a5970b1 100644
--- a/core/server/views/default.hbs
+++ b/core/server/views/default.hbs
@@ -28,7 +28,7 @@
{{{body}}}
diff --git a/core/server/views/partials/flashes.hbs b/core/server/views/partials/notifications.hbs
similarity index 100%
rename from core/server/views/partials/flashes.hbs
rename to core/server/views/partials/notifications.hbs
diff --git a/index.js b/index.js
index 9eaa3b08c0..bbac7c720d 100644
--- a/index.js
+++ b/index.js
@@ -14,7 +14,6 @@ var express = require('express'),
admin = require('./core/server/controllers/admin'),
frontend = require('./core/server/controllers/frontend'),
api = require('./core/server/api'),
- flash = require('connect-flash'),
Ghost = require('./core/ghost'),
I18n = require('./core/shared/lang/i18n'),
filters = require('./core/server/filters'),
@@ -39,14 +38,37 @@ v.error = function () {
function auth(req, res, next) {
if (!req.session.user) {
var path = req.path.replace(/^\/ghost\/?/gi, ''),
- redirect = '';
+ redirect = '',
+ msg;
if (path !== '') {
- req.flash('warn', "Please login");
+ msg = {
+ type: 'error',
+ message: 'Please Log In',
+ status: 'passive',
+ id: 'failedauth'
+ };
+ // let's only add the notification once
+ if (!_.contains(_.pluck(ghost.notifications, 'id'), 'failedauth')) {
+ ghost.notifications.push(msg);
+ }
redirect = '?r=' + encodeURIComponent(path);
}
return res.redirect('/ghost/login/' + redirect);
}
+
+ next();
+}
+
+
+// While we're here, let's clean up on aisle 5
+// That being ghost.notifications, and let's remove the passives from there
+// plus the local messages, as the have already been added at this point
+// otherwise they'd appear one too many times
+function cleanNotifications(req, res, next) {
+ ghost.notifications = _.reject(ghost.notifications, function (notification) {
+ return notification.status === 'passive';
+ });
next();
}
@@ -165,7 +187,6 @@ ghost.app().configure(function () {
ghost.app().use(express.cookieParser('try-ghost'));
ghost.app().use(express.cookieSession({ cookie: { maxAge: 60000000 }}));
ghost.app().use(ghost.initTheme(ghost.app()));
- ghost.app().use(flash());
if (process.env.NODE_ENV !== "development") {
ghost.app().use(express.logger());
@@ -187,6 +208,8 @@ when.all([ghost.init(), filters.loadCoreFilters(ghost), helpers.loadCoreHelpers(
// post init config
ghost.app().use(ghostLocals);
+ // because science
+ ghost.app().use(cleanNotifications);
// ## Routing
diff --git a/package.json b/package.json
index b68a9d2cac..9add69045b 100644
--- a/package.json
+++ b/package.json
@@ -13,7 +13,6 @@
"dependencies": {
"express": "3.3.4",
"express-hbs": "0.2.0",
- "connect-flash": "0.1.1",
"node-polyglot": "0.2.1",
"moment": "2.1.0",
"underscore": "1.5.1",