0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00

Removed flash, renamed file, unbroken logout / login request notifications

Closes #354
* Reintroduced the redirect functionality (not logged in, tries to go to `/settings/user/`, is sent to `/login/` with info notification, after login user is taken to `/settings/user/)
* Reintroduced the "Successfully logged out" message
* Added middleware to scrub passive notifications from `ghost.notifications` after one use basically mimicing client side passive notifications
* Removed flash from everywhere. Even from package.json.
* Renamed flashed.hbs to notifications.hbs, modified default.hbs accordingly
* Added function to parse GET variables on client side
This commit is contained in:
Gabor Javorszky 2013-08-20 00:40:09 +01:00
parent ae3b1ac635
commit 4e1aa2119c
8 changed files with 60 additions and 15 deletions

View file

@ -99,8 +99,22 @@
} }
return message; 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;
}
}); });
/** /**

View file

@ -45,14 +45,16 @@
submitHandler: function (event) { submitHandler: function (event) {
event.preventDefault(); event.preventDefault();
var email = this.$el.find('.email').val(), var email = this.$el.find('.email').val(),
password = this.$el.find('.password').val(); password = this.$el.find('.password').val(),
redirect = this.getUrlVariables().r;
$.ajax({ $.ajax({
url: '/ghost/login/', url: '/ghost/login/',
type: 'POST', type: 'POST',
data: { data: {
email: email, email: email,
password: password password: password,
redirect: redirect
}, },
success: function (msg) { success: function (msg) {
window.location.href = msg.redirect; window.location.href = msg.redirect;

View file

@ -95,7 +95,8 @@ adminControllers = {
'auth': function (req, res) { 'auth': function (req, res) {
api.users.check({email: req.body.email, pw: req.body.password}).then(function (user) { api.users.check({email: req.body.email, pw: req.body.password}).then(function (user) {
req.session.user = user.id; 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) { }, function (error) {
res.send(401, error.message); res.send(401, error.message);
}); });
@ -143,7 +144,17 @@ adminControllers = {
}, },
'logout': function (req, res) { 'logout': function (req, res) {
delete req.session.user; 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/'); res.redirect('/ghost/login/');
}, },
'index': function (req, res) { 'index': function (req, res) {

View file

@ -1,4 +0,0 @@
<section class="notification{{#if type}}-{{type}}{{/if}} notification-{{status}} js-notification">
{{message}}
<a class="close" href="#"><span class="hidden">Close</span></a>
</section>

View file

@ -28,7 +28,7 @@
<main role="main" id="main"> <main role="main" id="main">
<aside id="flashbar"> <aside id="flashbar">
{{> flashes}} {{> notifications}}
</aside> </aside>
{{{body}}} {{{body}}}

View file

@ -14,7 +14,6 @@ var express = require('express'),
admin = require('./core/server/controllers/admin'), admin = require('./core/server/controllers/admin'),
frontend = require('./core/server/controllers/frontend'), frontend = require('./core/server/controllers/frontend'),
api = require('./core/server/api'), api = require('./core/server/api'),
flash = require('connect-flash'),
Ghost = require('./core/ghost'), Ghost = require('./core/ghost'),
I18n = require('./core/shared/lang/i18n'), I18n = require('./core/shared/lang/i18n'),
filters = require('./core/server/filters'), filters = require('./core/server/filters'),
@ -34,14 +33,37 @@ var express = require('express'),
function auth(req, res, next) { function auth(req, res, next) {
if (!req.session.user) { if (!req.session.user) {
var path = req.path.replace(/^\/ghost\/?/gi, ''), var path = req.path.replace(/^\/ghost\/?/gi, ''),
redirect = ''; redirect = '',
msg;
if (path !== '') { 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); redirect = '?r=' + encodeURIComponent(path);
} }
return res.redirect('/ghost/login/' + redirect); 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(); next();
} }
@ -133,7 +155,6 @@ ghost.app().configure(function () {
ghost.app().use(express.cookieParser('try-ghost')); ghost.app().use(express.cookieParser('try-ghost'));
ghost.app().use(express.cookieSession({ cookie: { maxAge: 60000000 }})); ghost.app().use(express.cookieSession({ cookie: { maxAge: 60000000 }}));
ghost.app().use(ghost.initTheme(ghost.app())); ghost.app().use(ghost.initTheme(ghost.app()));
ghost.app().use(flash());
if (process.env.NODE_ENV !== "development") { if (process.env.NODE_ENV !== "development") {
ghost.app().use(express.logger()); ghost.app().use(express.logger());
@ -155,6 +176,8 @@ when.all([ghost.init(), filters.loadCoreFilters(ghost), helpers.loadCoreHelpers(
// post init config // post init config
ghost.app().use(ghostLocals); ghost.app().use(ghostLocals);
// because science
ghost.app().use(cleanNotifications);
// ## Routing // ## Routing

View file

@ -13,7 +13,6 @@
"dependencies": { "dependencies": {
"express": "3.3.4", "express": "3.3.4",
"express-hbs": "0.2.0", "express-hbs": "0.2.0",
"connect-flash": "0.1.1",
"node-polyglot": "0.2.1", "node-polyglot": "0.2.1",
"moment": "2.1.0", "moment": "2.1.0",
"underscore": "1.5.1", "underscore": "1.5.1",