mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
Cleaner login redirects
- closes #136 - stripped /ghost/ out of all redirects - changed redirect= to r=
This commit is contained in:
parent
b5f4c9334e
commit
9e1191ae1e
2 changed files with 8 additions and 6 deletions
12
app.js
12
app.js
|
@ -44,19 +44,21 @@ ghost.app().configure('development', function () {
|
|||
|
||||
/**
|
||||
* Authenticate a request by redirecting to login if not logged in
|
||||
* We strip /ghost/ out of the redirect parameter for neatness
|
||||
*
|
||||
* @type {*}
|
||||
*/
|
||||
auth = function (req, res, next) {
|
||||
if (!req.session.user) {
|
||||
if (req.url && /^\/ghost\/?$/gi.test(req.url)) {
|
||||
// TODO: Welcome message? Intro if no logins yet?
|
||||
req.shutUpJsLint = true;
|
||||
} else {
|
||||
var path = req.path.replace(/^\/ghost\/?/gi, ''),
|
||||
redirect = '';
|
||||
|
||||
if (path !== '') {
|
||||
req.flash('warn', "Please login");
|
||||
redirect = '?r=' + encodeURIComponent(path);
|
||||
}
|
||||
|
||||
return res.redirect('/ghost/login/?redirect=' + encodeURIComponent(req.path));
|
||||
return res.redirect('/ghost/login/' + redirect);
|
||||
}
|
||||
|
||||
next();
|
||||
|
|
|
@ -69,7 +69,7 @@ adminControllers = {
|
|||
api.users.check({email: req.body.email, pw: req.body.password}).then(function (user) {
|
||||
console.log('user found: ', user);
|
||||
req.session.user = "ghostadmin";
|
||||
res.redirect(req.query.redirect || '/ghost/');
|
||||
res.redirect('/ghost/' + req.query.r || '/ghost/');
|
||||
}, function (error) {
|
||||
// Do something here to signal the reason for an error
|
||||
req.flash('error', error.message);
|
||||
|
|
Loading…
Add table
Reference in a new issue